Simple Script to Backup VCenter Appliance Postgres Database

Written by James McDonald

February 12, 2013

Create a backup dir

# create a directory to hold the backup files
mkdir /storage/backup

# create a backup script file
/storage/backup/embedded_db_backup.sh

# make it executeable
chmod +x /storage/backup/embedded_db_backup.sh

Add the following to the backup script

#!/bin/bash

# source the vmware postgres embedded db configuration
. /etc/vmware-vpx/embedded_db.cfg

# get the day of week 1-7 starting mon=1
DOW=`date +"%u"`

# this is what roughly embedded_db.cfg contains
#EMB_DB_INSTALL_DIR='/opt/vmware/vpostgres/1.0'
#EMB_DB_TYPE='PostgreSQL'
#EMB_DB_SERVER='127.0.0.1'
#EMB_DB_PORT='5432'
#EMB_DB_INSTANCE='VCDB'
#EMB_DB_USER='vc'
#EMB_DB_STORAGE='/storage/db/vpostgres'
#EMB_DB_PASSWORD='<normally this is a password>'

# specify the postgres password in the PGPASSWORD var
# for pg_dump not to prompt for a password
export PGPASSWORD=$EMB_DB_PASSWORD

# as per vmware instructions change to the bin dir
cd $EMB_DB_INSTALL_DIR/bin

# run pg_dump passing in the correct values
# create a gzipped backup file
./pg_dump $EMB_DB_INSTANCE -U $EMB_DB_USER -Fp -c | gzip > /storage/backup/${DOW}-VCDB.bak.gz

Install a crontab as root

# min, hour, day of mon, month, day of week
3 18 * * * /storage/backup/embedded_db_backup.sh

 

1 Comment

  1. Erwin Zoer

    Just wondering:

    # create a backup script file
    /storage/backup/embedded_db_backup.sh

    should that have read instead:

    # create a backup script file
    touch /storage/backup/embedded_db_backup.sh

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like…

How to Research a CPU Upgrade

How to Research a CPU Upgrade

Upgrade Time! Doing a lot of VMWare Workstation virtualization to create labs for self-study and training. Finding...