Skip to content

Instantly share code, notes, and snippets.

@edisplay
Forked from JRGould/backup-all-dbs.sh
Created December 27, 2020 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edisplay/163443f11b2a4e84372123450e1a31f3 to your computer and use it in GitHub Desktop.
Save edisplay/163443f11b2a4e84372123450e1a31f3 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 "---------------------------------------------";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment