Skip to content

Instantly share code, notes, and snippets.

@xelwarto
Created March 25, 2017 02:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xelwarto/7c26529e4858e4c039ba8af1d2ac29cb to your computer and use it in GitHub Desktop.
Save xelwarto/7c26529e4858e4c039ba8af1d2ac29cb to your computer and use it in GitHub Desktop.
Automatic rsync script for use in vagrants
#!/usr/bin/env bash
SRC=""
DEST=""
TMP_FILE="/tmp/auto_rsync_"
PAUSE="10"
while getopts ":s:d:p:" OPTS; do
case $OPTS in
s)
SRC="$OPTARG"
;;
d)
DST="$OPTARG"
;;
p)
PAUSE="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
if [ -z "$SRC" ] ; then
echo "Source not provided"
exit 1
fi
if [ -z "$DST" ] ; then
echo "Destination not provided"
exit 1
fi
echo "Performing initial sync..."
rsync --archive "$SRC" "$DST"
while [ "1" ]; do
rsync --itemize-changes --archive "$SRC" "$DST"
sleep $PAUSE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment