Skip to content

Instantly share code, notes, and snippets.

@mrsarm
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save mrsarm/c3f9bd65061d46dcd5f4 to your computer and use it in GitHub Desktop.

Select an option

Save mrsarm/c3f9bd65061d46dcd5f4 to your computer and use it in GitHub Desktop.
Script to execute the 'cron' task with Barman Postgres backup system
#!/bin/bash
#
# Script to execute the 'cron' task with Barman Postgres backup
# system.
#
# Do NOT confuse this with a **crontab** task: this script
# only do the archive of the continuous WAL files sent
# by PostgreSQL, but it's a good practise execute this
# script periodically with the Unix Cron system.
#
# See the `PG Barman` home page for more information:
# http://www.pgbarman.org
#
# Author: (2014) Mariano Ruiz <mrsarm@gmail.com>
#
# Duplicity command line options
BARMAN_OPTS=""
# Database instance to backup
DATABASE="main"
# Log file
LOG="/var/log/backup-pgbarman-$DATABASE.log"
# Date format printed into the log
DATE_FORMAT="+%Y-%m-%d %T"
echo "`date "$DATE_FORMAT"` INFO : Starting to perform PG Barman 'cron' task ... " 2>&1 | tee -a $LOG
T_START=$(date +%s) # To calculate the process time
barman cron $BARMAN_OPTS 2>&1 | tee -a $LOG
EXIT_CODE=${PIPESTATUS[0]}
T_DIFF=$(( $(date +%s) - $T_START ))
if [ "$EXIT_CODE" != "0" ]; then
echo "`date "$DATE_FORMAT"` ERROR : ... Performing PG Barman 'cron' task done with errors (elapsed time `date -u -d @"$T_DIFF" +'%-Hh %-Mm %-Ss'`). Check the log above." 2>&1 | tee -a $LOG
exit -1
fi
echo "`date "$DATE_FORMAT"` INFO : ... Performing PG Barman 'cron' task done at `date -u -d @"$T_DIFF" +'%-Hh %-Mm %-Ss'`." 2>&1 | tee -a $LOG
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment