-
Notifications
You must be signed in to change notification settings - Fork 13
/
synchro.sh
executable file
·75 lines (61 loc) · 2.5 KB
/
synchro.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/sh
# Simple rsync "driver" script. (Uses SSH as the transport layer.)
# http://www.scrounge.org/linux/rsync.html
# Demonstrates how to use rsync to back up a directory tree from a local
# machine to a remote machine. Then re-run the script, as needed, to keep
# the two machines "in sync." It only copies new or changed files and ignores
# identical files.
# Destination host machine name
DEST="home"
# User that rsync will connect as
# Are you sure that you want to run as root, though?
USER="martin"
# Directory to copy from on the source machine.
TVDIR="/home/torrent/public/tv"
MOVIEDIR="/home/torrent/public/movies/"
# Directory to copy to on the destination machine.
TVDESTDIR="/home/media/"
MOVIEDESTDIR="/home/media/temp/"
# Log file
LOG_FILE="local0.info"
LOG_APP="rsync"
SCRIPT_PATH="/home/torrent/torrent-scripts/"
# excludes file - Contains wildcard patterns of files to exclude.
# i.e., *~, *.bak, etc. One "pattern" per line.
# You must create this file.
# EXCLUDES=/root/bin/excludes
# Options.
# -n Don't do any copyi, but display what rsync *would* copy. For testing.
# -a Archive. Mainly propogate file permissions, ownership, timestamp, etc.
# -u Update. Don't copy file if file on destination is newer.
# -v Verbose -vv More verbose. -vvv Even more verbose.
# See man rsync for other options.
# For testing. Only displays what rsync *would* do and does no actual copying.
#OPTS="-n -u -r -L --rsh=ssh --exclude-from=$EXCLUDES --log-format=%n"
# Does copy, but still gives a verbose display of what it is doing
OPTS="-u -L -r --rsh=ssh --exclude-from=$EXCLUDES --log-format=%n"
# Copies and does no display at all.
#OPTS="--archive --update --rsh=ssh --exclude-from=$EXCLUDES --quiet"
# May be needed if run by cron?
export PATH=$PATH:/bin:/usr/bin:/usr/local/bin
PROCESS="rsync"
pgrep $PROCESS >/dev/null
if [ "$?" = "1" ]
then
# Only run rsync if $DEST responds.
VAR=`ping -s 1 -c 1 $DEST > /dev/null; echo $?`
if [ $VAR -eq 0 ]
then
TV_STATUS=`rsync $OPTS $TVDIR $USER@$DEST:$TVDESTDIR`
TV_STATUS2=`echo $TV_STATUS | sed '/rsync:.*]/d' | sed 's/ /\n/g' | sed s_tv/.*/__ | sed '/^$/d'`
if [ "$TV_STATUS2" != "" ]; then
LOG=`echo $TV_STATUS2 | sed 's/ /\n/g'`
logger -p $LOG_FILE -t $LOG_APP "tv: "$LOG
fi
MOVIE_STATUS=`rsync $OPTS $MOVIEDIR $USER@$DEST:$MOVIEDESTDIR | sed 's/rsync:.*]//' | sed 's/ /\n/g' | sed 's/\(.*[\/]\).*/\1/' | grep "/$"`
if [ "$MOVIE_STATUS" != "" ]; then
LOG=`echo $MOVIE_STATUS | sed 's/ /\n/g'`
logger -p $LOG_FILE -t $LOG_APP "movies: "$LOG
fi
fi
fi