PG-pg_rman物理备份工具
g_rman 物理备份
pg_rman是一款专门为postgresql设计的在线备份恢复的工具。其支持在线和基于时间点备份方式,还可以通过创建backup catalog来维护DB cluster备份信息。
pg_rman特点
- 使用简单一个命令即可完成备份和恢复
- 支持在线全备,增量备份,归档备份
- 支持备份压缩.通过gzip工具实现页内压缩
- 自动备份维护.自动删除过期的WAL备份文件
- 支持备份验证
- 恢复期间无事务丢失.支持基于PITR的配置文件生成器
下载地址
软件安装
wget https://github.com/ossc-db/pg_rman/releases/download/V1.3.13/pg_rman-1.3.13-pg12.tar.gz
tar -xf pg_rman-1.3.13-pg12.tar.gz
cd pg_rman-1.3.13-pg12
yum -y install zlib-devel
make
make install
pg_rman的用法(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
-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
--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
Generic options:
-q, --quiet don't show any INFO or DEBUG messages
--debug show DEBUG messages
--help show this help, then exit
--version output version information, then exit
备份操作
全量备份
[postgres@progs pg_rman]$ pg_rman backup --backup-mode=full --backup-path=/ups/data/pgdata/12/backups/pg_rman
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@progs pg_rman]$
增量备份
pg_rman backup --backup-mode=incremental --backup-path=/ups/data/pgdata/12/backups/pg_rman
备份集校验
# 每次备份完,必须要做一次校验,否则备份集不可用用来恢复,增量备份时也不会用它来做增量比较
export BACKUP_PATH='/ups/data/pgdata/12/backups/pg_rman' && pg_rman validate
pg_rman validate --backup-path=/ups/data/pgdata/12/backups/pg_rman
查看备份集
pg_rman show
删除备份集
删除指定时间的备份集
# 从catalog删除指定时间的备份集
## 例如:只需要能恢复到2021-09-23 11:00:00,在这个时间点以前的不需要用来恢复到这个时间点的备份全删掉
pg_rman delete '2021-09-23 11:00:00'
根据备份策略来删除备份集
# 在备份时,指定备份策略
pg_rman backup --backup-mode=incremental --keep-data-generations=2 --keep-data-days=10 --keep-data-generations=2
清除备份集
它不是删除备份集中物理文件,仅删除catalog中的备份条目
pg_rman purge
恢复操作
恢复操作选项
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
使用最新全备恢复到$PGDATA目录
[postgres@progs pg_rman]$ export PGDATA=/tmp/pg_recov
[postgres@progs pg_rman]$ pg_rman restore
分类:
数据库(PostgreSQL)
标签:
postgresql
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)