Summary


This article will describe the steps to create a backup and restore the Aqua Postgres database container database using the pg_dump utility. 


Procedure


1. Attach to the aqua-db container. 

docker exec -t aqua-db bash


2. Navigate to /usr/local/bin. You will see the pg_dump and psql utilities here. 

cd /usr/local/bin
ls


3. Run the pg_dump command to create the backup. The backup will be saved to the same directory. 

pg_dump -U postgres scalock > (database backup name)
ls

pg_dump -U postgres scalock > scalockdump
ls


4. Switch to user postgres, then switch to psql.

su postgres
psql

5. Create a new database. Run \l+ and verify the new database has been created.  

CREATE DATABASE <newDBname>;
\l+

CREATE DATABASE newscalock;
\l+


6. Return to bash prompt. 

\q
exit

7.  Navigate to /usr/local/bin if not still in that directory. Restore the backup file to the newly created database. 

cd /usr/local/bin
psql -U postgres newDBname < {database_backup_filename}

cd /usr/local/bin
psql -U postgres newscalock < {scalock_database_dump_file}


8. Switch to the user postgres, then switch to psql. Check that the new database was restored correctly by comparing the before and after size. 

su postgres
psql 
\l+