Before you stared, I recommended to read the archiving document first. The documentation tells you more about how it works, but not how to configure it. Here I use my own example.http://www.postgresql.org/docs/9.2/static/continuous-archiving.html 1. Prepare disk space for the archived files.BKUPDIR=/home/backups/pgsql_data 2. PostgreSQL setting, a restart is need to enable the changewal_level = archive archive_mode = on archive_command = '/bin/cp -p %p /home/backups/archivelogs/%f </dev/null' The following two are optional, suggest you test your system before you chagne them, you can find the detail in the documentation http://www.postgresql.org/docs/9.2/static/continuous-archiving.html archive_timeout = 60 checkpoint_timeout = 1h 3. continuous backup script#set -v # debugging tools #set -x cmd=`basename $0` EMAIL='dba@abc.com'; export EMAIL BKUPDIR=/home/backups/pgsql_data; export BKUPDIR LOG=/home/backups/pgsql_data/backuplog.`date +%m%d%y%H`.log; export LOG typeset -i res function exitMsg() { mylog=$1 mymsg=$2 echo "$cmd: Unsuccessful PostgreSQL database hotbackup at `/bin/date`" >>$mylog echo "$mymsg" >>$mylog cat $mylog >> $LOG cat "$LOG" | mail -s "PostgreSQL database hotbackup failed (`/bin/date`)" $EMAIL exit 1 } LOG1=$LOG"_hotbackup" cat /dev/null >$LOG1 2>/dev/null echo "" >> $LOG echo "On `/bin/date` Daily PostgreSQL database hot backup:" >> $LOG /usr/bin/psql -U postgres -c "SELECT pg_start_backup('/home/backups/pgsql_data/label');" postgres &>backup.log nice tar -zcf /home/backups/pgsql_data/data.`date +%m%d%y%H`.tgz /var/lib/pgsql/9.1/data >>backup.log /usr/bin/psql -U postgres -c "SELECT pg_stop_backup();" postgres &>backup1.log res=$? if [ $res -ne 0 ] ; then exitMsg $LOG1 "ERROR: PostgreSQL database hotbackup failed." fi nice /usr/bin/find /home/backups/archivelogs -not -name "*.bz2" | xargs -n 1 -P 5 bzip2 cat $LOG1 >> $LOG cat /dev/null >$LOG1 2>/dev/null rm $LOG1 2>/dev/null cat backup1.log >> backup.log cat backup.log >> $LOG rm backup.log backup1.log echo "On `/bin/date` End of PostgreSQL hotbackup :" >> $LOG cat "$LOG" | mail -s "PostgreSQL Hotbackup SUCCEEDED! (`/bin/date`)" $EMAIL; exit 0 4. cleanup old backups scriptset -x # # Cleanup old database log files daily. # if [ `whoami` != 'postgres' ]; then echo '$cmd: you must be logged in as the postgres user' exit 1 fi nice /usr/bin/find /home/backups/pgsql_data -name "*.log*" \ -mtime +1 -exec rm {} \; # nice /usr/bin/find /home/backups/pgsql_data -name "*.tgz" \ -mtime +1 -exec rm {} \; # nice /usr/bin/find /home/backups/archivelogs -name "*.bz2" \ -mtime +1 -exec rm {} \; 5. Recovery, I tested but never used for real case, I put the preocedure here
Important thing is that sometime, you need to specify timeline recovery_target_time = '' # for example '2013-11-06 10:00:05' |