作者
Anna Bellandi
译者简介
张岩&崔鹏&海能达DBA团队,任职于海能达通信股份有限公司哈尔滨平台中心,数据库开发高级工程师,致力于PostgreSQL数据库在专网通信领域、公共安全领域的应用与推广,个人兴趣主要集中在:分布式数据库系统设计、高并发高可用数据库架构设计与开源数据库的源码研究。
校对者简介
赵全明 华为云资深数据库内核专家,PG中文社区核心委员。多年数据库管理及研发经验,包括Oracle、MySQL、PostgreSQL,曾参与华为云RDS管控研发、GaussDB多个版本的研发,在SQL引擎、高可用、高可靠方面有着丰富的经验,致力于openGauss及PostgreSQL在金融、政企、互联网等行业的应用与推广。
由于在Barman 2.11中引入了新的实用程序barman-cloud-restore和barman-cloud-wal-restore,现在可以使用以前使用的barman-cloud-wal-archive和 barman-cloud-backup命令执行的完全备份来执行PostgreSQL实例的恢复。在下一篇文章中,我们一起探索如何实现这一点。
值得注意的是,在Barman 2.11中,Barman的所有云实用程序现在都位于一个称为barman-cli-cloud的单独软件包中。
要求
1. barman-cli-cloud软件包
2.一个PostgreSQL实例
3.一个AWS S3桶
4.执行恢复的第二台虚拟机
在本文中,我们将使用Debian Buster和PostgreSQL 12在虚拟机中测试barman-cli-cloud功能。为了正确遵循本文中包含的说明,我们还假定您具有:
l. 配置的Postgres使用barman-cloud-wal-archive将WAL文件存档到现有的S3存储桶
l. 执行备份并将其通过barman-cloud-backup发送到同一个的S3存储桶
您可以按照以前的博客文章中包含的说明轻松实现此目的:
l. Barman Cloud – Part 1: WAL Archive
l. Barman Cloud – Part 2: Cloud Backup
设置恢复服务器
作为一个结果,我们在AWS上有一个名为barman-s3-test的S3桶,该存储桶已经包含WAL文件和通过barman-cloud-wal-archive和barman-cloud-backup工具存档的备份,现在我们需要正确配置服务器将主机恢复PostgreSQL实例。
1.从官方的PGDG仓库下载安装PostgreSQL 12
2.安装2ndQuadrant公共仓库
3.安装barman-cli-cloud软件包:
root@recovery:~# apt update
root@recovery:~# apt install barman-cli-cloud
4.安装awscli软件包:
root@recovery:~# apt install awscli
5.使用awscli工具将AWS凭证配置为postgres用户:
postgres@recovery:~$ aws configure --profile barman-cloud
AWS Access Key ID [None]: AKI*****************
AWS Secret Access Key [None]: ****************************************
Default region name [None]: eu-west-1
Default output format [None]: json
执行恢复
现在已经正确配置了恢复服务器,我们可以准备开始恢复过程。
Barman 2.11引入了barman-cloud-backup-list命令,该命令可让您检索有关使用barman-cloud-backup进行的备份的信息:
postgres@recovery:~$ barman-cloud-backup-list \
--profile barman-cloud \
s3://barman-s3-test pg12
Backup ID End Time Begin Wal
20200713T120856 2020-07-13 12:09:05 00000001000000000000000C
现在,我们准备使用barman-cloud-restore命令执行恢复:
postgres@recovery:~$ barman-cloud-restore \
--profile barman-cloud \
s3://barman-s3-test \
pg12 20200713T120856 \
/var/lib/postgresql/12/main/
恢复结束后,我们可以检查PGDATA目录的内容:
postgres@recovery:~$ ls /var/lib/postgresql/12/main/
PG_VERSION global pg_hba.conf pg_multixact pg_serial pg_stat_tmp pg_twophase postgresql.auto.conf
backup_label pg_commit_ts pg_ident.conf pg_notify pg_snapshots pg_subtrans pg_wal postgresql.conf
base pg_dynshmem pg_logical pg_replslot pg_stat pg_tblspc pg_xact
现在,为了确保恢复过程正常,我们需要启动已恢复的PostgreSQL实例并验证一切均如预期一样。此过程需要一些额外的步骤。
首先,由于我们使用的是Debian系统,因此需要在/ etc / postgresql / 12 / main /目录下复制包含PostgreSQL配置的文件:
postgres@recovery:~$ cp /var/lib/postgresql/12/main/postgresql.conf /etc/postgresql/12/main/
postgres@recovery:~$ cp /var/lib/postgresql/12/main/pg_hba.conf /etc/postgresql/12/main/
postgres@recovery:~$ cp /var/lib/postgresql/12/main/pg_ident.conf /etc/postgresql/12/main/
其次,创建recovery.signal文件:
postgres@recovery:~$ touch /var/lib/postgresql/12/main/recovery.signal
然后,禁用archive_command以阻止恢复的实例写入到与原始实例相同的桶中:
postgres@recovery:~$ echo \"archive_command = 'cd .'\" >> /etc/postgresql/12/main/postgresql.conf
之后,您需要配置PostgreSQL,以使用restore_command中的barman-cloud-wal-restore从S3存储桶中检索最新可用时间线的WAL文件:
postgres@recovery:~$ echo \"restore_command = 'barman-cloud-wal-restore --profile barman-cloud s3://barman-s3-test pg12 %f %p'\" >> /etc/postgresql/12/main/postgresql.conf
postgres@recovery:~$ echo \"recovery_target_timeline = 'latest'\" >> /etc/postgresql/12/main/postgresql.conf
重要信息:在继续操作之前,请确保PostgreSQL实例未运行,并且目标目录(默认PostgreSQL数据目录)为空。
最后,我们准备开始启动新的恢复实例:
root@recovery:~# systemctl restart postgresql@12-main.service
太棒了!正如我们从PostgreSQL日志中看到的,从S3存储桶中恢复了WAL文件,并且实例已正确启动:
postgres@recovery:~$ less /var/log/postgresql/postgresql-12-main.log...2020-07-13 12:43:25.093 UTC [9458] LOG: starting PostgreSQL 12.3 (Debian 12.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit2020-07-13 12:43:25.093 UTC [9458] LOG: listening on IPv4 address "127.0.0.1", port 54322020-07-13 12:43:25.095 UTC [9458] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"2020-07-13 12:43:25.111 UTC [9459] LOG: database system was interrupted; last known up at 2020-07-13 12:08:56 UTC2020-07-13 12:43:25.508 UTC [9459] LOG: starting archive recovery2020-07-13 12:43:26.010 UTC [9459] LOG: restored log file "00000001000000000000000C" from archive2020-07-13 12:43:26.052 UTC [9459] LOG: redo starts at 0/C0000282020-07-13 12:43:26.054 UTC [9459] LOG: consistent recovery state reached at 0/C0001382020-07-13 12:43:26.054 UTC [9458] LOG: database system is ready to accept read only connections2020-07-13 12:43:26.469 UTC [9459] LOG: restored log file "00000001000000000000000D" from archive2020-07-13 12:43:26.823 UTC [9459] LOG: redo done at 0/D0001B02020-07-13 12:43:27.242 UTC [9459] LOG: restored log file "00000001000000000000000D" from archive2020-07-13 12:43:27.592 UTC [9459] LOG: selected new timeline ID: 22020-07-13 12:43:27.644 UTC [9459] LOG: archive recovery complete2020-07-13 12:43:27.979 UTC [9458] LOG: database system is ready to accept connections
结论
与任何新发行的Barman一样,我们建议每个人都将其系统更新为最新版本。此处提供了更改和bug修复的完整列表。
请注意,如果您正在使用通过RPM / Apt软件包安装的barman-cloud-wal-archive或barman-cloud-backup,则必须安装barman-cli-cloud软件包才能升级。这是因为:在Barman 2.11发行版中,所有与云相关的工具都是barman-cli-cloud软件包的一部分,如本文开头所述。
下一版本的Barman可能会像实际的Barman一样通过准备recovery.conf或recovery.signal文件来提高restore命令的易用性和自动化能力。
原文出处
PostgreSQL中文社区欢迎广大技术人员投稿
投稿邮箱:press@postgres.cn
http://ly.shtcxxw.cn/wuwei/ http://wutai.cqtcxxw.cn/lishui/ https://beiwaitan.tiancebbs.cn/ https://fenlei.tiancebbs.cn/qitaihe/ http://xinguang.sctcbmw.cn/chuzhou/ http://nalei.zjtcbmw.cn/hbhg/ http://taiying.njtcbmw.cn/fjmchs/ http://tuiguang.hntcxxw.cn/putuosh/ http://shenghuo.china-bbs.com/cqrc/ http://ouyu.hftcbmw.cn/guangdong/ https://hukouzhen.tiancebbs.cn/ http://js.sytcxxw.cn/kspx/ https://huayuanqiao.tiancebbs.cn/ http://jinqiang.ahtcbmw.cn/quanguo/ https://jiuzhaigou.tiancebbs.cn/ http://ouyu.hftcbmw.cn/qinzhou/ http://taiying.njtcbmw.cn/gren/
政协提案范文:https://www.deipei.com/fanwen/1276.html 生活中的科学作文:https://www.deipei.com/zuowen/1205.html 有余数的除法教学设计:https://www.deipei.com/jiaoxue/1146.html 自我批评个人不足与改进措施:https://www.deipei.com/gongzuo/1353.html 执行异议申请书:https://www.deipei.com/fanwen/1459.html 团支部工作计划:https://www.deipei.com/jihua/1236.html 实践出真知的事例:https://www.deipei.com/yuedu/1358.html 像花儿一样绽放作文:https://www.deipei.com/zuowen/1444.html 班会总结:https://www.deipei.com/zongjie/1285.html 个人检视剖析材料:https://www.deipei.com/shijicailiao/1363.html 旅游计划书:https://www.deipei.com/fanwen/1417.html 小学语文教学案例:https://www.deipei.com/jiaoxue/1206.html 三会一课会议记录:https://www.deipei.com/gongzuo/1087.html 民主生活会征求意见:https://www.deipei.com/gongzuo/1336.html 合同终止协议:https://www.deipei.com/hetong/1338.html 小学后勤工作总结:https://www.deipei.com/zongjie/1265.html 实践心得体会:https://www.deipei.com/xindetihui/1061.html 学前教育论文:https://www.deipei.com/xuexi/1180.html 教师个人年度总结:https://www.deipei.com/zongjie/1322.html 二审答辩状:https://www.deipei.com/fanwen/1440.html 管理能力提升心得体会:https://www.deipei.com/xindetihui/1113.html 我与企业共成长演讲稿:https://www.deipei.com/yanjianggao/1360.html 整治方案:https://www.deipei.com/fangan/1492.html 鸡兔同笼教学设计:https://www.deipei.com/jiaoxue/1316.html 夸父追日读后感:https://www.deipei.com/duhougan/1072.html 技术总结:https://www.deipei.com/zongjie/1099.html 个人安全预案:https://www.deipei.com/fangan/1273.html 月考成绩分析总结与反思:https://www.deipei.com/xuexi/1350.html 纪律作风方面存在的问题及整改措施:https://www.deipei.com/zongjie/1256.html 组织生活会谈心谈话记录:https://www.deipei.com/gongzuo/1334.html