Created
March 7, 2017 21:11
-
-
Save wemrekurt/fe4b0eb237714bcec64e8c2ebc7c7e14 to your computer and use it in GitHub Desktop.
MySQL Backup for Rails Apps (on Nginx)
This file contains 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 | |
today=`date +%Y-%m-%d_%H-%M` | |
for i in /etc/nginx/sites-enabled/* | |
do | |
if [ $i != "/etc/nginx/sites-enabled/default" ] | |
then | |
path=`cat $i | grep -w root | awk '{print $2}' | sed 's/\public;//g'` | |
path=$path"config/database.yml" | |
if [ -e $path ] | |
then | |
username=`cat $path | grep -w username | awk '{print $2}'` | |
password=`cat $path | grep -w password | awk '{print $2}'` | |
dbname=`cat $path | awk '$0 == "production:" {i=1;next}; i && $1 == "database:"' | awk '{print $2}'` | |
dump=`mysqldump $dbname -u$username -p$password` | |
filename="/home/emre/mysql_backups/"$today"_"$dbname | |
`echo $dump > $filename.sql` | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment