Skip to content

Instantly share code, notes, and snippets.

@seangreen
Created June 29, 2015 10:18
Show Gist options
  • Save seangreen/a4a753ab8d98f3dfd149 to your computer and use it in GitHub Desktop.
Save seangreen/a4a753ab8d98f3dfd149 to your computer and use it in GitHub Desktop.
Shell Script to RSync media folder from LIVE Install to DEV install + to create a maintenance.flag while doing so
#!/bin/bash
# Variables
# LIVE PATH (relative to current path
LIVE_PATH = ../public_html
# USAGE
function usage()
{
cat <<EOF
Usage: $0 [OPTIONS]
Version: 1.0
Author: Sean Grünböck / studio19.at
Changedate: 29.06.2015
Use this script to rsync live media folder + set maintenance mode, while doing so
OPTIONS:
-s Sync
-n Do not set Maintenance Mode
-h Show help/usage
EOF
}
# FUNCTIONS
function message()
{
STRIP=$(for i in {1..38}; do echo -n "#"; done)
echo -e "$STRIP\n$1\n$STRIP"
}
# GET OPTIONS
while getopts ":snh" OPTION; do
case $OPTION in
h)
usage
exit 0
;;
*)
[[ "$OPTARG" == "" ]] && OPTARG='"-'$OPTION' 1"'
OPTION="OPT_$OPTION"
eval ${OPTION}=$OPTARG
;;
esac
done
# Check that options are set
[[ "$OPT_s$OPT_n" == "" ]] && usage && exit 1
if [[ "$OPT_n" == "" ]]; then
echo "creating maintenance.flag"
echo " " > maintenance.flag
fi
if [[ ! "$OPT_s" == "" ]]; then
rsync -avzh $LIVE_PATH/media/ media/
fi
if [[ "$OPT_n" == "" ]]; then
echo "removing maintenance.flag"
rm maintenance.flag
fi
echo "RSYNC finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment