Database Backups

Modified on Wed, 28 Sep 2022 at 02:34 PM

Create a Backup


The script below will run a on-off container that will run pg_dumpand write the results to the file backup.db. This process could take a while, depending on the size of the database.

Shell

1docker run -it --rm --link codecov-postgres:postgres postgres pg_dump -Fc -h postgres -U postgres > backup.db 2 

Recover From a Backup

The script below is used to run a on-off container with the backup file mounted. pg_restore will run with 2 processes.

Concerning -j2, the optimal value for this option depends on the hardware setup of the server, of the client, and of the network. Factors include the number of CPU cores, and the disk setup. A good place to start is the number of CPU cores on the server, but values larger than that can also lead to faster restore times in many cases. Of course, values that are too high will lead to decreased performance because of thrashing.


Shell

1docker run -it --rm -v "$PWD/backup.db:/backup.db" --link codecov-postgres:postgres postgres pg_restore -h postgres -U postgres -j2 /backup.db 2

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article