pg_rman是一款专门为postgresql设计的在线备份恢复的工具。其支持在线和基于时间点备份方式,还可以通过创建backup catalog来维护DB cluster备份信息。 - 使用简单.一个命令即可完成备份和恢复. - 支持在线全备,增量备份,归档备份. - 支持备份压缩.通过gzip工具实现页内压缩. - 自动备份维护.自动删除过期的WAL备份文件. - 支持备份验证. - 恢复期间无事务丢失.支持基于PITR的配置文件生成器.
找到对应版本下载,默认安装到路径/usr/pgsql-13/bin
https://github.com/ossc-db/pg_rman/releases
wget https://github.com/ossc-db/pg_rman/releases/download/V1.3.14/pg_rman-1.3.14-1.pg13.rhel8.x86_64.rpm
yum install pg_rman-1.3.14-1.pg13.rhel8.x86_64.rpm
sed -ir "s/#*max_wal_senders.*/max_wal_senders = 10/" postgresql.conf
sed -ir "s/#*max_replication_slots.*/max_replication_slots= 10/" postgresql.conf
sed -ir "s/#*hot_standby .*/hot_standby = on/" postgresql.conf
sed -ir "s/#*wal_level.*/wal_level = replica/" postgresql.conf
sed -ir "s/#*archive_mode.*/archive_mode = on/" postgresql.conf
sed -ir "s/#*archive_command.*/archive_command = '\/bin\/true'/" postgresql.conf
# 检查
cat postgresql.conf | grep "max_replication_slots\|max_wal_senders\|wal_level\|archive_mode\|archive_command\|hot_standby "
修改完重启
systemctl restart postgresql-13
[root@lys-mysql pg_rman]# /usr/pgsql-13/bin/pg_rman --backup-path /lys/data/pg_rman --pgdata /var/lib/pgsql/13/data --arclog-path /lys/data/arclog init
INFO: ARCLOG_PATH is set to '/lys/data/arclog'
INFO: SRVLOG_PATH is set to '/var/lib/pgsql/13/data/log'
[root@lys-mysql pg_rman]# /usr/pgsql-13/bin/pg_rman --backup-path /lys/data/pg_rman --pgdata /var/lib/pgsql/13/data --arclog-path /lys/data/arclog backup -b full -U user001 -d db001 -h 127.0.0.1 -p 5432
Password for user user001:
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.
增量备份前必须先验证
[root@lys-mysql pg_rman]# /usr/pgsql-13/bin/pg_rman --backup-path /lys/data/pg_rman --pgdata /var/lib/pgsql/13/data validate
INFO: validate: "2022-07-28 08:04:54" backup and archive log files by CRC
INFO: backup "2022-07-28 08:04:54" is valid
[root@lys-mysql pg_rman]# /usr/pgsql-13/bin/pg_rman --backup-path /lys/data/pg_rman --pgdata /var/lib/pgsql/13/data show
=====================================================================
StartTime EndTime Mode Size TLI Status
=====================================================================
2022-07-28 08:05:51 2022-07-28 08:05:54 INCR 0B 1 ERROR
2022-07-28 08:04:54 2022-07-28 08:05:00 FULL 37MB 1 OK
[root@lys-mysql pg_rman]# /usr/pgsql-13/bin/pg_rman --backup-path /lys/data/pg_rman --pgdata /var/lib/pgsql/13/data validate
INFO: validate: "2022-07-28 08:08:05" backup and archive log files by CRC
INFO: backup "2022-07-28 08:08:05" is valid
[root@lys-mysql pg_rman]# /usr/pgsql-13/bin/pg_rman --backup-path /lys/data/pg_rman --pgdata /var/lib/pgsql/13/data show
=====================================================================
StartTime EndTime Mode Size TLI Status
=====================================================================
2022-07-28 08:08:05 2022-07-28 08:08:10 INCR 24kB 1 OK
2022-07-28 08:05:51 2022-07-28 08:05:54 INCR 0B 1 ERROR
2022-07-28 08:04:54 2022-07-28 08:05:00 FULL 37MB 1 OK
[root@lys-mysql pg_rman]# /usr/pgsql-13/bin/pg_rman --backup-path /lys/data/pg_rman --pgdata /var/lib/pgsql/13/data delete "2022-07-28 08:05:51"
INFO: delete the backup with start time: "2022-07-28 08:05:51"
WARNING: cannot delete backup with start time "2022-07-28 08:04:54"
DETAIL: This is the latest full backup necessary for successful recovery.
[root@lys-mysql pg_rman]# /usr/pgsql-13/bin/pg_rman --backup-path /lys/data/pg_rman --pgdata /var/lib/pgsql/13/data show
=====================================================================
StartTime EndTime Mode Size TLI Status
=====================================================================
2022-07-28 08:08:05 2022-07-28 08:08:10 INCR 24kB 1 OK
2022-07-28 08:04:54 2022-07-28 08:05:00 FULL 37MB 1 OK
以上内容摘自《PolarDB for Postgres SQL 》电子书,点击https://developer.aliyun.com/ebook/download/7673可下载完成版
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
PolarDB 分布式版 (PolarDB for Xscale,简称“PolarDB-X”) 是阿里云自主设计研发的高性能云原生分布式数据库产品,为用户提供高吞吐、大存储、低延时、易扩展和超高可用的云时代数据库服务。