Skip to content

Instantly share code, notes, and snippets.

@alcides
Created April 28, 2009 21:57
Show Gist options
  • Save alcides/103424 to your computer and use it in GitHub Desktop.
Save alcides/103424 to your computer and use it in GitHub Desktop.
#!/bin/sh
# MySQL Backup
DIRS="/home/alcides/admin /home/alcides/sites"
NOW=$(date +"%Y-%m-%d")
DAY=$(date +"%a")
FULLBACKUP="Sun"
BACKUP=/home/alcides/backups/$NOW
MUSER="root"
MPASS="youwish"
MHOST="localhost"
EMAIL="[email protected]"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"
[ ! -d $BACKUP ] && mkdir -p $BACKUP || :
if [ "$DAY" == "$FULLBACKUP" ]; then
FILE="filesystem.tar.gz"
tar -zcvf $BACKUP/$FILE $DIRS
fi
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
FILE=$BACKUP/mysql-$db.gz
$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment