-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync_files.sh
54 lines (45 loc) · 1.15 KB
/
sync_files.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
#!/bin/sh
# Default variables
HOST=`hostname`
LOCALIP=`ifconfig eth0 | grep "inet addr:" | awk '{split($2,a,":"); print a[2]}'`
REALIP=`dig +short myip.opendns.com @resolver1.opendns.com`
CURRENTDIR="$(dirname "$0")"
SETTINGS="$CURRENTDIR/sync_files.conf"
SERVERIP=(dig +short "$SERVER")
# Get Setting from File
. $SETTINGS
function log {
(
echo =======================
echo Date: "$(date)"
echo Host: "$HOST"
echo Local IP: "$LOCALIP"
echo External IP: "$REALIP"
echo Key file: "$KEYFILE"
echo Server: "$SERVER"
echo Server IP: "$SERVERIP"
echo User: "$USER"
echo Rsync attributes: "$ATTRIBUTES"
) >> "$LOGFILE"
}
# If you are master exit
function immaster {
if [ "$REALIP" == "$SERVERIP" ]; then
echo Real IP same as Server IP - I\'m master >> "$LOGFILE"
exit 0
fi
if [ "$LOCALIP" == "$SERVERIP" ]; then
echo Local IP same as Server IP - I\'m master >> "$LOGFILE"
exit 0
fi
}
# Copy files usin Rsync
function syncfiles {
while read SOURCE; do
rsync "-$ATTRIBUTES" -e 'ssh -i '"$KEYFILE"'' "$USER"@"$SERVERIP":"$SOURCE/" "$SOURCE" --log-file="$LOGFILE"
done < "$SOURCELIST"
}
log
immaster
syncfiles
exit 0