How to Change the Backup Location in pgBackRest for PostgreSQL 15
This guide walks you through updating pgBackRest to use a new backup directory — in this case, /u01/pgbackrest.
๐ Step 1: Create the New Backup Directory
mkdir -p /u01/pgbackrest
chown postgres:postgres /u01/pgbackrest
chmod 750 /u01/pgbackrest
⚙️ Step 2: Update pgBackRest Configuration
Edit the config file:
vi /etc/pgbackrest.conf
Update the [global] section to use the new path:
ini
[global]
repo1-path=/u01/pgbackrest
repo1-retention-full=2
repo1-retention-diff=4
log-level-console=info
log-level-file=debug
log-path=/var/log/pgbackrest
[pg15]
pg1-path=/u01/postgres/pgdata_15/data
pg1-port=5432
pg1-user=postgres
๐ Step 3: Set Permissions on Config File
chmod 640 /etc/pgbackrest.conf
chown postgres:postgres /etc/pgbackrest.conf
๐งฑ Step 4: Recreate the Stanza
Since the backup location changed, you need to recreate the stanza:
sudo -u postgres env PGHOST=/tmp pgbackrest --stanza=pg15 stanza-create
๐ Step 5: Verify the New Location
Run a check to confirm everything is working:
sudo -u postgres env PGHOST=/tmp pgbackrest --stanza=pg15 check
✅ You should see a message like:
Code
INFO: WAL segment ... successfully archived to '/u01/pgbackrest/archive/pg15/...'
๐พ Step 6: Run a Test Backup
sudo -u postgres env PGHOST=/tmp pgbackrest --stanza=pg15 --type=full backup
๐ Step 7: Confirm Backup Storage
Check that backups are stored in the new location:
ls -l /u01/pgbackrest/pg15/backup
๐งน Optional: Clean Up Old Backup Location
If you no longer need the old backups:
bash
rm -rf /var/lib/pgbackrest
⚠️ Only do this if you're sure the new backups are working and complete.
No comments:
Post a Comment