Created
October 26, 2017 08:52
-
-
Save petri/f99a76a7c70e053baf3f180b73b54d5b to your computer and use it in GitHub Desktop.
mysql backup bash script
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
# 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