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 *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

Network speed test host to host

On Ubuntu / Debian apt-get install iperf3 On Windows download it from https://iperf.fr/iperf-download.php#windows Make...

Clear HSTS Settings in CHrome

Open chrome://net-internals/#hsts enter the domain in the query field and click Query to confirm it has HSTS settings...