The Backup Helper aims to help you make and restore backups of your project files and PostgreSQL database. Also, you can upload and download backup files to Google Cloud Storage.
A list of commands that you can run with this container:
backup_postgres
: make a backup of PostgreSQL database(s)backup_files
: make a backup of files and directoriesbackup_ls
: list local backup filesbackup_clean
: remove local backup filesrestore_postgres
: restore a backup of a PostgreSQL databaserestore_files
: restore a backup of files and directoriesgcs_upload
: upload backup files to Google Cloud Storagegcs_download
: download a backup file from Google Cloud Storagegcs_ls
: list backup files present in Google Cloud Storage
In the rest of this README, you can find more information about how to run and configure these commands.
The Docker image of the Backup Helper is available on Docker Hub:
docker pull askanna/backup-helper
Via environment variables you can configure the Backup Helper.
Environment variable | Required | Default | Description |
---|---|---|---|
BACKUP_DIR |
No | /backups |
The path where the backups will be saved |
BACKUP_FILE_PREFIX |
No | backup |
An optional prefix for the backup filename |
BACKUP_KEEP_DAYS |
No | NONE |
The number of days you want to keep local backup files. The Backup Helper only removes local backup files when you run backup_clean .NONE : remove all local backups0 : keep backups that are modified less than 24 hours ago1 : keep backups that are modified less than 48 hours agon : keep backups that are modified less than (n + 1) * 24 hours ago |
BACKUP_ZIP_FILES |
No | true |
true / false ; if set to true , file compression with gzip will be applied. To speed up the backup of files, you can set BACKUP_ZIP_FILES to false . |
Environment variable | Required | Default | Description |
---|---|---|---|
POSTGRES_HOST |
No | localhost |
The PostgreSQL database server host |
POSTGRES_PORT |
No | 5432 |
The PostgreSQL database server port |
POSTGRES_DB |
No | The database to backup. If this variable is not set, the POSTGRES_USER name is used (ref. documentation). |
|
POSTGRES_DATABASES |
No | The databases to backup. If both POSTGRES_DATABASES and POSTGRES_DB are provided, the POSTGRES_DATABASES variable will be used.Format: database_1 database_2 database_3 (without quotation marks) |
|
POSTGRES_USER |
No | The PostgreSQL database user | |
POSTGRES_PASSWORD |
No | The PostgreSQL database password |
Environment variable | Required | Default | Description |
---|---|---|---|
BACKUP_SOURCE |
No | /data |
The path of the directory with the files to backup |
BACKUP_TARGET |
No | ${BACKUP_SOURCE} |
The path of the directory where files should be restored to |
Environment variable | Required | Default | Description |
---|---|---|---|
GCS_BUCKET |
No | The Google Cloud Storage Bucket you want to upload the backup files to or download them from This variable is required if you want to use the Backup Helper to upload files to or download from Google Cloud Storage. |
|
GCS_KEY_FILE_PATH |
No | /keys/gcs-key.json |
The path where the GCS service account key file will be mounted. This variable is required if you want to use the Backup Helper to upload files to or download from Google Cloud Storage. |
To use the Google Cloud Storage features, you need to have a Google service account or create a new service account. To authenticate, you need to have the associated private JSON key of the service account or create a new service account JSON key.
There is a backup, upload and clean script in this image's directory /etc/periodic/daily
. This backup script run the
following commands:
- gcs_upload
- backup_clean
- backup_postgres
- backup_files
- gcs_upload
When you start the image, the daily backup is not scheduled because the cron daemon is not started by default. When
you run the image with the command crond -f
it will start the cron daemon and schedule the daily backup. See also
'How we use it'.
We use the Backup Helper for the AskAnna project that we run as a Docker Stack. In our
Docker Compose file we have a service named backup-helper
:
backup_helper:
image: askanna/backup-helper
command: crond -f
volumes:
- backup_volume:/backups
- storage_volume:/data
- ../gcs-key.json:/keys/gcs-key.json:ro
env_file:
- ./postgres.env
environment:
GCS_BUCKET: <Google Cloud Storage Bucket name>
With the Backup Helper available as a service in the Docker Stack, we can perform backup tasks. Depending on the backup task, we run one or multiple of the commands below.
If you don't want to schedule a daily backup, remove the line
command: crond -f
.
docker-compose run --rm backup_helper backup_postgres
docker-compose run --rm backup_helper backup_files
docker-compose run --rm backup_helper backup_ls
docker-compose run --rm backup_helper restore_postgres <backup file>
docker-compose run --rm backup_helper restore_files <backup file>
docker-compose run --rm backup_helper backup_clean
docker-compose run --rm backup_helper gcs_upload
docker-compose run --rm backup_helper gcs_download <backup file>
docker-compose run --rm backup_helper gcs_ls
The Backup Helper is inspired by cookiecutter/cookiecutter-django and diogopms/postgres-gcs-backup.