Created
March 25, 2017 02:31
-
-
Save xelwarto/7c26529e4858e4c039ba8af1d2ac29cb to your computer and use it in GitHub Desktop.
Automatic rsync script for use in vagrants
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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