Automated script for MariaDB/MySQL database backup with upload to Amazon S3.
This script performs automatic backup of a database running in a Docker and uploads the compressed file to an AWS S3 bucket.
- Docker with MariaDB/MySQL container running
 - AWS CLI installed
 - Valid AWS credentials
 - Credentials of database
 
dockergzipaws-cli
Edit the automatic-bkp.sh file and adjust the following variables:
BUCKET_NAME='your-bucket-name'
DESTINATION_IN_BUCKET='backups/'
AWS_ACCESS_KEY_ID="your-access-key"
AWS_SECRET_ACCESS_KEY="your-secret-key"
AWS_DEFAULT_REGION="us-east-1"Make sure the MariaDB container is running with the name mariadb:
docker ps | grep mariadbGive execution permission to the script:
chmod +x automatic-bkp.sh./automatic-bkp.shOr
source automatic-bkp.shExamples crontab:
# Daily backup at 2:00 AM
0 2 * * * /path/to/automatic-bkp.sh
# Backup every 6 hours
0 */6 * * * /path/to/automatic-bkp.shMachine:
/tmp/
└── backup-auto-DD-MM-YYYY-HHh.sql.gz
S3 Bucket:
└── backups/
    └── backup-auto-DD-MM-YYYY-HHh.sql.gz
- Filename generation: Creates unique name based on current date/time
 - Database backup: Executes 
mysqldumpin Docker container - Compression: Compresses dump using 
gzip - S3 upload: Sends file to configured bucket
 - Verification: Confirms if upload was successful
 
backup-auto-16-09-2025-14h.sql.gz
DD-MM-YYYY: Current dateHHh: Current hour
- Check if AWS credentials are correct
 - Make sure variables are exported
 
- Check if MariaDB container is running
 - Confirm container name
 
- Check S3 bucket permissions
 - Confirm credentials have bucket access