One of my customers asked me to backup and replicate their VMware vCenter 5.5 Appliance using the embedded database with Veeam Backup & Replication. To achieve this the vCenter embedded database, which is a vPostgres database, must in a consistent state before it can be backed up and replicated properly.

There is a KB article from VMware about Backing up and restoring the vCenter Server Appliance vPostgres database. But the downside on this is that every time the backup runs the vPostgres database is dumped on the disk and the database is not consistent when it replicated. So when the replicated vCenter on the DR side is started bad things will happen…

To put the vCenter Appliance embedded database in a consistent state we need to tell the vPostgres database before the Backup / Replication job starts to prepare for performing an on-line backup. This can be done by creating 2 scripts which put the vPostgres database in a on-line backup mode and afterwards exits this state. These two scripts are triggered by the VMware tools when the Backup and Replicate job runs when the “Guest Quiescence” option is enabled.

For the VMware vCenter 6.0 Appliance this is not necessary because these scripts are already in place by default!

Let’s get started!

Fist enable SSH on the vCenter (if you’ve not done that already).

Login the VAMI of the vCenter Appliance and go to the Admin tab and change “Administrator SSH login enabled” to Yes.

Now start your favourite SSH client and login the SSH session of the vCenter Appliance.

And create the first script for “freezing” the vPostgres database.

vi /usr/sbin/pre-freeze-script 1 vi /usr/sbin/pre-freeze-script

And and the following content :

#!/bin/bash #set log directory log="/var/log/vpostgres_backup.log" #set and log start date today=`date +%Y\/%m\/%d\ %H:%M:%S` echo "${today}: Start of creation consistent state" >> ${log} #execute freeze command cmd="echo \"SELECT pg_start_backup('${today}', true);\" | sudo /opt/vmware/vpostgres/9.0/bin/psql -U postgres >> ${log} 2>&1" eval ${cmd} #set and log end date today=`date +%Y\/%m\/%d\ %H:%M:%S` echo "${today}: Finished freeze script" >> ${log} 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #!/bin/bash #set log directory log="/var/log/vpostgres_backup.log" #set and log start date today=`date +%Y\/%m\/%d\ %H:%M:%S` echo "${today}: Start of creation consistent state" >> ${log} #execute freeze command cmd="echo \"SELECT pg_start_backup('${today}', true);\" | sudo /opt/vmware/vpostgres/9.0/bin/psql -U postgres >> ${log} 2>&1" eval ${cmd} #set and log end date today=`date +%Y\/%m\/%d\ %H:%M:%S` echo "${today}: Finished freeze script" >> ${log}

Make the script executable.

chmod +x /usr/sbin/pre-freeze-script 1 chmod +x /usr/sbin/pre-freeze-script

Then create the second script for “releasing” the vPostgres database.



vi /usr/sbin/post-thaw-script 1 vi /usr/sbin/post-thaw-script

And and the following content :

#!/bin/bash #set log directory log="/var/log/vpostgres_backup.log" #set and log start date today=`date +%Y\/%m\/%d\ %H:%M:%S` echo "${today}: Release of backup" >> ${log} #execute release command cmd="echo \"SELECT pg_stop_backup();\" | sudo /opt/vmware/vpostgres/9.0/bin/psql -U postgres >> ${log} 2>&1" eval ${cmd} #set and log end date today=`date +%Y\/%m\/%d\ %H:%M:%S` echo "${today}: Finished thaw script" >> ${log} 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #!/bin/bash #set log directory log="/var/log/vpostgres_backup.log" #set and log start date today=`date +%Y\/%m\/%d\ %H:%M:%S` echo "${today}: Release of backup" >> ${log} #execute release command cmd="echo \"SELECT pg_stop_backup();\" | sudo /opt/vmware/vpostgres/9.0/bin/psql -U postgres >> ${log} 2>&1" eval ${cmd} #set and log end date today=`date +%Y\/%m\/%d\ %H:%M:%S` echo "${today}: Finished thaw script" >> ${log}

Make the script executable.

chmod +x /usr/sbin/post-thaw-script 1 chmod +x /usr/sbin/post-thaw-script

Prepare VMware vPostgres database configuration

vi /db/data/postgresql.conf 1 vi /db/data/postgresql.conf

Look for the following settings, uncomment them and change the value.

wal_level = hot_standby wal_sync_method = fsync max_wal_senders = 5 wal_keep_segments = 16 hot_standby = on 1 2 3 4 5 wal_level = hot_standby wal_sync_method = fsync max_wal_senders = 5 wal_keep_segments = 16 hot_standby = on

Restart de VMware vPostgres service on the VMware vCenter Appliance.

/etc/init.d/vmware-vpostgres restart 1 /etc/init.d/vmware-vpostgres restart

Retrieve the vPostgres database password and store it so it can be used by the scripts.

cat /etc/vmware-vpx/embedded_db.cfg | grep EMB_DB_PASSWORD | awk -F "'" '{print "localhost:*:*:postgres:"$2}' > $HOME/.pgpass chmod 0600 $HOME/.pgpass 1 2 cat /etc/vmware-vpx/embedded_db.cfg | grep EMB_DB_PASSWORD | awk -F "'" '{print "localhost:*:*:postgres:"$2}' > $HOME/.pgpass chmod 0600 $HOME/.pgpass

And lastly don’t forget to enable the “Guest Quiescence” option on the backup job.

And you are done! From now on if you run a Backup or Replication job the vPostgres database will be in a consistent state and can be safely restored.

If you run into any issues running the scripts, please check the log file /var/log/vpostgres_backup.log for more information on what’s wrong.