Admin Commands
On a database node, run backup commands as the database superuser (pg_dbsu, which defaults to postgres.
Use one of these interfaces:
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 at cluster creation, Pigsty enables backup automatically.
If backup was disabled at creation, 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.
If the attempt fails, the playbook ignores the failure and leaves no marker.
This file only prevents the initialization task from repeating.
Always verify repository state with pig pb info or pgbackrest info.
Define scheduled backups with pg_crontab; see Backup Policy.
Remove Backup
To remove only a backup stanza, use pig pb delete as the preferred interface.
It asks for interactive confirmation.
With a multi-stanza configuration, you must also specify the target explicitly.
Verify the exact target first:
By default, pgsql-rm.yml also tries to delete the cluster’s backup stanza when it removes a primary instance (pg_role = primary).
Each command below changes or deletes state.
Do not run a command only because it appears in an example:
Before execution, verify a recent usable backup and record the recovery requirement.
Have the operator re-enter the exact cluster/stanza name.
To preserve backups when you remove the cluster, set pg_rm_backup to false.
pgsql-rm.yml -t pg_backup forcibly runs pgbackrest stanza-delete on the primary.
In local mode, it removes the local repository directory.
It then removes the pgBackRest configuration and initial-backup marker.
The task ignores some deletion errors.
Thus, a successful playbook result does not prove that it physically removed the repository objects.
To delete only a stanza, prefer pig pb delete, which provides a plan and requires confirmation.
With object versioning and object-lock retention, deletion may create a delete marker. Locked historical versions continue to consume 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.
Keep the pig pb info output and deletion plan as an audit record.
Manual Backup
You can start a backup outside the crontab schedule.
Both pg-backup and pig pb backup check that the current instance is primary.
They exit on a replica:
Backup consumes disk I/O and network bandwidth. Pigsty limits parallelism to a small number of processes. Still, you should schedule production backups for periods with low traffic.
Inspect Backups
pb info shows backups and WAL archive status for the current stanza:
Backup labels that end in F, D, and I identify full, differential, and incremental backups.
The portion before an underscore identifies the full backup at the start of that chain.
The WAL archive range and oldest usable full backup define 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
pgBackRest applies the retention policy automatically after backups (expire-auto).
To preview or run expiration manually, use:
Stanza Management
A stanza records a cluster’s backup identity, including its system identifier and major version. You may need to manage it manually:
The usual manual upgrade case is post-clone cleanup.
After you restore another cluster’s backup into a new cluster, update the stanza identity before you write new backups.
Check and Control
check verifies that WAL can reach the repository through the archive path.
It is not a purely local or read-only operation.
Logs
For pgsql-pitr.yml, PostgreSQL writes recovery output to /pg/tmp/recovery.log.
Alternative Backup Tools
pg-basebackup
The legacy /pg/bin/pg-basebackup script creates a single-file physical backup with native pg_basebackup.
It uses an lz4-compressed tar stream and writes to /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. You must not treat it as confidentiality protection.
For encrypted backups, use a pgBackRest repository with AES-256 (cipher_type: aes-256-cbc).
Logical Backup
Logical backups made with pg_dump cannot provide PITR.
They are suitable 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.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)