Skip to content

Backup and Restore

NOTE

This doc assumes that the old Postgres server, from where backup is being taken, is accessible via SSH.

Create a Backup Dump

  • SSH into the old Postgres Server.
  • Use the following command to export the database into a backup file:
sh
# Example: Backing up the 'piratedev' database
pg_dump -U postgres --dbname piratedev -f backup.dump

Transfer the Backup File

  • Copy the backup file from the old Postgres server:
sh
# Replace <Old Postgres Private IP address> with the private IP of the old server
# Replace <USER> with the server user (Ex: `ec2-user` for Amazon Linux, `admin` for Debian etc.) 
scp <USER>@<Old Postgres Private IP address>:/home/<USER>/backup.dump ./
  • Transfer the backup file to the new Postgres server:
sh
# Replace <New Postgres Private IP address> with the private IP of the new server
# Replace <USER> with the server user (Ex: `ec2-user` for Amazon Linux, `admin` for Debian etc.)
scp backup.dump <USER>@<New Postgres Private IP address>:/home/<USER>/

Prepare Postgres Instance for Backup Restoration

The backup.dump file you created earlier assumes the existence of a database named piratdev, owned by a user called piratedev.

Refer this doc if not already done

Restore Backup

To restore the database from the backup, use the following command on the new server:

shell
psql -U postgres -d piratdev -f backup.dump