Sign inSign up

leikir/postgres-backup-local

By leikir

•Updated over 7 years ago

Backup PostgresSQL to local filesystem with periodic backups and rotate backups.

Image
0

538

leikir/postgres-backup-local repository overview

⁠postgres-backup-local

Backup PostgresSQL to local filesystem with periodic backups and rotate backups. Based on prodrigestivill/docker-postgres-backup-local⁠. It can backup multiple databases from the same host by setting all databases in POSTGRES_DB separated by comas or spaces.

⁠Usage

Docker:

$ docker run -e POSTGRES_HOST=postgres -e POSTGRES_DB=dbname -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password  leikir/postgres-backup-local

Docker Compose:

version: '2'
services:
    postgres:
        image: postgres
        restart: always
        environment:
            - POSTGRES_DB=database
            - POSTGRES_USER=username
            - POSTGRES_PASSWORD=password
         #  - POSTGRES_PASSWORD_FILE=/run/secrets/db_password <-- alternative for POSTGRES_PASSWORD (to use with docker secrets)
    pgbackups:
        image: leikir/postgres-backup-local
        restart: always
        volumes:
            - /var/opt/pgbackups:/backups
        links:
            - postgres
        depends_on:
            - postgres
        environment:
            - POSTGRES_HOST=postgres
            - POSTGRES_DB=database
            - POSTGRES_USER=username
            - POSTGRES_PASSWORD=password
         #  - POSTGRES_PASSWORD_FILE=/run/secrets/db_password <-- alternative for POSTGRES_PASSWORD (to use with docker secrets)
            - POSTGRES_EXTRA_OPTS=-Z9 --schema=public --blobs
            - SCHEDULE=@daily
            - BACKUP_KEEP_DAYS=7
            - BACKUP_KEEP_WEEKS=4
            - BACKUP_KEEP_MONTHS=6
            - HEALTHCHECK_PORT=80

⁠Manual Backups

By default it makes daily backups but you can start a manual one by running the command /backup.sh.

Example running only manual backup on Docker:

$ docker run -e POSTGRES_HOST=postgres -e POSTGRES_DB=dbname -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password  leikir/postgres-backup-local /backup.sh
⁠Automatic Periodic Backups

You can change the SCHEDULE environment variable like -e SCHEDULE="@daily" to change its default frequency, by default is daily.

More information about the scheduling can be found here⁠.

Folders daily, weekly and monthly are created and populated using hard links to save disk space.

Tag summary

Content type

Image

Digest

Size

86.9 MB

Last updated

over 7 years ago

docker pull leikir/postgres-backup-local:10.4