PostgreSQL备份工具 pgBackRest使用详解

论坛 期权论坛 脚本     
niminba   2021-5-23 05:21   1813   0

前言

pgBackRest是一款开源的备份还原工具,目标旨在为备份和还原提供可靠易用的备份。

特性

并行备份和还原

备份操作期间压缩通常是其瓶颈所在。pgBackRest通过并行处理解决了备份期间压缩出现的瓶颈问题。

本地远程操作

自定义协议允许 pgBackRest以最小化配置通过SSH在本地或者远程执行备份、还原和归档。并且该程序也通过协议层提供了PostgreSQL查询接口,以便于必须要再远程访问PostgreSQL,从而保证了其安全性能。

全量,增量和差异备份

支持全量,增量和差异备份。pgBackRest不受异步时间影响,因此差异和增量备份完全安全。

备份保留策略和和归档过期

支持保留策略设置可以在任意时间创建全备和差异备份的覆盖。

备份完整性

可以计算备份中每个文件的校验和,并在还原期间重新检查。备份完成文件复制后,将等待直到每个WAL段所需的备份保持一致然后存储到备份仓库中。

块校验和断点备份流压缩和校验和增量还原并行异步WAL Push和Get表空间重新映射和Link支持S3存储支持和Azure兼容对象存储支持加密

使用

安装解压

[postgres@pgserver12 tools]$ tar -zxf pgbackrest-release-2.31.tar.gz
[postgres@pgserver12 tools]$ ls

创建必要目录

ostgres@sungsasong ~]$ sudo mkdir -p -m 770 /var/log/pgbackrest
[postgres@sungsasong ~]$ sudo chown postgres.postgres /var/log/pgbackrest/
[postgres@sungsasong ~]$ sudo mkdir -p /etc/pgbackrest
[postgres@sungsasong ~]$ sudo mkdir -p /etc/pgbackrest/conf.d
[postgres@sungsasong ~]$ sudo touch /etc/pgbackrest/pgbackrest.conf
[postgres@sungsasong ~]$ sudo chmod 640 /etc/pgbackrest/pgbackrest.conf
[postgres@sungsasong ~]$ sudo chown postgres.postgres -R /etc/pgbackrest/
[postgres@sungsasong ~]$ sudo mkdir /usr/bin/pgbackrest
[postgres@sungsasong ~]$ sudo chown postgres.postgres /usr/bin/pgbackrest/
[postgres@sungsasong ~]$ sudo chmod 755 /usr/bin/pgbackrest/

编译安装

[postgres@sungsasong src]$ ./configure --prefix=/usr/bin/pgbackrest/
[postgres@sungsasong src]$ make -j24
[postgres@sungsasong src]$ make install -j24
install -d /usr/bin/pgbackrest/bin
install -m 755 pgbackrest /usr/bin/pgbackrest/bin

命令测试

[postgres@sungsasong src]$ /usr/bin/pgbackrest/bin/pgbackrest
pgBackRest 2.31 - General help
 
Usage:
 pgbackrest [options] [command]
 
Commands:
 archive-get Get a WAL segment from the archive.
 archive-push Push a WAL segment to the archive.
 backup Backup a database cluster.
 check Check the configuration.
 expire Expire backups that exceed retention.
 help Get help.
 info Retrieve information about backups.
 restore Restore a database cluster.
 stanza-create Create the required stanza data.
 stanza-delete Delete a stanza.
 stanza-upgrade Upgrade a stanza.
 start Allow pgBackRest processes to run.
 stop Stop pgBackRest processes from running.
 version Get version.
 
Use 'pgbackrest help [command]' for more information.

配置数据库监听和访问及日志(可选)

[postgres@sungsasong pgbackrest-release-2.31]$ egrep "10.10" $PGDATA/pg_hba.conf
host all all 10.10.20.0/24 trust
[postgres@sungsasong pgbackrest-release-2.31]$ egrep -v "^#" $PGDATA/postgresql.auto.conf
logging_collector = 'on'
listen_addresses = '*'

配置PostgreSQL数据库数据存储目录

[postgres@sungsasong src]$ cat >>/etc/pgbackrest/pgbackrest.conf <<EOF
> [demo]
> pgl-path=/data/pg10/pgdata
> EOF

配置环境变量

[postgres@sungsasong ~]$ echo "export PATH=/usr/bin/pgbackrest/bin:\$PATH" >> .bashrc

创建备份和归档仓库

[postgres@sungsasong ~]$ sudo mkdir -p /pgbackrest/repos
[postgres@sungsasong ~]$ sudo chmod 750 /pgbackrest/ -R
[postgres@sungsasong ~]$ sudo chown postgres.postgres /pgbackrest/ -R

将仓库路径加载在pgBackRest配置文件中

[postgres@sungsasong ~]$ cat /etc/pgbackrest/pgbackrest.conf
[demo]
pgl-path=/data/pg10/pgdata
 
[global]
repol-path=/pgbackrest/repos

配置数据库归档

[postgres@sungsasong ~]$ egrep -v "^#" $PGDATA/postgresql.auto.conf
logging_collector = 'on'
archive_mode = 'on'
archive_command = 'pgbackrest --stanza=demo archive-push %p'
listen_addresses = '*'
log_filename = 'postgresql.log'
log_line_prefix = ''
max_wal_senders = '3'聍4(~r,4(4)m4)4(4(4(4(Ф4(4(4(4(4(4(х4(4(4(|4(4(4(х-4(4(4(:4(.V66v<4(4)mAQ4)mхt4("F+.&04(34(4)mхt4(7ZB*V64(4)mхt}AQ4)4)4)mхt4)4)Q4(b>+7jrZ&#r>R2AME0&#rbZΣR2rZ"ME0&#rjB3>:W4(ro>rokkR2r'Rg"[rfG3jrZ3roBwVg
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1060120
帖子:212021
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP