- Build the image
docker build -t backups . --build-arg HOUR_OF_DAY=23
- Run the image
docker run -idt backups --env MYSQL_USERNAME=<> --env MYSQL_PASSWORD=<> --env SERVER=<> --env DB_NAME=<> --env BUCKET=<abc.bucket.com> --env AWS_ACCESS_KEY_ID=<> --env AWS_SECRET_ACCESS_KEY=<>
- Connect to the network of your DB container (Only when DB is in another container)
docker network connect <network_name> <backup_container>
- Verify backups manually
docker exec -it <backup_container> bash
Inside the container: sh script.sh
Add the below section to your docker compose:
backups:
build:
context: ./backups
args:
HOUR_OF_DAY: 23
depends_on:
- <"db">
networks:
- <db>
environment:
- BUCKET_NAME=<abc.bucket.com>
- MYSQL_USERNAME=
- MYSQL_PASSWORD=
- SERVER=
- DB_NAME=
# Specify AWS credentials or skip if using AWS IAM roles
- AWS_ACCESS_KEY_ID=
- AWS_SECRET_ACCESS_KEY=
restart: always
Using Dockerhub? Replace build:
with image: fundwave/s3-mysql-backup-cron:latest
, but you won't be able to change HOUR_OF_DAY
as it's a build arg.