#!/bin/sh

# A list of website directories to back up
websites="site1.com site2.com site3.com"

# The destination directory to backup the files to
destdir=/home/xxxxx/users/.home/s3sync/s3backup

# The directory where all website domain directories reside
domaindir=/home/xxxxx/users/.home/domains


# The MySQL database hostname
dbhost=internal-db.sxxxxx.gridserver.com

# The MySQL database username - requires read access to databases
dbuser=dbxxxxx

# The MySQL database password
dbpassword=xxxxxxx


echo `date` ": Beginning backup process..." > $destdir/backup.log

# remove old backups
rm $destdir/*.tar.gz

# backup databases
for dbname in `echo 'show databases;' | /usr/bin/mysql -h $dbhost -u$dbuser -p$dbpassword`
do
if [ $dbname != "Database" ];
then
echo `date` ": Backing up database $dbname..." >> $destdir/backup.log
/usr/bin/mysqldump --opt -h $dbhost -u$dbuser -p$dbpassword $dbname > $destdir/$dbname.sql
tar -czf $destdir/$dbname.sql.tar.gz $destdir/$dbname.sql
rm $destdir/$dbname.sql
fi
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

# The directory where s3sync is installed
s3syncdir=/home/xxxxx/users/.home/s3sync

# The directory where the backup archives are stored
backupdir=/home/xxxxx/users/.home/s3sync/s3backup

# The S3 bucket a.k.a. directory to upload the backups into
s3bucket=BUCKET-NAME

cd $s3syncdir
./s3sync.rb $backupdir/ $s3bucket: