Skip to content

Instantly share code, notes, and snippets.

@evandhoffman
Created July 12, 2011 21:32
Show Gist options
  • Save evandhoffman/1079026 to your computer and use it in GitHub Desktop.
Save evandhoffman/1079026 to your computer and use it in GitHub Desktop.
Postgres/Compellent snapsho backup
#!/bin/bash
# Compellent CLI config
WAL_ARCHIVE_DIR=/mnt/isilon/wal-archive/
TIMESTAMP_FILE="$WAL_ARCHIVE_DIR/`date +%s`.lock"
JAVA=/usr/bin/java
CML_JAR=CompCU.jar
CML_HOST='192.168.1.200'
CML_USER='backup'
CML_PASS="password"
#CML_VOLUME=104
CML_VOLUME=104
CML_REPLAY_NAME="Scripted `date +%Y%m%d-%H%M%S`"
CML_EXPIRE_MINS=10080
CML_SNAP_CMD="$JAVA -jar $CML_JAR -host $CML_HOST -user $CML_USER -password '$CML_PASS' -c \"replay create -volumeindex $CML_VOLUME -name '$CML_REPLAY_NAME' -expire $CML_EXPIRE_MINS\" -verbose"
# Postgres backup info
# http://www.postgresql.org/docs/8.2/interactive/continuous-archiving.html
PG_PSQL_CMD=/usr/bin/psql
PG_PSQL_USER=user
PG_PSQL_DB=password
PG_PSQL_HOST=localhost
PG_WAL_RETENTION_DAYS=1
PG_BACKUP_LABEL='backup_label'
PG_BACKUP_START_CMD="$PG_PSQL_CMD -U$PG_PSQL_USER -h $PG_PSQL_HOST -c \"select pg_start_backup('$PG_BACKUP_LABEL')\" $PG_PSQL_DB"
PG_BACKUP_STOP_CMD="$PG_PSQL_CMD -U$PG_PSQL_USER -h $PG_PSQL_HOST -c \"select pg_stop_backup()\" $PG_PSQL_DB"
if [ ! -f $CML_JAR ]
then
echo "Unable to find jar $CML_JAR"
exit 1;
fi
touch $TIMESTAMP_FILE
sleep 2
echo $PG_BACKUP_START_CMD
eval $PG_BACKUP_START_CMD
sleep 2
echo $CML_SNAP_CMD
eval $CML_SNAP_CMD
sleep 2
#eval $CML_SNAP_CMD
echo $PG_BACKUP_STOP_CMD
eval $PG_BACKUP_STOP_CMD
# Delete all the old WAL archive files
#find $WAL_ARCHIVE_DIR -regextype posix-egrep ! -newer $TIMESTAMP_FILE -regex .+/[A-F0-9]{24}\$ | xargs rm -fv
find $WAL_ARCHIVE_DIR -regextype posix-egrep -mtime +$PG_WAL_RETENTION_DAYS -regex .+/[A-F0-9]{24}\$ | xargs rm -fv
rm -fv $TIMESTAMP_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment