Last active
October 12, 2015 19:48
-
-
Save mklooss/4078327 to your computer and use it in GitHub Desktop.
MySQL Backups with mysqldumper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# MySQL Account Data in ~/.my.cnf | |
BACKUPDIR="/home/backups/sql"; | |
DBFILTER="(information_schema|performance_schema|mysql|dev|tmp|froxlor|test)"; | |
MYSQLDUMP="$(which mysqldump) -e --opt --skip-add-locks"; | |
DIRNAME=`date +%Y-%m-%d`; | |
MYSQL=$(which mysql); | |
TAR=$(which tar); | |
GZIP=$(which gzip); | |
NICE=$(which nice); | |
EGREP=$(which egrep); | |
# Delete Old Files | |
/usr/bin/find $BACKUPDIR -depth -mtime +14 -exec rm -rf '{}' \; | |
mkdir -p "$BACKUPDIR/$DIRNAME"; | |
DBS=$($MYSQL -Bse "show databases"); | |
for db in $DBS | |
do | |
if !(echo $db | $EGREP $DBFILTER > /dev/null); | |
then | |
FILENAME="$db-`date +%Y_%m_%d_%H_%M_%S`.sql.gz"; | |
$NICE -n 20 $MYSQLDUMP $db | $NICE -n 20 $GZIP -c > "$BACKUPDIR/$DIRNAME/$FILENAME"; | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment