Skip to content

Instantly share code, notes, and snippets.

@pch
Created January 5, 2011 14:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pch/766349 to your computer and use it in GitHub Desktop.
Save pch/766349 to your computer and use it in GitHub Desktop.
#!/bin/bash
BACKUP_DIR='/home/rsync/mysql_backup'
MHOST='localhost'
MUSER='root'
MPASS='yourpass'
NOW=$(date +"%Y-%m-%d_%H")
#
#
#
mkdir $BACKUP_DIR/$NOW
DBS="$(mysql -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"§
for db in $DBS
do
db=${db%§}
echo "Backing up $db"
FILE=$BACKUP_DIR/$NOW/$db.sql
mysqldump --extended-insert --add-drop-table --allow-keywords -q -c -u $MUSER -h $MHOST -p$MPASS $db> $FILE
done
cd $BACKUP_DIR
tar -czf $NOW.tar.gz $NOW
rm -rf $NOW
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment