[1] https://postgrespro.com/docs/enterprise/13/app-pgprobackup

Making backups in PAGE backup mode, performing PITR and making backups with ARCHIVE WAL delivery mode require continuous WAL archiving to be enabled.

You can use both STREAM and ARCHIVE backups for point in time recovery as long as the WAL archive is available at least starting from the time the backup was taken.

  • PTRACK增量备份模式,及incremental restore,要求initdb时--data-checksums.
  • todo stream,archive有什么区别

初始化

pg_probackup init -B $HOME/probackup
pg_probackup add-instance -B $HOME/probackup -D $HOME/pgdata2 --instance pg5433
archive_mode = on
archive_command = '"$HOME/.local/pgsql/bin/pg_probackup" archive-push -B "$HOME/probackup" --instance pg5433 --wal-file-name=%f'
# pg_ctl start

全量,及PAGE增量备份

pg_probackup backup -B $HOME/probackup --instance pg5433 -b FULL -p 5433 -d postgres
pg_probackup backup -B $HOME/probackup --instance pg5433 -b PAGE -p 5433 -d postgres
pg_probackup backup -B $HOME/probackup --instance pg5433 -b PAGE -p 5433 -d postgres --log-level-file=info
# --log-level-file默认off,打开后默认记录在-B/log
pg_probackup show -B $HOME/probackup
BACKUP INSTANCE 'pg5433'
=================================================================================================================================
Instance Version ID Recovery Time Mode WAL Mode TLI Time Data WAL Zratio Start LSN Stop LSN Status
=================================================================================================================================
pg5433 13 R2RP9H 2021-11-18 20:27:17+08 PAGE ARCHIVE 1/1 1s 106kB 16MB 1.00 0/8000028 0/90000B8 OK
pg5433 13 R2RP38 2021-11-18 20:23:32+08 PAGE ARCHIVE 1/1 1s 106kB 16MB 1.00 0/5000028 0/60000F0 OK
pg5433 13 R2RP1U 2021-11-18 20:22:44+08 FULL ARCHIVE 1/0 6s 23MB 16MB 1.00 0/2000028 0/30000F0 OK pg_probackup show -B $HOME/probackup --instance pg5433
pg_probackup show -B $HOME/probackup --archive

删除不需要的备份数据

pg_probackup delete -B $HOME/probackup --instance pg5433 --delete-expired
pg_probackup delete -B $HOME/probackup --instance pg5433 --delete-wal
pg_probackup delete -B $HOME/probackup --instance pg5433 --status=ERROR

恢复

pg_probackup validate -B $HOME/probackup --instance pg5433
pg_probackup restore -B $HOME/probackup --instance pg5433 -D $HOME/pgdata2-restored pg_probackup validate -B $HOME/probackup --instance pg5433 --recovery-target-time="2021-11-18 20:15:32+08"
# => ERROR: Backup satisfying target options is not found.
pg_probackup validate -B $HOME/probackup --instance pg5433 --recovery-target-time="2021-11-18 20:23:32+08"
pg_probackup validate -B $HOME/probackup --instance pg5433 --recovery-target-time="2021-11-18 20:25:32+08"
# => INFO: Backup validation completed successfully on time 2021-11-18 20:23:32+08, xid 485 and LSN 0/60000F0
pg_probackup validate -B $HOME/probackup --instance pg5433 --recovery-target-time="2021-11-18 20:35:32+08"
# => WARNING: Thread [1]: Could not read WAL record at 0/A000000
# ERROR: Thread [1]: WAL segment "/home/fang/probackup/wal/pg5433/00000001000000000000000A" is absent
# WARNING: Recovery can be done up to time 2021-11-18 20:27:17+08, xid 485 and LSN 0/90000B8
# ERROR: Not enough WAL records to time 2021-11-18 20:35:32+08 pg_probackup restore -B $HOME/probackup --instance pg5433 -D $HOME/pgdata2-restored2 --recovery-target-time="2021-11-18 20:23:32+08"

DELTA增量备份

pg_probackup backup -B $HOME/probackup --instance pg5433 -b DELTA -p 5433 -d postgres --log-level-file=info

PTRACK增量备份,要求--data-checksums

pg_probackup backup -B $HOME/probackup --instance pg5433 -b PTRACK -p 5433 -d postgres --log-level-file=info
# WARNING: This PostgreSQL instance was initialized without data block checksums. pg_probackup have no way to detect data block corruption without them. Reinitialize PGDATA with option '--data-checksums'.
# WARNING: Current PostgreSQL role is superuser. It is not recommended to run pg_probackup under superuser.
# ERROR: This PostgreSQL instance does not support ptrack
# WARNING: Backup R2TMDU is running, setting its status to ERROR pg_probackup show -B $HOME/probackup
BACKUP INSTANCE 'pg5433'
=====================================================================================================================================
Instance Version ID Recovery Time Mode WAL Mode TLI Time Data WAL Zratio Start LSN Stop LSN Status
=====================================================================================================================================
pg5433 13 R2TMDU ---- PTRACK ARCHIVE 0/0 0 0 0 1.00 0/0 0/0 ERROR
pg5433 13 R2TMDK 2021-11-19 21:20:08+08 DELTA ARCHIVE 1/1 1s 106kB 16MB 1.00 0/11000028 0/120000B8 OK
pg5433 13 R2SQBU 2021-11-19 09:47:54+08 PAGE ARCHIVE 1/1 1s 106kB 16MB 1.00 0/E000028 0/F0000B8 OK
pg5433 13 R2SQAS 2021-11-19 09:47:16+08 PAGE ARCHIVE 1/1 1s 106kB 16MB 1.00 0/B000028 0/C0000B8 OK
pg5433 13 R2RP9H 2021-11-18 20:27:17+08 PAGE ARCHIVE 1/1 1s 106kB 16MB 1.00 0/8000028 0/90000B8 OK
pg5433 13 R2RP38 2021-11-18 20:23:32+08 PAGE ARCHIVE 1/1 1s 106kB 16MB 1.00 0/5000028 0/60000F0 OK
pg5433 13 R2RP1U 2021-11-18 20:22:44+08 FULL ARCHIVE 1/0 6s 23MB 16MB 1.00 0/2000028 0/30000F0 OK

在有交易时增量备份

pgbench -i -s 10 postgres
pgbench -c 2 -T 100 -R 100 postgres
pg_probackup backup -B $HOME/probackup --instance pg5433 -b PAGE -p 5433 -d postgres --log-level-file=info
pg_probackup backup -B $HOME/probackup --instance pg5433 -b DELTA -p 5433 -d postgres --log-level-file=info
pg_probackup show -B $HOME/probackup
BACKUP INSTANCE 'pg5433'
====================================================================================================================================
Instance Version ID Recovery Time Mode WAL Mode TLI Time Data WAL Zratio Start LSN Stop LSN Status
====================================================================================================================================
pg5433 13 R2TMOZ 2021-11-19 21:26:59+08 DELTA ARCHIVE 1/1 1s 106kB 16MB 1.00 0/29000028 0/2A0000B8 OK
pg5433 13 R2TMOI 2021-11-19 21:26:42+08 PAGE ARCHIVE 1/1 1s 106kB 16MB 1.00 0/27000028 0/280000B8 OK
pg5433 13 R2TMO9 2021-11-19 21:26:34+08 DELTA ARCHIVE 1/1 2s 106kB 16MB 1.00 0/24000028 0/250000B8 OK
pg5433 13 R2TMO0 2021-11-19 21:26:24+08 PAGE ARCHIVE 1/1 1s 106kB 16MB 1.00 0/22000028 0/230000B8 OK
pg5433 13 R2TMNR 2021-11-19 21:26:16+08 DELTA ARCHIVE 1/1 2s 106kB 16MB 1.00 0/1F000028 0/200000B8 OK
pg5433 13 R2TMNH 2021-11-19 21:26:05+08 PAGE ARCHIVE 1/1 1s 106kB 16MB 1.00 0/1D000028 0/1E0000B8 OK
pg5433 13 R2TMNA 2021-11-19 21:25:58+08 DELTA ARCHIVE 1/1 1s 106kB 16MB 1.00 0/1B000028 0/1C0000F0 OK
pg5433 13 R2TMN1 2021-11-19 21:25:50+08 PAGE ARCHIVE 1/1 2s 106kB 16MB 1.00 0/19000028 0/1A0000B8 OK
pg5433 13 R2TMMR 2021-11-19 21:25:39+08 DELTA ARCHIVE 1/1 1s 106kB 16MB 1.00 0/17000028 0/180000B8 OK
pg5433 13 R2TMM7 2021-11-19 21:25:20+08 PAGE ARCHIVE 1/1 2s 106kB 16MB 1.00 0/14000028 0/150000B8 OK
pg5433 13 R2TMDK 2021-11-19 21:20:08+08 DELTA ARCHIVE 1/1 1s 106kB 16MB 1.00 0/11000028 0/120000B8 OK
pg5433 13 R2SQBU 2021-11-19 09:47:54+08 PAGE ARCHIVE 1/1 1s 106kB 16MB 1.00 0/E000028 0/F0000B8 OK
pg5433 13 R2SQAS 2021-11-19 09:47:16+08 PAGE ARCHIVE 1/1 1s 106kB 16MB 1.00 0/B000028 0/C0000B8 OK
pg5433 13 R2RP9H 2021-11-18 20:27:17+08 PAGE ARCHIVE 1/1 1s 106kB 16MB 1.00 0/8000028 0/90000B8 OK
pg5433 13 R2RP38 2021-11-18 20:23:32+08 PAGE ARCHIVE 1/1 1s 106kB 16MB 1.00 0/5000028 0/60000F0 OK
pg5433 13 R2RP1U 2021-11-18 20:22:44+08 FULL ARCHIVE 1/0 6s 23MB 16MB 1.00 0/2000028 0/30000F0 OK pg_probackup validate -B $HOME/probackup --instance pg5433 --recovery-target-time="2021-11-19 21:26:32+08"
pg_probackup validate -B $HOME/probackup --instance pg5433 --recovery-target-time="2021-11-19 21:26:52+08"

增量恢复,两种模式(checksum,lsn)都需要--data-checksums

pg_probackup restore -B $HOME/probackup --instance pg5433 -D $HOME/pgdata2 -I lsn
pg_probackup restore -B $HOME/probackup --instance pg5433 -D $HOME/pgdata2 -I lsn
# INFO: Running incremental restore into nonempty directory: "/home/fang/pgdata2"
# WARNING: Postmaster with pid 1405 is running in destination directory "/home/fang/pgdata2"
# INFO: Trying to read pg_control file in destination directory
# ERROR: Incremental restore is not allowed
pg_ctl -D ~/pgdata2 -l ~/repos/postgres/logfile2 stop
# waiting for server to shut down.... done
# server stopped
pg_probackup restore -B $HOME/probackup --instance pg5433 -D $HOME/pgdata2 -I lsn
# INFO: Running incremental restore into nonempty directory: "/home/fang/pgdata2"
# INFO: Trying to read pg_control file in destination directory
# ERROR: Incremental restore in 'lsn' mode require data_checksums to be enabled in destination data directory

pg_probackup的更多相关文章

随机推荐

  1. MyBatis-Plus——实践篇

    MyBatis-Plus--实践篇 MyBatis-Plus (简称 MP)是一个 MyBatis的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发.提高效率而生.进行数据库操作常用 ...

  2. 使用CEF(二)— 基于VS2019编写一个简单CEF样例

    使用CEF(二)- 基于VS2019编写一个简单CEF样例 在这一节中,本人将会在Windows下使用VS2019创建一个空白的C++Windows Desktop Application项目,逐步进 ...

  3. SpringBoot如何实现定时任务

    写在前面 SpringBoot创建定时任务的方式很简单,主要有两种方式:一.基于注解的方式(@Scheduled)二.数据库动态配置.实际开发中,第一种需要在代码中写死表达式,如果修改起来,又得重启会 ...

  4. 对epoll机制的学习理解v1

    epoll机制 wrk用非阻塞多路复用IO技术创造出大量的连接,从而达到很好的压力测试效果.epoll就是实现IO多路复用的关键. 本节是对epoll的本质的学习总结,进一步的参考资料为: <深 ...

  5. SpringCloud-初见

    目录 前言 微服务概述 微服务与微服务架构 微服务优缺点 微服务技术栈 为什么选择SpringCloud作为微服务架构 SpringCloud入门 SpringCloud和SpringBoot的关系 ...

  6. Noip模拟83 2021.10.26

    T1 树上的数 有手就能在衡中$OJ$上过,但是$WaitingCoders$不行,就是这样 必须使用$O(n)$算法加上大力卡常,思路就是找子树内没更新的更新,更新过了直接$return$ 1 #i ...

  7. 按照工业标准1英寸=25.4mm,而在电子元件成像领域Sensor尺寸1英寸=16mm。

    按照工业标准1英寸=25.4mm,而在电子元件成像领域Sensor尺寸1英寸=16mm. 我们平常所说的CCD/CMOS的尺寸,实际上是指Sensor对角线的长度,这一点跟我们平常所说的屏幕尺寸是一样 ...

  8. 攻防世界 杂项 10.2017_Dating_in_Singapore

    题目描述: 01081522291516170310172431-050607132027262728-0102030209162330-02091623020310090910172423-0201 ...

  9. Docker 安装 MySQL8

    1. 环境准备 创建挂载数据目录和配置文件 mkdir -p /mnt/mysql/data /etc/mysql/conf touch /etc/mysql/conf/my.cnf 2. 拉取镜像 ...

  10. tar 解压分割压缩文件

    被分割后的压缩文件必须先合并成一个压缩文件才能正常的解压. 第一步.合并压缩文件 第二步.正常解压 $ls TINA-1.3.tar.gzaa TINA-1.3.tar.gzab TINA-1.3.t ...