DBAtlas · 数据库运维图谱

使用 pgBackRest 进行全量、差异和增量备份

PostgreSQL备份与 PITR

命令

sudo -u postgres pgbackrest --stanza=<stanza> --type=full backup
sudo -u postgres pgbackrest --stanza=<stanza> --type=diff backup   # changes since the last full
sudo -u postgres pgbackrest --stanza=<stanza> --type=incr backup   # changes since the last backup of any type
# cron example (postgres user): full on Sunday, diff on other days
# 30 1 * * 0   pgbackrest --stanza=<stanza> --type=full backup
# 30 1 * * 1-6 pgbackrest --stanza=<stanza> --type=diff backup

作用

全量备份复制整个集群,diff 复制自上次全量以来变化的文件,incr 复制自上次任意类型备份以来变化的文件;结束时会验证所需的 WAL 已归档,并按保留策略自动运行 expire。

适用场景

在常规备份计划中:通常每周全量 + 每日 diff/incr,大型集群可更频繁地做 incr。

注意

如果之前没有全量备份,diff/incr 请求会自动升级为全量。incr 链越长,还原时间和依赖性越大;链中丢失一个备份会使之后的备份不可用。为减轻主库负担,可用 backup-standby=y 从备库备份(仍需要主库进行协调)。

在 DBAtlas 中打开 →

相关内容