Skip to content

Instantly share code, notes, and snippets.

@anggadarkprince
Last active July 19, 2019 07:31
Show Gist options
  • Save anggadarkprince/4c528c64100eca05ff0f7fead92d0811 to your computer and use it in GitHub Desktop.
Save anggadarkprince/4c528c64100eca05ff0f7fead92d0811 to your computer and use it in GitHub Desktop.
Shell script to run mysqldump and gzip them to separate database
#!/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