Created
November 11, 2013 17:16
-
-
Save abovedave/7416785 to your computer and use it in GitHub Desktop.
Backup to an S3 bucket. Requires Python and s3cmd (https://github.com/s3tools/s3cmd) Optimised for Media temple but could be tweaked for any set-up
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Media Temple account number | |
account="XXXXXX" | |
# A list of website directories to back up | |
websites="example.com" | |
homedir="/home/$account/users/.home" | |
# The destination directory to backup the files to | |
destdir="/home/$account/users/.home/s3backup" | |
# The directory where all website domain directories reside | |
domaindir="/home/$account/domains" | |
# The MySQL database hostname | |
dbhost="internal-db.s$account.gridserver.com" | |
# The MySQL database username - requires read access to databases | |
dbuser="dbXXXXXX" | |
# The MySQL database password | |
dbpassword="RpGKyApS" | |
dbnames="XXXXXX" | |
# The S3 bucket a.k.a. directory to upload the backups into | |
s3bucket="XXXXXX" | |
echo date ": Beginning backup process..." > "$destdir/backup.log" | |
# remove old backup | |
rm $destdir/*.tar.gz > /dev/null 2>&1 | |
for dbname in $dbnames; do | |
echo date ": Backing up database $dbname..." >> $destdir/backup.log | |
/usr/bin/mysqldump --opt --skip-lock-tables -h $dbhost -u$dbuser -p$dbpassword $dbname > $destdir/$dbname.sql | |
tar -czf $destdir/$dbname.sql.tar.gz $destdir/$dbname.sql | |
rm $destdir/$dbname.sql | |
done | |
# backup web content | |
echo date ": Backing up web content..." >> $destdir/backup.log | |
for website in $websites; do | |
echo date ": Backing up website $website..." >> $destdir/backup.log | |
tar -czf $destdir/$website.tar.gz $domaindir/$website | |
done | |
echo date ": Backup process complete." >> $destdir/backup.log | |
$homedir/bin/s3cmd sync --config="$homedir/.s3cfg" --acl-private --recursive "$destdir/" s3://$s3bucket | |
echo date ": Upload complete! :)" >> $destdir/backup.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment