postgres
Postgres PITR Backup & Restore Demo Configuration
Continuous Archiving and Point-in-Time Recovery (PITR)
Cick here for Video Demo https://youtu.be/WZps_MYYvV8
Postgres WAL Archiving
- Create the WAL & backup Directory and add necessary Permisson
bash~ mkdir -p /var/lib/pgsql/wals/
bash~ mkdir -p /var/lib/pgsql/backups/
bash~ chown postgres:postgres -R /var/lib/pgsql/backups/
bash~ chown postgres:postgres -R /var/lib/pgsql/wals/
- Edit the postgresql.conf with postgres user and add the below changes
wal_level=archive
archive_mode=on
archive_command = 'test ! -f /var/lib/pgsql/wals/%f && cp %p /var/lib/pgsql/wals/%f'
- Restart the database
bash~ service postgresql restart
- Prepare for the basebackup
su - postgres
psql -c "SELECT pg_start_backup('label');" postgres
tar -C /var/lib/pgsql/data/ -czvf /var/lib/pgsql/backups/pg_basebackup_backup.tar.gz .
psql -c "SELECT pg_stop_backup();" postgres
Add Data to PostgreSQL
bash~ su - postgres
bash~ createdb mydb
bash~ psql -s mydb
Testing Restore
- Stop the postgres
bash~ /etc/init.d/postgresql stop
- Remove the data folder and Initilize the DB
bash~ cd /var/lib/pgsql/
bash~ rm -rf data/
- Initilaize the Database
bash~ /etc/init.d/postgresql initdb
bash~ /etc/init.d/postgresql start
Restore from WAL Archiving
- Stop the Postgres Server
bash~ /etc/init.d/postgresql stop
- Extract the Basebackup...
bash~ tar xvf /var/lib/pgsql/backups/pg_basebackup_backup.tar.gz -C /var/lib/pgsql/data
- Create recovery.conf with the below content and check the permission also
bash~ cd /var/lib/pgsql/data
bash~ cat recovery.conf
restore_command = 'cp /var/lib/pgsql/wals/%f %p'
- Restart the Postgres DB
bash~ /etc/init.d/postgresql start
- Upon completion of the recovery process, the server will rename recovery.conf to recovery.done
bash~ cd /var/lib/pgsql/data
bash~ cat recover.done

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
