Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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

This comment has been minimized.

Copy link
Owner Author

@JRGould 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