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).
Requirements:
This script requires boto. Install boto using pip:
sudo pip install boto
Configuration:
The script requires the following configuration parameters
AWS Details:
AWS_ACCESS_KEY_ID = 'You-AWS-ACCESS-KEY-ID' AWS_SECRET_ACCESS_KEY = 'You-AWS-SECRET-ACCESS-KEY' S3_BUCKET = 'Your-S3-Bucket'
MySQL Details:
DB_HOST = 'DB-HOST-ADDRESS' # Can be RDS/localhost DB_USER = 'USERNAME' DB_USER_PASSWD = 'PASSWORD' 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 https://gist.github.com/arbabnazar/b612e210fe31bcd33077 /]
To use this script:
You can use it manually or using as cronjob.
python mysqldumptos3.py
Or make it executable first:
chmod +x mysqldumptos3.py
and then run it:
./mysqldumptos3.py
Or add this line to run the script at midnight every day:
0 0 * * * /usr/bin/python /path/to/script/mysqldumptos3.py
Enjoy
Hope this will help you!
Please Remember me in your prayers!
Regard's
Muhammad Waseem Mayo
+923007396305
Muhammad Waseem Mayo
+923007396305
Comments
Post a Comment