Skip to content

pgBackup

Docker Pulls GitHub Stars Compose Templates

Description

pgBackup: Backup PostgresSQL to the local filesystem with periodic rotating backups

Install/Setup

Set your postgres host, username and password in the .env file along with a comma seperated list of databases you want to backup.

By default, backups run daily. Change PGBACKUP_SCHEDULE to any valid cron schedule to modify the default.

For extra security, it is recommended to limit permissions on the backup folder to a priviledged user. Modify docker-compose.override.yml as below.

If you are using postgres docker container, add a dependency to the container

  pgbackup:
    user: postgres:postgres
    depends_on:
      - postgres

Manually trigger a backup

docker exec -it pgbackup ./backup.sh

Restore from latest backup

If the database already exists, drop it. Create a database

docker exec -it <postgres_container> /bin/sh -c "zcat /storage/backups/postgres/last/<db_name>-latest.sql.gz | psql --username=<username> --dbname=<db_name> -W"