Skip to content

Instantly share code, notes, and snippets.

@hpatoio
Created July 18, 2012 13:54
Show Gist options
  • Save hpatoio/3136349 to your computer and use it in GitHub Desktop.
Save hpatoio/3136349 to your computer and use it in GitHub Desktop.
#!/bin/sh
BACKUP="/path/to/temp/dir/$$"
DAY=$(date +"%a")
### MySQL Setup ###
MUSER="root"
MPASS="your_root_password"
MHOST="localhost"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"
### FTP server Setup ###
FTPUSER="ftp_username"
FTPPASS="ftp_password"
FTPHOST="ftp_host"
mkdir -p $BACKUP
### Start MySQL Backup ###
# Get all databases name
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
FILE=$BACKUP/$(date +"%a")-$db.gz
$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
echo "Saving "$db" to "$FILE
done
### Dump backup using FTP ###
echo "Sending file via FTP"
ftp -ni $FTPHOST > /tmp/ftp.worked 2 > /tmp/ftp.failed <yourmail@yourdomain.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment