Skip to content

Instantly share code, notes, and snippets.

@mklooss
Last active October 12, 2015 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mklooss/4078327 to your computer and use it in GitHub Desktop.
Save mklooss/4078327 to your computer and use it in GitHub Desktop.
MySQL Backups with mysqldumper
#!/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