Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.