Skip to content

Instantly share code, notes, and snippets.

@petri
Created October 26, 2017 08:52
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 petri/f99a76a7c70e053baf3f180b73b54d5b to your computer and use it in GitHub Desktop.
Save petri/f99a76a7c70e053baf3f180b73b54d5b to your computer and use it in GitHub Desktop.
mysql backup bash script
# list of databases to back up (all of them except information_schema, see below)
declare -a databases=("mydatabase" "mysql" "performance_schema")
# current day of week as a number from 1 to 7 starting monday
# for week of year use %V (for ISO weeks from 1 to 53)
day_num=$(date +%u)
echo backing up for day "$day_num"
# where the backups are written
cd /var/backups/mysql/daily
#
for dbname in "${databases[@]}"
do
echo backing up "$dbname"
mysqldump -l --databases "$dbname" --single-transaction --routines --triggers | gzip > "$dbname".$day_num.dump.gz
done
# special case; needs skip lock tables param
echo backing up information_schema
mysqldump -l --databases information_schema --single-transaction --routines --triggers --skip-lock-tables | gzip > information_schema."$day_num".dump.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment