Last active
October 13, 2020 19:46
-
-
Save jeremynikolic/f89e93942365454c20e78046555cd625 to your computer and use it in GitHub Desktop.
Commands to backup all databases except excluded ones into a current date folder. Restore allows to restore backups from specific date.
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/bash | |
declare -a exclude=(information_schema mysql performance_schema sys default) | |
echo Mysql user ? | |
read user | |
echo Mysql password ? | |
read password | |
declare folder=$(date +%Y%m%d) | |
mkdir -p $folder | |
for DB in $(mysql --protocol=TCP -u $user -p$password -h mysql -e 'show databases' -s --skip-column-names); do | |
if [[ ! ${exclude[*]} =~ $DB ]]; then | |
mysqldump --protocol=TCP -u $user -p$password -h mysql $DB > "$folder/$DB.sql"; | |
fi | |
done | |
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/bash | |
echo Mysql user ? | |
read user | |
echo Mysql password ? | |
read password | |
echo Backup date to be restored ? | |
read date | |
declare folder=$date | |
for DB in $folder/*; do | |
fullfilename=$(basename -- "$DB") | |
filename="${fullfilename%.*}" | |
echo "Processing $filename file..." | |
mysql --protocol=TCP -u $user -p$password -h mysql $filename < "$folder/$fullfilename"; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment