Last active
January 5, 2016 14:38
-
-
Save psyao/f13dae5e801788894178 to your computer and use it in GitHub Desktop.
Dump 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/sh | |
# 0 9,16 * * * /home/vagrant/backups/dbbackup.sh >/dev/null | |
DATE=`date +%Y%m%d%H%M%S` | |
USER=homestead | |
PASSWORD=secret | |
echo "Changing directory..." | |
cd "/home/vagrant/backups/db/" | |
echo "All databases backup..." | |
sudo mysqldump -R -u$USER -p$PASSWORD --all-databases > ./$DATE.sql | |
gzip ./$DATE.sql | |
echo "Single database backup..." | |
for i in `mysql -u $USER -p$PASSWORD -e "show databases;" | grep -Ev "^(Database|mysql|performance_schema|information_schema)$")`; do | |
mkdir -p ./${i}/ | |
sudo mysqldump -c -u $USER -p$PASSWORD ${i} > ./${i}/$DATE.sql | |
gzip ./${i}/$DATE.sql | |
#find ./${i}/*.sql -mtime +31 -exec rm {} \; | |
done | |
echo "Databases dumped" | |
cd - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment