Admin Commands
Run backup commands as the database superuser (pg_dbsu, postgres by default) on a database node. You can use any of these entry points:
pig pb: the PIG CLI wrapper, with automatic stanza detection, DBSU switching, and safety checks; this is the recommended interfacepb: a login-shell function that supplies--stanzaand forwards arguments to pgBackRestpgbackrest: the native command; see the pgBackRest command reference
Command Overview
| PIG command | Alias | Native pgBackRest command | Purpose |
|---|---|---|---|
pig pb info |
i |
info |
Show backup and archive status |
pig pb list |
ls |
— | List repositories, stanzas, or backup sets |
pig pb backup [full/diff/incr] |
b |
backup |
Create a backup after checking the primary role |
pig pb restore |
r |
restore |
Low-level restore primitive; see Restore Operations |
pig pb expire |
e |
expire |
Expire backups according to retention (--plan previews) |
pig pb create |
c |
stanza-create |
Create a stanza |
pig pb upgrade |
u |
stanza-upgrade |
Upgrade a stanza after a major-version change or clone |
pig pb delete |
d |
stanza-delete |
Delete a stanza and all of its backups |
pig pb check |
ck |
check |
Verify configuration, repository access, and archiving |
pig pb start |
up |
start |
Re-enable pgBackRest operations |
pig pb stop |
dw |
stop |
Stop new pgBackRest operations |
pig pb log [list/show/tail] |
l |
— | Inspect pgBackRest logs |
Enable Backup
If pgbackrest_enabled is true when the cluster is created, backup is enabled automatically. If it was disabled at creation time, or repository settings have changed, run the pg_backup subtask:
After cluster initialization, Pigsty attempts an initial full backup. It writes /etc/pgbackrest/initial.done only after the backup command succeeds; the playbook ignores a failed attempt and leaves no marker. This file only prevents the initialization task from repeating, so always verify actual repository state with pig pb info or pgbackrest info. Define scheduled backups with pg_crontab; see Backup Policy.
Remove Backup
pig pb delete is the preferred interface when only a backup stanza must be removed. It asks for interactive confirmation; with a multi-stanza configuration, the target must also be explicit. Verify the exact target first:
When a primary instance (pg_role = primary) is removed, pgsql-rm.yml also tries to delete the cluster’s backup stanza by default. Every command below changes or deletes state; never execute one merely by copying the example:
Before execution, verify a recent usable backup, record the recovery requirement, and have the operator re-enter the exact cluster/stanza name. Set pg_rm_backup to false to preserve backups while removing the cluster.
pgsql-rm.yml -t pg_backup forcibly runs pgbackrest stanza-delete on the primary, removes the local repository directory in local mode, then removes the pgBackRest configuration and initial-backup marker. The task ignores some deletion errors, so a successful playbook result does not prove that repository objects were physically removed. Prefer pig pb delete when only the stanza needs deletion because it supplies a plan and confirmation guard.
With object versioning and object-lock retention, deletion may create a delete marker while locked historical versions continue consuming storage until their retention period expires.
Deleting backups can permanently destroy recovery options. Confirm the cluster/stanza, verify a recent backup and an alternative recovery copy, and retain the pig pb info output and deletion plan as an audit record.
Manual Backup
You can trigger a backup outside the crontab schedule. Both pg-backup and pig pb backup check that the current instance is primary and exit on a replica:
Backup consumes disk I/O and network bandwidth. Pigsty limits parallelism to a small number of processes, but production runs should still be scheduled for low-traffic periods.
Inspect Backups
pb info shows backups and WAL archive status for the current stanza:
Backup labels ending in F, D, and I identify full, differential, and incremental backups. The portion before an underscore identifies the full backup anchoring that chain. The WAL archive range and the oldest usable full backup together bound the recovery window.
The pgbackrest_exporter service on port 9854 continuously exports metrics such as the latest backup time, type, size, and error status.
Expire Old Backups
The configured retention policy is applied automatically after backups (expire-auto). Preview or run expiration manually with:
Stanza Management
A stanza records a cluster’s backup identity, including its system identifier and major version. Manual management is occasionally required:
The usual manual upgrade case is post-clone cleanup: after restoring another cluster’s backup into a new cluster, update the stanza identity before new backups can be written.
Check and Control
check performs an archive-path check rather than being purely local or read-only; it verifies that WAL can reach the repository.
Logs
For pgsql-pitr.yml, PostgreSQL recovery output is written to /pg/tmp/recovery.log.
Alternative Backup Tools
pg-basebackup
The legacy /pg/bin/pg-basebackup script creates a single-file physical backup using native pg_basebackup, an lz4-compressed tar stream, and /pg/backup by default. Use it only for a simple local copy when a pgBackRest repository is unavailable:
pg-basebackup -e uses the obsolete OpenSSL RC4 cipher and must not be treated as confidentiality protection. For encrypted backups, use a pgBackRest repository configured with AES-256 (cipher_type: aes-256-cbc).
Logical Backup
Logical backups made with pg_dump cannot provide PITR, but they are appropriate for cross-major-version migration, partial exports, and long-term logical snapshots. Production recovery plans commonly use logical and physical backups together. See the PostgreSQL documentation.