he simplest way to back up and restore a PostgreSQL database us by using pg_dump for backup and pg_restore for restoration. For more information, see https://www.postgresql.org/docs/8.1/backup.html.
Backup your PostgreSQL Database
Backup your PostgreSQL database by running the following command:
pg_dump -U <your_username> -d <your_database> -F c -f backup.dumpWhere:
-U <your_username> specifies the PostgreSQL user.
-d <your_database> specifies the name of the database to back up.
-F -c specifies the format (c for custom, t for tar, p for plain text).
-f backup.dump specifies the output file.
Restoring your PostgreSQL Database on a Same VM
Restore the backup and exit from the PostgreSQL console:
Copypg_restore -U <your_username> -d <your_database> -F c backup.dumpRestart PostgreSQL:
Copysystemctl restart postgresqlLogin to the PostgreSQL server:
Copysudo -u postgresql psqlEnsure the Entrust PSQL extension is created:
CopyCREATE EXTENSION IF NOT EXISTS entrust_psql_extension;
Restoring your PostgreSQL Database on a Different VM
After the backup is complete, share the folder to the new backup location.
Copyscp backup.dump user@destination_host:/tmp/backup.dumpWhere user@destination_host is the new location for the backup.
Install the Policy Agent in the new directory and configure it. For more information, see Manually Installing and Registering the Policy Agent for PostgreSQL.
Enable TDE. For more information, see Enable TDE on PostgreSQL Database Server.
Create the database connector in the same Key Set that was used to encrypt the backed up data, then generate the access token and store it in a file. For more information, see:
Restore your database:
Copypg_restore -U <your_username> -d <your_database> -F c /tmp/backup.dumpRestart PostgreSQL:
Copysystemctl restart postgresqlLogin to the PostgreSQL server:
Copysudo -u postgresql psqlEnsure the Entrust PSQL extension is created:
CopyCREATE EXTENSION IF NOT EXISTS entrust_psql_extension;