Skip to content

Restore a PostgreSQL backup

Download and restore a PostgreSQL dump file to any PostgreSQL database.

SimpleBackups stores PostgreSQL backups as compressed dump files. The restore command depends on the output format you selected when creating the backup: custom format (.pgsql) uses pg_restore, and plain text format (.sql) uses psql.

Download the backup file

  1. Go to your backup page and open the Logs tab. Click the (i) icon next to the backup run you want to restore.

The backup log entry with the info icon highlighted

  1. In the modal that appears, click Click to generate a signed download link and copy the resulting URL.

  2. On your server, download and decompress the backup using the signed URL:

bash
wget -O - "PASTE_SIGNED_DOWNLOAD_LINK_HERE" | gunzip -c > postgresql-backup.pgsql

Restore the database

Custom format (.pgsql)

If you used the quick export option in SimpleBackups, the backup is in custom format. Restore it with pg_restore:

bash
sudo -u postgres createdb NEW_DATABASE_NAME
sudo -u postgres psql -U postgres -d NEW_DATABASE_NAME -c "drop schema public cascade;"
sudo -u postgres pg_restore --single-transaction --no-owner -U postgres -d NEW_DATABASE_NAME postgresql-backup.pgsql

Replace postgres with your database user and NEW_DATABASE_NAME with your target database name.

Plain text format (.sql)

If you did not use the quick export option, the backup is in plain text format. Restore it with psql:

bash
sudo -u postgres createdb NEW_DATABASE_NAME
sudo -u postgres PGPASSWORD=DATABASE_PASSWORD psql --single-transaction \
  -U postgres -h 127.0.0.1 -p 5432 -d NEW_DATABASE_NAME < postgresql-backup.pgsql

Replace DATABASE_PASSWORD, postgres, 127.0.0.1, 5432, and NEW_DATABASE_NAME with your actual values.