Database Reference
In-Depth Information
9. Stop the backup as follows:
psql -c "select pg_stop_backup(), current_timestamp"
10. Stop archiving as follows:
rm ../standalone/archiving_active
11. Move the files to the archive subdirectory, ready for recovery as follows:
mv ../standalone/archive/ archive/
12. Add the archived files to the standalone backup as follows:
tar -rzf ../standalone/$BACKUPNAME archive/
13. Write a recovery.conf with which to recover. Note that the archive directory
mentioned here must match the location files to which are copied in step 8.
echo "restore_command = 'cp archive/%f %p'" > recovery.conf
14. Add the recovery.conf to the archive as follows:
tar -rf ../standalone/$BACKUPNAME recovery.conf
echo "recovery_end_command = 'rm -R archive' " >> recovery.conf
15. Store $BACKUPNAME somewhere safe . A safe place is definitely not on the same
server.
The procedure ends with a file named $BACKUPNAME in the standalone directory. So, you
need to remember to copy it somewhere safe. The file contains everything that you need to
recover, including a recovery parameter file.
How it works...
The backup produced by the preceding procedure allows you to restore only to a single point
in time. That point is the time of the pg_stop_backup() function.
Physical backup takes a copy of all files in the database (step 8, the "base backup"). That
alone is not sufficient as a backup, and you need the other steps as well. A simple copy of the
database produces a time-inconsistent copy of the database files. To make the backup time-
consistent, we need to add to it all the changes that took place from the start to the end of the
backup. That's why we have steps 7 and 9 to bracket our backup step.
The changes made are put into the standalone/archive directory as a set of archived
transaction log/write-ahead log (WAL) files. Step 6 creates the archive directory. Steps 1,
2, 3, and 5 set the parameters that copy the files to the archive. Changing archive_mode
requires us to restart the database server, so there is a trick to avoid that. These parameters
are conditional upon the existence of a file named archiving_active , whose presence
enables or disables the archiving process. Note this choice of parameters is configurable, so
PostgreSQL doesn't always need to work this way.
 
Search WWH ::




Custom Search