MySQL Script For Database Backup to Amazon S3

Script Specification:

• It will take MySQL Database backup automatically.
• Upload it to Amazon S3
• After Uploading MySQL Backup to Amazon S3 it automatically delete backup more then 14 days old.
• This script will run on every Wednesday at 5:30 AM

# vi mysqlscript.sh
#############################################################
Insert following Lines in it.
##############################################################
#!/bin/sh

DB_NAME=”your_DB_Name”
DB_USER=”Your_DB_User_Name”
DB_PASSWORD=”Your_DB_password”
DB_PATH=/tmp/DB_Backup
DATE=`date +%d%m%y%H%M`

# export database
mysqldump -u $DB_USER -p$DB_PASSWORD $DB_NAME | gzip>$DB_PATH/MySQL_BACKUP_$DATE.sql.gz

# sync to amazon
s3cmd sync $DB_PATH/MySQL_BACKUP_$DATE.sql.gz s3://q2kdbbackup

# remove backups older than 14 days
find $DB_PATH/MySQL_BACKUP* -mtime +14 -exec rm {} ;

################################################################
Crontab Entry
################################################################
30 5 * * wed /home/jitendra/script/mysqldb.sh.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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