https://ossc-db.github.io/pg_rman/index.html


下载安装

[root@bcscm tmp]# wget https://github.com/ossc-db/pg_rman/releases/download/V1.3.9/pg_rman-1.3.9-1.pg12.rhel8.x86_64.rpm
[root@bcscm tmp]# dnf install -y pg_rman-1.3.9-1.pg12.rhel8.x86_64.rpm


设置PGDATA和BACKUP_PATH路径

export PGDATA=/u01/pgdata/wiki
export BACKUP_PATH=/u01/backup/db/pg



初始化catalog

[postgres@bcscm pg_arch]$  pg_rman init  
INFO: ARCLOG_PATH is set to '/u01/pgdata/wiki/pg_arch'
INFO: SRVLOG_PATH is set to '/u01/pgdata/wiki/log'


全备/增量/归档

[postgres@bcscm pg]$ pg_rman backup --backup-mode=full --with-serverlog --progress
INFO: copying database files
Processed 2250 of 2250 files, skipped 0
INFO: copying archived WAL files
Processed 4 of 4 files, skipped 0
INFO: copying server log files
Processed 7 of 7 files, skipped 0
INFO: backup complete
INFO: Please execute 'pg_rman validate' to verify the files are correctly copied.

[postgres@bcscm ~]$ pg_rman backup  --backup-mode=incremental
INFO: copying database files
INFO: copying archived WAL files
INFO: backup complete
INFO: Please execute 'pg_rman validate' to verify the files are correctly copied.


[postgres@bcscm ~]$ pg_rman backup  --backup-mode=archive
INFO: copying archived WAL files
INFO: backup complete
INFO: Please execute 'pg_rman validate' to verify the files are correctly copied.



验证-不经过验证的备份无法正常使用

[postgres@bcscm pg]$ pg_rman validate
INFO: validate: "2020-06-17 17:24:02" backup, archive log files and server log files by CRC
INFO: backup "2020-06-17 17:24:02" is valid


查看备份

[postgres@bcscm pg]$ pg_rman show
=====================================================================
 StartTime           EndTime              Mode    Size   TLI  Status
=====================================================================
2020-06-17 17:24:02  2020-06-17 17:24:08  FULL   393MB     1  OK



异机异构恢复

#
# 新机备份位置/u01/cfbackup
# 新机数据文件位置/u01/cfdata
#

#1,复制备份到目标位置
/u01/cfbackup

#2,更改备份配置文件pg_rman.ini
ARCLOG_PATH='/u01/cfdata/pg_arch'
SRVLOG_PATH='/u01/cfdata/log'

#3,检查环境变量
-bash-4.2$ env | grep PGDATA
PGDATA=/u01/cfdata
-bash-4.2$ env | grep BACKUP_PATH
BACKUP_PATH=/u01/cfbackup

#4,恢复
-bash-4.2$  pg_rman restore --recovery-target-time '2020-06-17 17:47:16'
WARNING: pg_controldata file "/u01/cfdata/global/pg_control" does not exist
INFO: the recovery target timeline ID is not given
INFO: use timeline ID of latest full backup as recovery target: 1
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: "2020-06-17 17:24:02"
INFO: copying online WAL files and server log files
INFO: clearing restore destination
INFO: validate: "2020-06-17 17:24:02" backup, archive log files and server log files by SIZE
INFO: backup "2020-06-17 17:24:02" is valid
INFO: restoring database files from the full mode backup "2020-06-17 17:24:02"
INFO: searching incremental backup to be restored
INFO: validate: "2020-06-17 17:46:55" backup and archive log files by SIZE
INFO: backup "2020-06-17 17:46:55" is valid
INFO: restoring database files from the incremental mode backup "2020-06-17 17:46:55"
INFO: searching backup which contained archived WAL files to be restored
INFO: backup "2020-06-17 17:46:55" is valid
INFO: restoring WAL files from backup "2020-06-17 17:46:55"
INFO: validate: "2020-06-17 17:47:16" archive log files by SIZE
INFO: backup "2020-06-17 17:47:16" is valid
INFO: restoring WAL files from backup "2020-06-17 17:47:16"
INFO: restoring online WAL files and server log files
INFO: add recovery related options to postgresql.conf
INFO: generating recovery.signal
INFO: restore complete
HINT: Recovery will start automatically when the PostgreSQL server is started.




  • No labels