2016-06-15 00:32:14 +03:00
============================
Database Backups with Docker
============================
2017-07-14 17:09:41 +03:00
The database has to be running to create/restore a backup. These examples show local examples. If you want to use it on a remote server, remove `` -f local.yml `` from each example.
2016-06-15 00:32:14 +03:00
Running Backups
================
2017-07-14 17:09:41 +03:00
Run the app with `docker-compose -f local.yml up` .
2016-06-15 00:32:14 +03:00
To create a backup, run::
2017-07-14 17:09:41 +03:00
docker-compose -f local.yml run postgres backup
2016-06-15 00:32:14 +03:00
To list backups, run::
2017-07-14 17:09:41 +03:00
docker-compose -f local.yml run postgres list-backups
2016-06-15 00:32:14 +03:00
To restore a backup, run::
2017-07-14 17:09:41 +03:00
docker-compose -f local.yml run postgres restore filename.sql
2016-06-15 00:32:14 +03:00
Where <containerId> is the ID of the Postgres container. To get it, run::
docker ps
To copy the files from the running Postgres container to the host system::
docker cp <containerId>:/backups /host/path/target
Restoring From Backups
======================
To restore the production database to a local PostgreSQL database::
createdb NAME_OF_DATABASE
psql NAME_OF_DATABASE < NAME_OF_BACKUP_FILE