This post describes how a backup of the PostgreSQL database for Cloud Director can be setup to be scheduled and automated

In the VMware documentation there is only a description on how one could take a manual backup of the Postgres DB. In normal Operations it can be convenient to have this automated and scheduled. Link
We want to create a daily backup of the database and save that on the NFS Transfer Store inorder to be able to create image backup of the NFS Server.

To start with we use a tool called Cron that’s included in the Cloud Director Cell.
Cron is running it’s schedules from the directory that is placed at /etc/cron.d/
In order to create backups for Postgres we create a new file in the location. Called: vcdpostgres_db_backup

In the file we add the following lines that creates a backup everyday at 15:00, this can be customized to be once every week or whatever is suitable.

#m  h  dom mon dow user     command
00 15  *   *   *   postgres  /opt/vmware/vpostgres/10/bin/pg_dump vcloud > /opt/vmware/vcloud-director/data/transfer/pgdb-backup/$(date +\%F)_vcloud_postgresdbdump.tgz
00 15  *   *   *   root      find /opt/vmware/vcloud-director/data/transfer/pgdb-backup/_vcloud -mtime +5 -type f -delete

The command runs as the Postgres user and creates a dump of the vcloud database to the location of /opt/vmware/vcloud-director/data/transfer/pgdb-backup.
It finally checks if there are any files that are older than 5 days and deletes them.
Be sure to check that the cron job works by tailing /var/log/cron

Now backups are created at the NFS Transfer Store and are ready to be secured with image backup of the NFS Server.