Skip to content

Instantly share code, notes, and snippets.

@onyxraven
Last active December 10, 2015 02:18
Show Gist options
  • Save onyxraven/4366220 to your computer and use it in GitHub Desktop.
Save onyxraven/4366220 to your computer and use it in GitHub Desktop.
rsync wrapper script
#!/bin/bash
#requires gnu getopt
#requires rsync
GETOPT="/opt/local/bin/getopt"
rsynccmd="rtlzv --exclude=compile --exclude=cache"
localdir='/Volumes/Work/dev'
devdir='/home/username/dev'
devhost="dev"
fromdev=0
nodelete=0
upfirst=0
withcustom=0
withsvn=0
tmp=`$GETOPT -o h?nRrs -l reverse,no-delete,help,dry-run:: -n $0 -- "$@"`
if [ $? != 0 ] ; then
echo $USAGE >&2
exit 1
fi
eval set -- "$tmp"
# parse options
while true; do
case $1 in
-n|--dry-run )
rsynccmd="n$rsynccmd"
shift;;
--with-custom )
withcustom=1
shift;;
--no-delete )
nodelete=1
shift;;
-o|--config_override )
override=1
shift;;
-R|-r|--reverse )
fromdev=1
shift;;
-s|--svn )
withsvn=1
shift;;
-- )
shift
break;;
* )
echo $USAGE
exit 1;;
esac
done
if [ $nodelete -eq 0 ]; then
rsynccmd="$rsynccmd --delete"
fi
if [ $withcustom -eq 0 ]; then
rsynccmd="$rsynccmd --exclude=custom.ini"
fi
if [ $withsvn -eq 0 ]; then
rsynccmd="$rsynccmd --exclude=.svn"
fi
if [ "x$1" == "x" ]; then
if [ $fromdev -eq 0 ]; then
echo rsync -$rsynccmd $localdir/ $devhost:$devdir/
rsync -$rsynccmd $localdir/ $devhost:$devdir/
else
echo rsync -$rsynccmd $devhost:$devdir/ $localdir/
rsync -$rsynccmd $devhost:$devdir/ $localdir/
fi
fi
while [ "x$1" != "x" ]; do
dir=`echo $1 | tr '^' '/'`
if [ $fromdev -eq 0 ]; then
echo rsync -$rsynccmd $localdir/$dir/ $devhost:$devdir/$dir/
rsync -$rsynccmd $localdir/$dir/ $devhost:$devdir/$dir/
else
echo rsync -$rsynccmd $devhost:$devdir/$dir/ $localdir/$dir/
rsync -$rsynccmd $devhost:$devdir/$dir/ $localdir/$dir/
fi
shift
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment