«

»

vRA PostgreSQL database backup

In a vRealize Automation (vRA) formerly known as vCloud Automation Center (vCAC) there are quite a few components to keep in sync so you can successfully restore the environment in case of a disaster. I mentioned backup and restore as a critical piece of a vRA implementation during the podcast i joined the other week. Click here to view the podcast blog post.

For a standard vRA deployment including provisioning virtual machines (VMs) to vCenter Server you got a minimum of three (most likely four) databases to keep track of apart from the VMs delivering the management components:

  • vRA VA database
  • vRA IaaS database
  • vCenter Server database for management systems
  • vCenter Server database for workload systems

In many of the deployments i have implemented the customer database of choice has been Microsoft SQL (MSSQL) where possible and that covers three of the above mentioned databases. However, MSSQL is not supported for the vRA virtual appliance so in that case you need to use the internal PostgreSQL database or use an external PostgreSQL database.

Below is a script that you can run in the vRA VA to perform a PostgreSQL database dump that can be used for restore if necessary. The script has been verified for vRA version 6..1.0.0 Build 2077124.
The backups are created in the directory /root/postgresql_backup, which you have to create manually, and for the below example i save 7 daily copies of the dump.

#/bin/bash

# Script to backup the vRA PostgreSQL Database
# Version 1.0
# Magnus Andersson Nutanix
#
# Set date parameter
date=`date |awk ‘{print $2 $3}’`
#
# Set backup file
backupfile=”/root/postgresql_backup/PostgreSQL_DB_Backup_$date.sql”
# Set backup start date and time in log file
echo “Backup starting at:” `date` > /root/postgresql_backup/backup.log
#
# Start PostgreSQL dump
/opt/vmware/vpostgres/9.2/bin/pg_dump -U vcac vcac -f $backupfile
#
# Delete backup files older than 7 days
find /root/postgresql_backup/ -name “PostgreSQL_DB_Backup_*.sql” -mtime +7 -exec rm {} \;
#
# Set backup finish date and time in log file
echo “Backup finished at:” `date` >> /root/postgresql_backup/backup.log
Other vRA VA partition options if you don’t want to use the / partition are:
  • /Storage/db
  • /Storage/log
Now when we got a script to take PostgreSQL database dumps it could be nice to run the backup on a schedule and crontab is our friend here.
You list the crontab entries via “crontab -l ” command and you edit the crontab file using the “crontab -e” command.
The scheduling options in crontab includes:
  • minute (from 0 to 59)
  • hour (from 0 to 23)
  • day of month (from 1 to 31)
  • month (from 1 to 12)
  • day of week (from 0 to 6) (0=Sunday)

I used the following crontab entry to schedule the backup to take place every day at 10:30 PM for my most recent implementation.

# PostgreSQL backup job
30 22 * * * /root/postgresql_backup/backup.sh >/dev/null 2>&1

2 pings

Comments have been disabled.