Container can work in cron-mode and wait-mode:
Default mode, container will make backups according to CRON_SCHEDULE env variable.
In this mode cron is disabled, you may make backups / restores with docker exec (see below). To enable wait mode add command: /wait to your composition.
Container is making archive in the same S3 file every time.
If you want backup file retention enable Versioning on S3 bucket and create S3 Life Cycle Rules to permanently delete older version after certain number of days.
To make backup when container is running in cron-mode or wait-mode:
docker exec -it <container-id> backup
docker exec -it <container-id> backup
Example docker-compose.yml:
version: '3.3'
services:
app:
image: wordpress
environment:
WORDPRESS_DB_HOST: mysql
WORDPRESS_DB_PASSWORD: password
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: password
mysql-backup:
image: mysql-backup
environment:
FILEPREFIX: wordpress/default
S3BUCKET: <your-bucket-name-here>
AWS_ACCESS_KEY_ID: <your-key-id-here>
AWS_SECRET_ACCESS_KEY: <your-aws-secret-key-here>
depends_on:
- mysql
- AWS_ACCESS_KEY_ID - key for aws user with s3 put-object and get-object permissions
- AWS_SECRET_ACCESS_KEY
- S3BUCKET - S3 bucket name
- FILEPREFIX - (optional) file prefix, defaults to "backup"
- CRON_SCHEDULE - (optional) cron schedule, defaults to 3 3 * * * (at 3:03 am, every day)
- MYSQL_HOST - (optional) database host name, defaults to "mysql"
- MYSQL_USER - (optional) database user, defaults to "root"
- MYSQL_PASSWORD - (optional) password, defaults to "password"