Skip to content

Instantly share code, notes, and snippets.

@BinaryKitten
Last active March 20, 2018 09:44
Show Gist options
  • Save BinaryKitten/c61c8507982ca78991903f79879ebc11 to your computer and use it in GitHub Desktop.
Save BinaryKitten/c61c8507982ca78991903f79879ebc11 to your computer and use it in GitHub Desktop.
#!/bin/bash
DATE=`date +%Y-%m-%d_%H-%M-%S`
cd "/vagrant/backups/"
mkdir $DATE && cd $_
for i in `mysql -u root -psecret -e "show databases;" | grep -Ev "^(Database|mysql|performance_schema|information_schema)$"`; do
echo "dumping ${i}"
sudo mysqldump -c -u root -psecret ${i} > ${i}.sql
done
#!/bin/bash
for f in *.sql
do
filename=$(basename "$f")
extension="${filename##*.}"
table="${filename%.*}"
echo Restoring $filename to $table
mysql --login-path=local $table < $f
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment