I have pushed to the Docker Hub an image I have been using for 3 years to backup my containers: hleroy/backup-s3. It is fairly simple setup with a few bash scripts and
awscli to push data to S3. The typical use case is to back up an application run with docker-compose (like this WordPress blog).
It saved me from data loss a couple of times so it’s worth giving it a try if you use Docker to run your infrastructure 🙂
Setup with Docker-compose
Add backup-s3 to your compose file. This is an example to backup a WordPress container:
backup: image: hleroy/backup-s3 volumes: - wordpress:/var/www/html # Volume to back up environment: # Provide env secrets (S3 key etc...) # S3 S3_REGION: eu-central-1 S3_BUCKET: my-bucket S3_ACCESS_KEY_ID: access_key_id S3_SECRET_ACCESS_KEY: secret_access_key # Database DB_ENGINE: mysql DB_NAME: wordpress DB_USER: wordpress DB_PASS: wordpress DB_HOST: mysql DB_PORT: 5432 # Data DATA_PATH: '/var/www/html' # Customize to your needs # Cron schedule CRON_SCHEDULE: '0 0 * * *' # Every day at midnight
DB_ENGINE can be
postgres. If omitted, no database backup is attempted.
DB_PORT is optional. It defaults to 3306 (for mysql) or 5432 (for postgres).
DATA_PATH must be an absolute path with no trailing slash. If omitted, no data backup is attempted.
CRON_SHEDULE uses the usual cron format. Try https://crontab.guru/ to customize to your needs.
More details and a complete Docker-compose example for WordPress are available in the repository.