pgbackrest

优势

1、支持对象存储
2、支持从standby实例备份,可以减小主库的IO压力

使用

pgBackRest是一个可靠的备份和恢复工具,可以为PostgreSQL数据库提供快速和可靠的备份和还原。下面是使用pgBackRest进行备份和还原的基本步骤:

1、备份数据库

使用pgBackRest备份PostgreSQL数据库的命令如下:

pgbackrest --stanza=STANZA backup

其中,STANZA是指备份集的名称,可以在pgBackRest的配置文件中进行设置。

2、恢复数据库

在进行恢复之前,需要将备份文件拷贝到目标服务器上,并解压缩。恢复PostgreSQL数据库的命令如下:

pgbackrest --stanza=STANZA restore

此命令将恢复最新的备份。如果需要恢复早期的备份,则需要使用–set=restore-path=PATH参数指定备份文件的路径。

3、设置恢复参数

在进行恢复之前,还需要设置一些恢复参数,例如恢复目录、监听地址和端口等。可以在pgBackRest的配置文件中进行设置,或者在命令行中使用–set参数进行设置。

例如,设置恢复目录:

pgbackrest --stanza=STANZA --set=restore-command="cp %f /var/lib/pgsql/10/data/pg_restore/%p" restore

此命令将备份文件复制到指定的恢复目录中。

4、恢复数据库

设置好恢复参数后,使用–delta参数可以进行增量恢复,即只恢复指定时间点之后的更改。例如,恢复到2022年1月1日的命令如下:

pgbackrest --stanza=STANZA --delta=2022-01-01 restore

恢复过程可能需要一段时间,具体时间取决于数据库的大小和恢复参数的设置。恢复完成后,可以使用pgAdmin等工具连接数据库进行验证。

5、查看备份情况

pgbackrest info --repo-path=path where backups and archive are stored

在这里插入图片描述

pgbackrest

pgbackrest 
pgBackRest 2.43 - General help

Usage:
    pgbackrest [options] [command]

Commands:
    annotate        Add or modify backup annotation.
    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.
    repo-get        Get a file from a repository.
    repo-ls         List files in a repository.
    restore         Restore a database cluster.
    server          pgBackRest server.
    server-ping     Ping pgBackRest server.
    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.
    verify          Verify contents of the repository.
    version         Get version.

Use 'pgbackrest help [command]' for more information.


pgbackrest help info 

猜你喜欢

转载自blog.csdn.net/hezuijiudexiaobai/article/details/129924752