标签:
pg_rman是一款专门为postgresql设计的在线备份恢复的工具。其支持在线和基于时间点备份方式,还可以通过创建backup catalog来维护DB cluster备份信息。
看起来好像是模仿oracle的RMAN工具。
pg_rman特点:
包:pg_rman-1.3.2-1.pg95.rhel6.x86_64.rpm
[root@sdserver40_210 software]# rpm -ivh postgresql95-libs-9.5.2-1PGDG.rhel6.x86_64.rpm warning: postgresql95-libs-9.5.2-1PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY Preparing... ########################################### [100%] 1:postgresql95-libs ########################################### [100%] [root@sdserver40_210 software]# rpm -ivh pg_rman-1.3.2-1.pg95.rhel6.x86_64.rpm Preparing... ########################################### [100%] 1:pg_rman ########################################### [100%]
2. 配置环境变量
3.初始化备份目录
[postgres@sdserver40_210 ~]$ pg_rman init -B /data/pg_rman INFO: ARCLOG_PATH is set to ‘/home/postgres/archive‘ INFO: SRVLOG_PATH is set to ‘/data/pgdata/pg_log‘
[postgres@sdserver40_210 ~]$ pg_rman backup --backup-mode=full --progress INFO: copying database files Processed 1153 of 1153 files, skipped 0 NOTICE: pg_stop_backup complete, all required WAL segments have been archived INFO: copying archived WAL files Processed 26 of 26 files, skipped 0 INFO: backup complete HINT: Please execute ‘pg_rman validate‘ to verify the files are correctly copied.
--pg_rman 的备份必须都是经过验证过的,否则不能进行恢复和增量备份
Backups without validation cannot be used forrestoreand incremental backup--执行完备份要执行一次validate,因为备份后的状态是done,还不能进行恢复
[postgres@sdserver40_210 ~]$ pg_rman show ========================================================== StartTime Mode Duration Size TLI Status ========================================================== 2016-05-31 16:36:45 FULL 0m 343MB 3 DONE [postgres@sdserver40_210 ~]$ pg_rman validate INFO: validate: "2016-05-31 16:36:45" backup and archive log files by CRC INFO: backup "2016-05-31 16:36:45" is valid [postgres@sdserver40_210 ~]$ pg_rman show ========================================================== StartTime Mode Duration Size TLI Status ========================================================== 2016-05-31 16:36:45 FULL 0m 343MB 3 OK
[postgres@sdserver40_210 ~]$ ll total 32 drwxrwxr-x 2 postgres postgres 4096 May 31 17:44 archive drwxrwxr-x 2 postgres postgres 4096 May 30 16:16 backup drwx------ 3 postgres postgres 4096 May 31 17:43 data drwxrwxr-x 2 postgres postgres 4096 May 30 16:09 log -rw-rw-r-- 1 postgres postgres 82 May 16 14:03 out_file -rw-rw-r-- 1 postgres postgres 128 May 16 13:52 out.txt drwxrwxr-x 2 postgres postgres 4096 May 30 16:16 scripts -rw-r--r-- 1 postgres postgres 20 May 16 15:39 test.sql [postgres@sdserver40_210 ~]$ rm -rf data [postgres@sdserver40_210 ~]$ ll total 28 drwxrwxr-x 2 postgres postgres 4096 May 31 17:44 archive drwxrwxr-x 2 postgres postgres 4096 May 30 16:16 backup drwxrwxr-x 2 postgres postgres 4096 May 30 16:09 log -rw-rw-r-- 1 postgres postgres 82 May 16 14:03 out_file -rw-rw-r-- 1 postgres postgres 128 May 16 13:52 out.txt drwxrwxr-x 2 postgres postgres 4096 May 30 16:16 scripts -rw-r--r-- 1 postgres postgres 20 May 16 15:39 test.sql [postgres@sdserver40_210 ~]$ pg_stop waiting for server to shut down.... done server stopped [postgres@sdserver40_210 ~]$ pg_rman restore --recovery-target-time "2016-05-31 17:30:00" INFO: the recovery target timeline ID is not given INFO: use timeline ID of current database cluster as recovery target: 5 INFO: calculating timeline branches to be used to recovery target point INFO: searching latest full backup which can be used as restore start point INFO: found the full backup can be used as base in recovery: "2016-05-31 16:36:45" INFO: copying online WAL files and server log files INFO: clearing restore destination INFO: validate: "2016-05-31 16:36:45" backup and archive log files by SIZE INFO: backup "2016-05-31 16:36:45" is valid INFO: restoring database files from the full mode backup "2016-05-31 16:36:45" INFO: searching incremental backup to be restored INFO: searching backup which contained archived WAL files to be restored INFO: backup "2016-05-31 16:36:45" is valid INFO: restoring WAL files from backup "2016-05-31 16:36:45" INFO: restoring online WAL files and server log files INFO: generating recovery.conf INFO: restore complete HINT: Recovery will start automatically when the PostgreSQL server is started. [postgres@sdserver40_210 ~]$ pg_start server starting [postgres@sdserver40_210 ~]$ psql mydb lottu psql (9.5.0) Type "help" for help. mydb=> \d List of relations Schema | Name | Type | Owner --------+------+-------+------- public | test | table | lottu (1 row) mydb=> select * from test; id | name ------+-------- 1001 | lottu 1002 | rax 1003 | xuan 1004 | li0924 (4 rows) mydb=> \q [postgres@sdserver40_210 ~]$ ll total 32 drwxrwxr-x 2 postgres postgres 4096 May 31 17:46 archive drwxrwxr-x 2 postgres postgres 4096 May 30 16:16 backup drwx------ 3 postgres postgres 4096 May 31 17:46 data drwxrwxr-x 2 postgres postgres 4096 May 30 16:09 log -rw-rw-r-- 1 postgres postgres 82 May 16 14:03 out_file -rw-rw-r-- 1 postgres postgres 128 May 16 13:52 out.txt drwxrwxr-x 2 postgres postgres 4096 May 30 16:16 scripts -rw-r--r-- 1 postgres postgres 20 May 16 15:39 test.sql
【参考文献】
标签:
原文地址:http://www.cnblogs.com/lottu/p/5546792.html