Skip to content

Instantly share code, notes, and snippets.

@petethepig
Created September 15, 2012 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petethepig/3729222 to your computer and use it in GitHub Desktop.
Save petethepig/3729222 to your computer and use it in GitHub Desktop.
#!/bin/bash
USER=root #mysql credentials
PASSWORD=***
BACKUP=/root/backups #temporary storage
CLOUD=/mnt/yandex.disk/backups
OLD=10
PREFIX=dfilimonov.com
DATE=`date '+%Y-%m-%d'`
echo "dumping database to $BACKUP"
mkdir $BACKUP/$DATE.sql
cd $BACKUP/$DATE.sql
for i in `mysql -u $USER -p$PASSWORD -e'show databases;' | grep -v information_schema | grep -v Database`;
do mysqldump -u $USER -p$PASSWORD $i > $DATE-$i.sql;
done
echo "packing database backups"
cd ..
tar -cjf $BACKUP/$DATE-sql-$PREFIX.tar.bz2 ./$DATE.sql
rm -rf ./$DATE.sql
echo "packing all files to $BACKUP"
tar -cjf $BACKUP/$DATE-files-$PREFIX.tar.bz2 \
/var/www/ \
/etc/ \
/var/log/ \
/root/ \
/home/ \
--exclude=$BACKUP \
--exclude=/root/distrs
echo "moving everything to $CLOUD"
mv -b $BACKUP/* $CLOUD
echo "deleting old backups from $CLOUD"
find $CLOUD -mtime +$OLD -exec rm '{}' \;
echo "deleting everything from $BACKUP"
rm -rf $BACKUP/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment