PostgreSQL 学习实践:使用pg_rman1.3进行PG15备份恢复
pg_rman
是一款用于备份和恢复 PostgreSQL 数据库的插件。其功能类似于 Oracle 的 RMAN 工具
支持以下三种备份类型:
完整备份:备份整个数据库集群。
增量备份:仅备份在同一时间线上次验证备份后修改的文件或页面。
归档 WAL备份:仅备份归档WAL文件。
部署安装:
下载地址:
https://github.com/ossc-db/pg_rman/releases
安装:
#上传文件至/opt
cd /opt
#解压文件:
tar zxvf pg_rman-1.3.16-pg15.tar.gz
#解压完成后:
chown -R postgres.postgres /opt/pg_rman-1.3.16-pg15
su - postges
cd /opt/pg_rman-1.3.16-pg15
make
make install
#安装完成后校验版本
[postgres@wypg15 pg_rman-1.3.16-pg15]$ pg_rman --version
pg_rman 1.3.16
#安装位置
[postgres@wypg15 pg_rman-1.3.16-pg15]$ which pg_rman
/postgresql/pg15/bin/pg_rman
#使用帮助
[postgres@wypg15 pg_rman-1.3.16-pg15]$ pg_rman --help
pg_rman manage backup/recovery of PostgreSQL database.
Usage:
pg_rman OPTION init
pg_rman OPTION backup
pg_rman OPTION restore
pg_rman OPTION show [DATE]
pg_rman OPTION show detail [DATE]
pg_rman OPTION validate [DATE]
pg_rman OPTION delete DATE
pg_rman OPTION purge
Common Options:
-D, --pgdata=PATH location of the database storage area
-A, --arclog-path=PATH location of archive WAL storage area
-S, --srvlog-path=PATH location of server log storage area
-B, --backup-path=PATH location of the backup storage area
-G, --pgconf-path=PATH location of the configuration storage area
-c, --check show what would have been done
-v, --verbose show what detail messages
-P, --progress show progress of processed files
Backup options:
-b, --backup-mode=MODE full, incremental, or archive
-s, --with-serverlog also backup server log files
-Z, --compress-data compress data backup with zlib
-C, --smooth-checkpoint do smooth checkpoint before backup
-F, --full-backup-on-error switch to full backup mode
if pg_rman cannot find validate full backup
on current timeline
NOTE: this option is only used in --backup-mode=incremental or archive.
--keep-data-generations=NUM keep NUM generations of full data backup
--keep-data-days=NUM keep enough data backup to recover to N days ago
--keep-arclog-files=NUM keep NUM of archived WAL
--keep-arclog-days=DAY keep archived WAL modified in DAY days
--keep-srvlog-files=NUM keep NUM of serverlogs
--keep-srvlog-days=DAY keep serverlog modified in DAY days
--standby-host=HOSTNAME standby host when taking backup from standby
--standby-port=PORT standby port when taking backup from standby
Restore options:
--recovery-target-time time stamp up to which recovery will proceed
--recovery-target-xid transaction ID up to which recovery will proceed
--recovery-target-inclusive whether we stop just after the recovery target
--recovery-target-timeline recovering into a particular timeline
--recovery-target-action action the server should take once the recovery target is reached
--hard-copy copying archivelog not symbolic link
Catalog options:
-a, --show-all show deleted backup too
Delete options:
-f, --force forcibly delete backup older than given DATE
Connection options:
-d, --dbname=DBNAME database to connect
-h, --host=HOSTNAME database server host or socket directory
-p, --port=PORT database server port
-U, --username=USERNAME user name to connect as
-w, --no-password never prompt for password
-W, --password force password prompt