Skip to content

Postgresql Database ‐ Backup and Restore

dbeasley1 edited this page Sep 23, 2025 · 8 revisions

Configure Backup

The PostgreSQL database is backup up nightly from a cronjob.

The script that makes a backup is located:

/xnat-data/xnat/scripts/cronjobs/pg_backup.sh

Edit the configuration file to change the settings with immediate effect:

/xnat-data/xnat/scripts/cronjobs/pg_backup.config

Run the_ pg_backup.sh_ to ensure the changes are implemented correctly. The default configuration create a directory-format backup to:

/xnat-data/xnat/scripts/pg_backup

There are three options for backup, and this can be changed at any time by editing the config file.

pg_dump's custom dump format: Using the zlib compression library installed, the custom dump format will compress data as it writes it to the output file. This will produce dump file sizes similar to using gzip, but it has the added advantage that tables can be restored selectively. This produces a file: xnat.custom

Directory Format Backup: this enables faster parallel backup and restore, however the generated directories are very large. This produces a directory xnat.

Plain backup: the most flexible method, writing sql commands, it may be required if upgrading Postgresql. Slower than other methods for restoring. This produces a file xnat.sql.gz

To Restore from Backup:

If you need to restore your database from a backup (to upgrade PostgreSQL or database error), you need to run the script:

./Linux/restore_from_pg_backup.sh

This will make a backup if the postgresql database directory:

/xnat-data/postgresql/postgres-data

to

/xnat-data/postgresql_backup/postgres-data

and prompts you to copy the backup directory (xnat) or custom backup (xnat.custom) or plain backup (xnat.sql.gz) from /xnat-data/xnat/scripts/pg_backup to /xnat-data/pg_backup

When copied, XNAT will restart, detect the directory and restore the database.

Clone this wiki locally