Skip to content

Instantly share code, notes, and snippets.

@davit
Last active August 29, 2015 14:07
Show Gist options
  • Save davit/ef27b09d27a5b55f4247 to your computer and use it in GitHub Desktop.
Save davit/ef27b09d27a5b55f4247 to your computer and use it in GitHub Desktop.
This script should be used together with "exportdb" script. FOR LOCAL USE ONLY!!!
#!/bin/bash
program_name=`basename $0`
function print_usage() {
echo -e "Usage: ${program_name} [-i module1 module2 ... ] [-e database_name] [-m \"git commit message\"]"
exit "$1"
}
function install_modules() {
local modules="$1"
if [[ ! "$modules" ]]; then
return
else
echo -e "Installing modules: \n ${modules}"
drush -y en ${modules}
fi
}
function git_push() {
local commit_message="$1"
if [[ ! "${commit_message}" ]]; then
print_usage -1
fi
git add -A
git commit -m "${commit_message}"
git pull origin master
git push origin master
}
if [[ ( $1 == "--help") || ( $1 == "-h" ) ]]; then
print_usage 0
elif [[ "$#" -eq 0 ]]; then
print_usage 1
fi
while getopts ":i:e:m:" opt; do
case "${opt}" in
i) modules="${OPTARG}"
;;
e) database="${OPTARG}"
;;
m) message="${OPTARG}"
;;
\?)
echo "Invalid option: -${OPTARG}" >&2
print_usage
exit 1
;;
:)
echo "Option -${OPTARG} requires an argument." >&2
exit 1
esac
done
shift $((OPTIND -1))
if [[ ! -z "${modules}" ]]; then
install_modules "${modules}"
fi
if [[ ! -z "${database}" ]]; then
echo "Exporting database ${database}..."
fi
if [[ ! -z "${message}" ]]; then
git_push "${message}"
fi
#!/bin/bash
dbName=$1;
mysqldump -u DATABASEUSER -pYOURPASSWORD $dbName > ${dbName}.sql
exitcode=$?
#if passed database doesn't exist, remove the exported .sql file
if [[ $exitcode -ne 0 ]]
then
rm ${dbName}.sql
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment