Last active
July 19, 2019 07:31
-
-
Save anggadarkprince/4c528c64100eca05ff0f7fead92d0811 to your computer and use it in GitHub Desktop.
Shell script to run mysqldump and gzip them to separate database
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 | |
folder_name=/home/backup/databases/$(date +%Y)/$(date +%Y%m)/"$(date +%Y-%m-%d)-$(date +%H:%M)" | |
mkdir -p $folder_name && cd $folder_name | |
mysql -N -e 'show databases' | | |
while read dbname; | |
do | |
if [ $dbname != "mysql" ] && [ $dbname != "information_schema" ] && [ $dbname != "performance_schema" ] && [ $dbname != "sys" ] | |
then | |
mysqldump --complete-insert --routines --triggers --single-transaction "$dbname" > "$dbname".sql; | |
[[ $? -eq 0 ]] && gzip "$dbname".sql; | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment