Backup DB Server to S3 Encrypted Archive

The following script provides a handy way to perform a periodic backup of your databases to a S3 bucket in the form of a mysql dump encrypted in a password protected zip.


  • Install the aws cli via pip:¬†
  • Create an s3 bucket
  • Assign a role with access to the s3 bucket to your ec2 instance
fileName="dump$(date +%y-%m-%d-%H-%M-%S)"

cd /db/bkp

mysqldump -u backup --all-databases > $fileName.sql

zip $ $fileName.sql -me9D -P <YOUR_SECRET_PASSWORD>

aws s3 cp $ s3://<YOUR_BUCKET_NAME>/$