First, installation
PostgreSQL version is 9.4.4
# git clone-b rel9_4_stable https://github.com/ossc-db/pg_rman.gitInitialized empty git repository in/opt/pg_rman/.git /remote:counting objects:1939, done.remote:Total 1939 (Delta 0), reused 0 (Delta 0), pack-reused 1939Receiving objects: 100% (1939/1939), 702.67 KiB | 311 kib/s, done. Resolving deltas:100% (1393/1393), done.# yum install-y pam-devel readline-devel zlib-devel# make# make Install/bin/mkdi R-p '/opt/pg94/bin '/usr/bin/install-c pg_rman '/opt/pg94/bin ' # Pg_rman--versionpg_rman 1.3.1
Second, use
First you need to initialize the backup directory
# mkdir-p/data/pg_backup# mkdir-p/data/test_xlog_94/fulltime# pg_rman init--backup-path=/data/pg_backup/warning:ar Clog_path is isn't set yetdetail:the Archive_command is not a set in Postgresql.conf.HINT:Please set Arclog_path in Pg_rman. INI or environmental variable.# vim/data/pg_backup/pg_rman.iniarclog_path= '/data/test_xlog_94/fulltime '
Make a full backup on the master node and specify--host from the library,--standby-host=172.17.5.47--standby-port=5432
# pg_rman backup --backup-mode=full --backup-path=/data/pg_backup/ --pgdata=/ data/test_pgdata_94/ -u postgres -d postgres INFO: copying database filesNOTICE: pg_stop_backup complete, All required wal segments have been archivedinfo: copying archived WAL filesINFO: backup completeHINT: Please execute ' Pg_rman validate ' to verify the files are correctly copied.# pg_rman show detail --backup-path=/data/pg_backup/==================================================================== ======================================== starttime mode duration data arclog srvlog total compressed curtli parenttli status =============================== =============================================================================2015-09-07 02:52:22 full 0m 422mb 106kb ---- 394MB false 1 0 ok
Use Backup for recovery
# mkdir restore_test# pg_rman restore --backup-path=/data/pg_backup/ --pgdata=/ data/restore_test/warning: could not open pg_controldata file "/data/restore_ Test//global/pg_control ": no such file or directorywarning: could not open pg_controldata file "/data/restore_test//global/pg_control": No such file or directoryINFO: backup "2015-09-07 02:52:22" is validinfo: the recovery target timeline ID is not givenINFO: use timeline Id of latest full backup as recovery target: 1info: calculating timeline branches to be used to recovery target pointINFO: searching latest full backup which can be used as restore Start pointinfo:&nbsP;found the full backup can be used as base in recovery: "2015-09-07 02:52:22" info: copying online wal files and server log filesinfo: clearing restore destinationinfo: validate: "2015-09-07 02:52:22 " backup and archive log files by SIZEINFO: backup " 2015-09-07 02:52:22 " is validinfo: restoring database files from the full mode backup "2015-09-07 02:52:22" info: searching incremental Backup to be restoredinfo: searching backup which contained archived WAL files to be restoredINFO: backup "2015-09-07 02:52:22" is validINFO: restoring WAL files from backup "2015-09-07 02:52:22" INFO: restoring online wal files and server log filesinfo: generating recovery.confinfo: restore completehint: recovery will start automatically when the Postgresql server is started.
Because the root user is used for backup and restore, directory permissions are also root and need to be modified to Postgres
# ls-ld/data/restore_test/drwxr-xr-x. Root root 4096 Sep 7 03:00 restore_test/# cat/data/restore_test/recovery.conf # recovery.conf generated by Pg_rman 1. 3.1restore_command = ' cp/data/test_pgdata_94/pg_xlog/%f%p ' recovery_target_timeline = ' 1 ' # Chown-r postgres:postgres/ data/restore_test/# chmod 0700/data/restore_test/# ls-ld/data/restore_test/drwx------. Postgres postgres 4096 Sep 7 03:05/data/restore_test/
Modify the port to 5433 and start the restored database
$ pg_ctl-d/data/restore_test/startserver starting[[email protected] data]$ [2015-09-07 07:05:40.291 UTC 31889 55ed3 744.7c91 1 0]log:redirecting LOG output to logging collector process[2015-09-07 07:05:40.291 UTC 31889 55ed3744.7c91 2 0]hint:future log output would appear in directory "Pg_log". $ psql-p 5433psql (9.4.4) Type ' help ' for help.
Restore to a specified point in time, the following parameters are used when performing the restore:
--recovery-target-time time stamp up to which recovery would proceed--RECOVERY-TARGET-XID transaction ID up to WHI CH Recovery would proceed--recovery-target-inclusive whether we stop just after the recovery target--recovery-target-ti Meline recovering into a particular timeline
Will write the corresponding parameters into the recovery.conf.
Reference: http://ossc-db.github.io/pg_rman/index.html
Pg_rman of PostgreSQL Backup