Created
January 20, 2017 11:25
-
-
Save joshuadegier/8e4a721ab4a412e30e8618f8e26b83da to your computer and use it in GitHub Desktop.
Create back-ups for homestead/vagrant databases
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 | |
NOW=$(date +%Y%m%d%H%M) | |
USER="MYSQL_USERNAME" | |
PASSWORD="MYSQL_PASSWORD" | |
FOLDER="/home/vagrant/Projects/_dbdumps/" | |
cd $FOLDER | |
mkdir -p $NOW | |
databases=`mysql --user=$USER --password=$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database` | |
for db in $databases; do | |
if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != _* ]] ; then | |
echo "Dumping database: $db" | |
mysqldump --force --opt --user=$USER --password=$PASSWORD --databases $db > $NOW/$db.sql | |
fi | |
done | |
mysqldump --user=$USER --password=$PASSWORD --all-databases > $NOW/_full.sql | |
chmod -R +rw $NOW |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment