Skip to content

Instantly share code, notes, and snippets.

@wemrekurt
Created March 7, 2017 21:11
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 wemrekurt/fe4b0eb237714bcec64e8c2ebc7c7e14 to your computer and use it in GitHub Desktop.
Save wemrekurt/fe4b0eb237714bcec64e8c2ebc7c7e14 to your computer and use it in GitHub Desktop.
MySQL Backup for Rails Apps (on Nginx)
#!/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