Last active
September 25, 2015 02:57
-
-
Save jiphex/851099 to your computer and use it in GitHub Desktop.
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
!/bin/sh | |
# Rsync driver script | |
# James Hannah <james at tlyk dot eu> | |
# PID file name | |
PIDFILE=/var/run/rsyncd-thing.pid | |
# check that its not already running | |
if [ -f $PIDFILE ]; then | |
OLDPID=`cat $PIDFILE` | |
ps -p $OLDPID > /dev/null | |
if [ $? -eq 0 ]; then | |
echo "RSYNCD Already Running!" | |
exit 1 | |
else | |
echo "Stale Pidfile, clearing." | |
rm $PIDFILE | |
echo $! > $PIDFILE | |
fi | |
else | |
echo $! > $PIDFILE | |
fi | |
# Destination host machine name | |
SRC="123.123.123.123" | |
# User that rsync will connect as | |
USER="root" | |
# Directory to copy from on the remote machine. | |
REMOTEDIR="/home/" | |
# Directory to copy to on the local machine. | |
LOCALDIR="/home/" | |
# excludes file - Contains wildcard patterns of files to exclude. | |
EXCLUDES=/root/sync-excludes | |
# port is done below. | |
OPTS="-vaPh --exclude-from=$EXCLUDES --delete" | |
# May be needed if run by cron? | |
export PATH=$PATH:/bin:/usr/bin:/usr/local/bin | |
# Only run rsync if $DEST responds. | |
VAR=`ping -s 1 -c 1 $SRC > /dev/null; echo $?` | |
if [ $VAR -eq 0 ]; then | |
rsync -e'ssh -p2020' $OPTS $USER@$SRC:$REMOTEDIR $LOCALDIR | |
else | |
echo "Cannot connect to $DEST." | |
fi | |
rm -vf $PIDFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment