Script for backup and restoring postgresql
It follows http://www.postgresql.org/docs/9.3/static/continuous-archiving.html
Create archive directory and backup directory in our case are
mkdir /archivemkdir /backup
chown postgres:postgres /archivechown postgres:postgres /backup
At every new restore create a new archivedir ( for example /archive_1 ) and change it in set_archive.bash and in set_restore.bash .
All commands have to be execute as postgres login
This command will modify standard postgresql 9.3 configuration adding WAL Archiving (see 24.3.1 at http://www.postgresql.org/docs/9.3/static/continuous-archiving.html ).
WAL file will be written at /archive , ready to be used for a recovery.
A posgresql restart is needed
bash set_archive.bash
service postgresql restart
This command create a tar of entire PostgresSQL directory including pg_xlog directory
Tar is located at /backup/YYYYMMDD/basebackup_last.tgz
Tar is located at /backup/YYYYMMDD/backup_BACKUPID_YYYYMMDDHHmmss.tgz
bash backup.bash
This command create a tar of WAL file located /archive directory
Tar is located at /backup/archive_last.tgz
Tar is located at /backup/YYYYMMDD/archive_BACKUPID_YYYYMMDDHHmmss.tgz
A file /backup/last_archive_backup_label.info contain label of last archive log saved together with base backup done
bash backup_wal_last.bash
See test_sequence.md