Skip to content

Instantly share code, notes, and snippets.

@rikmeijer
Created June 29, 2020 08:07
Show Gist options
  • Save rikmeijer/be3d526ebee46f5c51f1a021ff866da9 to your computer and use it in GitHub Desktop.
Save rikmeijer/be3d526ebee46f5c51f1a021ff866da9 to your computer and use it in GitHub Desktop.
Daily mysql cron dumping all tables, except for information_schema. Writing backups to /var/backups/mysql.
#!/bin/sh
/usr/bin/find /var/backups/mysql/* -mtime +7 -exec rm {} \;
for DB in $(mysql -e 'show databases' -s --skip-column-names); do
if [ "$DB" = "information_schema" ]
then
echo Skipping $DB
continue
fi
echo -n Dumping $DB...
/usr/bin/mysqldump --add-drop-database --add-drop-table --single-transaction --routines --triggers $DB | gzip > "/var/backups/mysql/$DB-$(date '+%Y%m%e').sql.gz";
echo done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment