#!/bin/bash
BUCKET=bucketname
MYSQL_USER=username MYSQL_PASSWORD=password MYSQL_HOST=localhost
echo 'Started'
date +'%a %b %e %H:%M:%S %Z %Y'
mysqldump -u $MYSQL_USER -p$MYSQL_PASSWORD --single-transaction --routines --triggers --all-databases | gzip > backup.gz
S3_KEY=$BUCKET/database/$(date "+%Y-%m-%d")-backup.gz /root/.local/bin/aws s3 cp backup.gz s3://$S3_KEY
rm -f backup.gz date +'%a %b %e %H:%M:%S %Z %Y' echo 'Finished'