Linux command
pgbackrest 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Initialize a new stanza
pgbackrest --stanza=[name] stanza-create
Verify
pgbackrest --stanza=[name] check
Create a full backup
pgbackrest --stanza=[name] --type=full backup
Create an incremental backup
pgbackrest --stanza=[name] --type=incr backup
Restore the latest backup
pgbackrest --stanza=[name] restore
Restore to a specific point in time
pgbackrest --stanza=[name] --type=time --target="[2026-04-27 12:00:00]" restore
Show information
pgbackrest --stanza=[name] info
Expire
pgbackrest --stanza=[name] expire
说明
pgBackRest is a backup and restore solution for PostgreSQL designed for reliability at scale. It supports full, differential, and incremental backups, parallel processing, hardware-accelerated compression (gz, lz4, zstd), local and remote repositories, and storage backends including filesystem, S3, Azure Blob, and Google Cloud Storage. Backups can be verified end-to-end and restored to a point in time using PostgreSQL's recovery facilities. Operation is organized around a stanza, which represents a single PostgreSQL cluster and its backup repository. After stanza-create, the archive_command in postgresql.conf is set to pgbackrest --stanza=name archive-push %p so that every WAL segment is shipped to the repository. backup then captures the data directory and pairs it with the archived WAL to enable point-in-time recovery via restore. pgBackRest is implemented in C with a small Perl helper layer historically; modern versions are pure C. It is widely deployed in PostgreSQL operator stacks (Crunchy Data, CloudNativePG, Zalando) and in production database environments where pg_basebackup is insufficient.
参数
- backup
- Create a full, differential, or incremental backup of a PostgreSQL cluster.
- restore
- Restore a backup, optionally to a specific time, name, xid, LSN, or named recovery target.
- archive-push
- Push a WAL segment to the repository (called from PostgreSQL archive_command).
- archive-get
- Retrieve a WAL segment from the repository during recovery (called from restore_command).
- stanza-create
- Initialize a new stanza, creating the repository layout for a cluster.
- stanza-upgrade
- Update stanza metadata after a major PostgreSQL upgrade.
- stanza-delete
- Remove a stanza and all its backups and WAL.
- check
- Verify configuration, archive command, and repository accessibility.
- info
- Display backup and archive information for one or all stanzas.
- verify
- Verify integrity of backups and WAL in the repository.
- expire
- Apply retention policies, removing old backups and archived WAL.
- repo-ls, repo-get
- List or fetch files directly from the repository.
- server, server-ping, start, stop
- Manage the pgBackRest server (used with TLS-based remote repositories).
- annotate
- Add, modify, or remove free-form annotations on a backup.
- --stanza _name_
- Stanza (PostgreSQL cluster) to operate on.
- --type _full|diff|incr|time|name|xid|lsn|immediate|default|standby_
- Backup type (full/diff/incr) or restore recovery target type.
- --target _value_
- Target for --type=time/name/xid/lsn restores.
- --config _file_
- Path to alternative pgbackrest.conf.
- --config-path _dir_
- Base directory for configuration files.
- --repo _N_
- Select a specific repository when multiple are configured.
- --process-max _N_
- Maximum parallel processes for compression and transfer.
- --compress-type _none|gz|lz4|zst|bz2_
- Compression algorithm for backups and WAL.
- --log-level-console _off|error|warn|info|detail|debug|trace_
- Verbosity of console logging.
- --delta
- Restore only files that differ from the backup (faster repeated restores).
FAQ
What is the pgbackrest command used for?
pgBackRest is a backup and restore solution for PostgreSQL designed for reliability at scale. It supports full, differential, and incremental backups, parallel processing, hardware-accelerated compression (gz, lz4, zstd), local and remote repositories, and storage backends including filesystem, S3, Azure Blob, and Google Cloud Storage. Backups can be verified end-to-end and restored to a point in time using PostgreSQL's recovery facilities. Operation is organized around a stanza, which represents a single PostgreSQL cluster and its backup repository. After stanza-create, the archive_command in postgresql.conf is set to pgbackrest --stanza=name archive-push %p so that every WAL segment is shipped to the repository. backup then captures the data directory and pairs it with the archived WAL to enable point-in-time recovery via restore. pgBackRest is implemented in C with a small Perl helper layer historically; modern versions are pure C. It is widely deployed in PostgreSQL operator stacks (Crunchy Data, CloudNativePG, Zalando) and in production database environments where pg_basebackup is insufficient.
How do I run a basic pgbackrest example?
Run `pgbackrest --stanza=[name] stanza-create` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does backup do in pgbackrest?
Create a full, differential, or incremental backup of a PostgreSQL cluster.