Backup MySQL DBs to Amazon S3 Bucket using Python

In this tutorial I’ll show you the simple Python script that takes the compressed MySQL dumps and then upload it to AMAZON S3 Bucket. The script will also automatically delete the backup that are older than the days (mentioned in the script).


This script requires boto. Install boto using pip:

sudo pip install boto

The script requires the following configuration parameters

AWS Details:
S3_BUCKET = 'Your-S3-Bucket'
MySQL Details:
DB_HOST = 'DB-HOST-ADDRESS' # Can be RDS/localhost
BACKUP_PATH = '/tmp/dbbackup' # location on local host to save dump before upload it to S3
DeleteOlderThan = 10 # Delete the dumps older then mentioned days

Paste the below code into the script after the modifying the above configuration:

[gist /]

To use this script:

You can use it manually or using as cronjob.


Or make it executable first:

chmod +x

and then run it:


Or add this line to run the script at midnight every day:

0 0 * * * /usr/bin/python /path/to/script/

Enjoy :-)

Hope this will help you!

Please Remember me in your prayers!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: