MySQL database backup on S3 using a bash script

#!/bin/bash
# Open the Backup Directory
cd /home/[ user ]/backups/

#Database dump
/usr/bin/mysqldump -u[ database username ] -h localhost -p[ database password ] [ database name ] | gzip -c > [ database name ]_`date "+%Y-%m-%d.%H-%M-%S"`.sql.gz

#Once the database export is done, use s3cmd to safely upload your database on S3
s3cmd sync /home/[ user ]/backups/ s3://[ bucket ]/

 

If you want to automatically back-up your database, use the following cron

# Automatically back-up your database every 4 hours
0 */4 * * * /home/[ user ]/backups/[ bash filename ].sh

 

Top