pg_probackup
[1] https://postgrespro.com/docs/enterprise/13/app-pgprobackup
- PITR依赖continuous WAL archiving:
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的更多相关文章
随机推荐
- Java实现爬取京东手机数据
Java实现爬取京东手机数据 最近看了某马的Java爬虫视频,看完后自己上手操作了下,基本达到了爬数据的要求,HTML页面源码也刚好复习了下,之前发布两篇关于简单爬虫的文章,也刚好用得上.项目没什么太 ...
- Python - __all__ 变量
import * 当我们向文件导入某个模块时,导入的是该模块中那些名称不以下划线(单下划线 _ 或者双下划线 __ )开头的变量.函数和类 因此,如果不想模块文件中的某个对象被引入到其它文件中使用,可 ...
- CentOS7安装Python3和VIM8
参考:http://blog.sina.com.cn/s/blog_45249ad30102yulz.html
- 从零入门 Serverless | Serverless Kubernetes 应用部署及扩缩容
作者 | 邓青琳(轻零) 阿里云技术专家 导读:本文分为三个部分,首先给大家演示 Serverless Kubernetes 集群的创建和业务应用的部署,其次介绍 Serverless Kuberne ...
- Vue3学习(六)之使用Vue3进行数据绑定及显示列表数据
一.写在前面 说来还是比较惭愧的,从周二开始事就比较多,周三还电脑坏了,然后修电脑等等一些杂事,忙的团团转,因为周二.周三自己走的过多了,导致不敢直腰,周四卧床一天. 之前都听说<陈情令> ...
- Scrum Meeting 1补充会议
日期:2021年04月24日 会议主要内容概述: 本次会议于11:30举行,对项目架构做出了重要调整,并根据该调整修改了第1次例会报告中后两日计划完成的工作部分. 一.架构调整 会上讨论了用户模块相关 ...
- Noip模拟77 2021.10.15
T1 最大或 $T1$因为没有开$1ll$右移给炸掉了,调了一年不知道为啥,最后实在不懂了 换成$pow$就过掉了,但是考场上这题耽误了太多时间,后面的题也就没办法好好打了.... 以后一定要注意右移 ...
- 主仆见证了 Hobo 的离别 题解
前言: 题面挺神仙.反正我考试的时候看了40分钟也没看懂. 后来改题感觉自己写的挺假,没想到加个\(k==1\)的特判竟然就A了?无语力. 解析: 看懂题以后就好说了.首先这显然是一个树形结构.我们考 ...
- 【BZOJ 1419】Red is good [概率DP]
我 是 Z Z 概率好玄啊(好吧是我太弱.jpg Description 桌面上有R张红牌和B张黑牌,随机打乱顺序后放在桌面上,开始一张一张地翻牌,翻到红牌得到1美元,黑牌则付出1美元.可以随时停止翻 ...
- Balance的数学思想构造辅助函数
本类题的证明难点便在于如何构造出满足答案的辅助函数.通过下列类题便可以很好的理解. 题一 该类题可以理解为积分内部f(x)与xf(x)处于一种失衡状态,故我们需要使其平衡,否则直接构造出的函数无法满足 ...