Service to backup and/or restore a PostgreSQL database to/from a local filesystem directory
- Create a directory on the filesystem to hold your backups
- Supply all appropriate environment variables
- Run a backup and check your directory for that backup
MODE
Valid values: backup
, restore
DB_HOST
hostname of the database server
DB_NAME
name of the database
DB_OPTIONS
optional arguments to supply to the backup or restore commands
DB_ROOTPASSWORD
password for the DB_ROOTUSER
DB_ROOTUSER
database administrative user, typically "postgres" for PostgreSQL databases
DB_USERPASSWORD
password for the DB_USER
DB_USER
user that accesses the database (PostgreSQL "role")
BACKUP_DIR
e.g., /path/to/database-backups NOTE: no trailing slash
Versioning of the backup file is left as an exercise for the user. This script will overwrite an existing backup file.
This image is built automatically on Docker Hub as silintl/postgresql-backup-restore-fs
You'll need Docker, Docker Compose, and Make.
- cd .../postgres-backup-restore-fs
- mkdir ./mybackups
- cp -p test/world.sql.gz ./mybackups
make db
# creates the Postgres DB servermake restore
# restores the DB dump filedocker ps -a
# get the Container ID of the exited restore containerdocker logs <containerID>
# review the restoration log messagesmake backup
# create a new DB dump filedocker ps -a
# get the Container ID of the exited backup containerdocker logs <containerID>
# review the backup log messagesmake restore
# restore the DB dump file from the new backupdocker ps -a
# get the Container ID of the exited restore containerdocker logs <containerID>
# review the restoration log messagesmake clean
# remove containers and networkdocker volume ls
# find the volume ID of the Postgres data containerdocker volume rm <volumeID>
# remove the data volumedocker images
# list existing imagesdocker image rm <imageID ...>
# remove images no longer needed