pg_dump (pg_dumpall) and pg_restore tools.
To protect against data loss, back up Gcore Managed PostgreSQL databases regularly.
1. Install external utilities
Install the backup and restore utilities on the virtual or local server. Installation instructions are provided below for Ubuntu, CentOS, and Windows.Ubuntu 22.04
Ubuntu 22.04
- Connect to the virtual server.
-
Download the latest available updates and upgrade
apt:
- To install
pg_dumpandpg_restoretools, install the Postgres package, which includes them:
CentOS 7
CentOS 7
- Connect to the virtual server.
- Install the PostgreSQL package:
Windows
Windows
- Download the installer of the relevant PostgreSQL version.
- Run the installation process.
2. Get your credentials
The backup and restore tools require credentials (username, password, port, and dbname) to connect to the Gcore Managed PostgreSQL server. Credentials are available in the Customer Portal — see Get your credentials for instructions.
3. Back up databases
Back up a specific database
Use one of the following commands depending on the required backup format:- Default SQL format:
$ pg_dump -U username -W -h hostname -d database_name > database_name.sql - TAR format:
$ pg_dump -F t -U username -W -h hostname -d database_name > backup_file.tar - Custom format:
$ pg_dump -F c -U username -W -h hostname -d database_name > backup_file.dump - Directory format:
$ pg_dump -F d -U username -W -h hostname -d database_name -f backup_dir
username, hostname, and database_name with the actual values from the Customer Portal. For backup_file or backup_dir, specify the name for the backup file or directory.
Additional flag details:
-Wprompts the password before connecting to the PostgreSQL server-Fspecifies the output format of the backup and can be followed by the following flags:cfor custom formatdfor directory formattfor tar
Back up all databases
Run the command:all_pg.sql: the output backup file nameusername: the username from the Customer Portalhostname: the hostname from the Customer Portal
4. Restore databases
Run the command:username: the username from the Customer Portalhostname: the hostname from the Customer Portaldatabase_name: the database name from the Customer Portalbackup_file.tar: the backup file or directory to restore from