在今天的文章中,我将告诉你关于 PostgreSQL Community 13 上的 Pgbackrest 安装。
如果您之前没有安装过 PostgreSQL Community,您可以通过以下链接进行安装。
https://dbtut.com/index.php/2022/03/13/postgresql-community-13-installation-on-oracle-linux-7/
简单来说,pgBackrest 是 PostgreSQL 的备份工具。您可以使用此工具获得完整备份、增量备份、差异备份。您可以从这些备份中恢复或简单地恢复丢失的文件。
简单解释一下pgBackrest是什么之后,我们就可以开始安装了。首先,我们安装 pgBacgrest。
[root@testdb ~]#yum -y install pgbackrest
存储库是 pgBackRest 存储备份和归档 WAL 段的地方。
[root@testdb ~]#mkdir -p /pg_backup/pgbackrest
[root@testdb ~]#chmod 750 /pg_backup/pgbackrest
[root@testdb ~]#chown postgres:postgres /pg_backup/pgbackrest
存档配置:
要将数据库置于归档模式,我们将以下参数写入 postgresql.conf 文件。
archive_mode = on
archive_command = ‘pgbackrest --stanza=demo archive-push %p’
我们重新启动 postgresql 服务,以便我们所做的更改可以处于活动状态。
[root@testdb ~]#systemctl restart postgresql-13
备份
如果我们要在同一台服务器上备份,我们将 pgBackrest 配置如下。
$ vi /etc/pgbackrest.conf
[global]
repo-path=/pg_backup/pgbackrest/
backup-user=postgres
retention-full=2
retention-diff=2
process-max=3
log-path=/pg_backup/log/pgbackrest
[demo]
pg1-path=/var/lib/pgsql/13/data/
如果将备份到不同的服务器,我们将配置主服务器和我们将备份的服务器。
要在主服务器上完成的 pgBacrest 配置:
$vi /etc/pgbackrest.conf
[global]
repo1-host=<backup-sunucu-ip>
repo1-host-user=postgres
[demo]
pg1-path=/var/lib/pgsql/13/data/
要在要备份的服务器上进行的 pgBackrest 配置:
$ vi /etc/pgbackrest.conf
[global]
repo1-path=/pg_backup/pgbackrest
repo1-retention-full=2
repo1-retention-diff=2
process-max=3
[demo]
pg1-host=<master-sunucu-ip>
pg1-path=/var/lib/pgsql/13/data/
pg1-user=postgres
要使用 pgBackrest 进行备份,我们必须首先创建备份目录。创建后,我们检查我们所做的操作的正确性。
$ pgbackrest --stanza=demo --log-level-console=info stanza-create
$ pgbackrest --stanza=demo --log-level-console=info check
检查后,我们可以使用以下命令进行完整备份。
$ pgbackrest --stanza=demo --log-level-console=info backup
差异备份:
$ pgbackrest --stanza=demo --type=diff --log-level-console=info backup
增量备份:
$ pgbackrest --stanza=demo --type=incr --log-level-console=info backup
我们可以使用以下命令来获取有关先前进行的备份的信息。
$ pgbackrest info
备份还原
对于完整备份恢复,我们必须首先停止 postgresql 服务。执行还原过程后,我们可以再次启动服务。
[root@testdb ~]systemctl stop postgresql-13
$ pgbackrest --stanza=demo --delta restore
[root@testdb ~]systemctl start postgresql-13
增量备份还原:
[root@testdb ~]systemctl stop postgresql-13
$ pgbackrest --stanza=demo --delta restore \
--recovery-option=recovery_target=immediate
[root@testdb ~]systemctl start postgresql-13
我希望这对您来说是一份有用的文件。
原文标题:Pgbackrest Installation
原文作者:Melek Durdu
原文地址:https://dbtut.com/index.php/2022/03/29/pgbackrest-installation/




