Skip to content

Instantly share code, notes, and snippets.

@JRGould
Created September 19, 2017 21:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JRGould/9cb494b21a6886d47d7d4929931ff730 to your computer and use it in GitHub Desktop.
Save JRGould/9cb494b21a6886d47d7d4929931ff730 to your computer and use it in GitHub Desktop.
#!/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 "---------------------------------------------";
@JRGould
Copy link
Author

JRGould commented Sep 19, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment