Created
September 19, 2017 21:57
-
-
Save JRGould/9cb494b21a6886d47d7d4929931ff730 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
export TERM=xterm; | |
clear; | |
echo " "; | |
echo "---------------------------------------------"; | |
echo " START | "$(date +%m.%d.%Y-%H.%M.%S); | |
echo "---------------------------------------------"; | |
#create db dump for all databases | |
export PATH=/Applications/MAMP/Library/bin/:$PATH; | |
mysqluser=<YOUR MYSQL USER>; | |
mysqlpass=<YOUR MYSQL PASSWORD>; | |
basepath=<WHERE TO STORE DUMPS>; | |
latest=$basepath"_latest/"; | |
date=$basepath"h_"$(date +%Y%m%d_%H%M)"/"; | |
mv $latest $date; | |
mkdir $latest; | |
for I in $(mysql -e 'show databases' -s --skip-column-names -p$mysqlpass -u$mysqluser); | |
do | |
if [[ "$I" == *"_schema" ]]; then | |
echo "--skipping $I"; | |
else | |
echo "dumping $I..."; | |
mysqldump -p$mysqlpass -u$mysqluser $I | gzip > "$latest$I.sql.gz"; | |
fi | |
done | |
echo "---------------------------------------------"; | |
echo " COMPLETE | "$(date +%m.%d.%Y-%H.%M.%S); | |
echo "---------------------------------------------"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should probably change this a bit to always save the current backup in a folder with the current date/time and then just symlink _latest to that with each run as right now the
h_20170916_1800
folder actually contains backups from the previous hour.