Skip to content

Instantly share code, notes, and snippets.

@mofoster
Created August 3, 2014 12:36
Show Gist options
  • Save mofoster/dd462351247cc19fbab1 to your computer and use it in GitHub Desktop.
Save mofoster/dd462351247cc19fbab1 to your computer and use it in GitHub Desktop.
web & db backup shell script
#!/bin/bash
DOMAIN="melora.hk"
ADMIN="[email protected]"
DOCPATH="/var"
DOCNAME="www"
DBNAME="melora"
DBUSER="dbbackup"
DBPASS="93a09c1debd58578cd570fa0e4d1fb44"
LPATH="/backup/melora.hk"
RPATH="s3://mkw-backup/melora.hk"
DATE=$(date +%Y%m%d)
DAYWEEK=$(date +%a)
LOGFILE="/backup/melora.hk/logfile.txt"
S3CMD="/usr/bin/s3cmd"
TAR="/bin/tar"
MYSQLDUMP="/usr/bin/mysqldump"
GZIP="/bin/gzip"
TEE="/usr/bin/tee"
DU="/usr/bin/du"
### stop editing below this line :) ###
cd $DOCPATH
$TAR -czf $LPATH/$DOMAIN-$DAYWEEK.tar.gz $DOCNAME
$MYSQLDUMP -u"$DBUSER" -p"$DBPASS" $DBNAME | $GZIP > $LPATH/$DBNAME-$DAYWEEK.sql.gz
echo "=== s3 sync log ===" | $TEE $LOGFILE
$S3CMD sync $LPATH/ $RPATH/ | $TEE -a $LOGFILE
echo | tee -a $LOGFILE
echo "=== remote bucket backup ===" | $TEE -a $LOGFILE
$S3CMD ls $RPATH/ | tee -a $LOGFILE
echo | tee -a $LOGFILE
echo "=== local backup ===" | $TEE -a $LOGFILE
$DU -sh $LPATH/* | $TEE -a $LOGFILE
/usr/bin/mail -s "Backup report for $DOMAIN at $DATE" $ADMIN < $LOGFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment