-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfry-rsync.sh
executable file
·150 lines (123 loc) · 4.3 KB
/
fry-rsync.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/sh
REPONAME=openbricks
REPOURL="https://github.com/OpenBricks/openbricks.git"
SYNCTARGET="[email protected]"
BASE=/home/geexbox/bot/buildbot
BUILD=$BASE/build
REPO=$BASE/src/$REPONAME
SOURCES=$BASE/src/sources
STAMPSGET=$BASE/src/.stamps
SNAPSHOTS=$BASE/snapshots
SNAPSHOTSD=$BASE/snapshots/data
LOGS=$BASE/logs
LOGFILE=$BASE/logs/$REPONAME.log
STAMPS=$BASE/stamps
PIDFILE=$STAMPS/lockrsync
PIDFILE_BUILDBOT=$STAMPS/lock
BWLIMIT=100
XFERLOG=/tmp/rlog
RSYNCLOG=$LOGS/rsynclogs
STATUSLOG=$LOGS/statuslogs
DATE=`date +%Y%m%d`
log() {
NOW=`date "+%b %d %T"`
echo "$NOW [$$] $1" >> $LOGFILE
}
sendlogs () {
rsync_args="-t --size-only --bwlimit=$BWLIMIT --archive --log-file=$XFERLOG --partial $LOGS/$REPONAME/*.?z* $SYNCTARGET:/data/logs-buildbot"
echo "Rsyncing build logs: $rsync_args" >> $RSYNCLOG
rsync $rsync_args >> $RSYNCLOG 2>&1
if [ $? -eq 0 ]; then
log "rsync successful (logs)"
else
log "rsync failed (logs)"
fi
}
sendsnapshot () {
rsync_args="-t --size-only --bwlimit=$BWLIMIT --archive --log-file=$XFERLOG --partial $SNAPSHOTSD $SYNCTARGET:/data/snapshots/"
echo "Rsyncing snapshot data: $rsync_args" >> $RSYNCLOG
rsync $rsync_args >> $RSYNCLOG 2>&1
if [ $? -eq 0 ]; then
log "rsync successful (data)"
rm -f $LOGS/rsynchfailed
else
log "rsync failed (data)"
touch $LOGS/rsynchfailed
fi
}
sendsnapshotlink () {
if ! [ -f $LOGS/rsynchfailed ] ; then
rsync_args="-t --size-only --bwlimit=$BWLIMIT --archive --delete --log-file=$XFERLOG --partial $SNAPSHOTS/* $SYNCTARGET:/data/snapshots"
echo "Rsyncing snapshot links: $rsync_args" >> $RSYNCLOG
rsync $rsync_args >> $RSYNCLOG 2>&1
if [ $? -eq 0 ]; then
log "rsync successful (links)"
else
log "rsync failed (links)"
fi
else
log "rsync skipped (links)"
fi
}
remove_source () {
if [ ! -e $SOURCES/$1/$2.bad ]; then
mv -f $SOURCES/$1/$2 $SOURCES/$1/$2.bad
rm $STAMPSGET/$1/.*.get $STAMPSGET/$1/*.ok
echo "Removing $1/$2" >> $STATUSLOG
echo "--------------------------------------------------------------------------------------" >> $STATUSLOG
fi
}
# Create directories
mkdir -p $SNAPSHOTS/$REPONAME $SNAPSHOTSD/$REPONAME $STAMPS/$REPONAME $LOGS/$REPONAME
log "Starting rsync to fry ..."
# Check for re-entry
if [ -r $PIDFILE ]; then
log "Another rsync instance ($(cat $PIDFILE)) is running, aborting."
exit 1
fi
/bin/echo -n $$ > $PIDFILE
# Move old rsync log
cat $RSYNCLOG >> $LOGS/$REPONAME/rsync.$DATE.log
date -R > $RSYNCLOG
echo "--------------------------------------------------------------------------------------" > $STATUSLOG
cat $LOGFILE >> $STATUSLOG
echo "--------------------------------------------------------------------------------------" >> $STATUSLOG
echo "SYSTEM: $(cat /etc/issue)" >> $STATUSLOG
echo "WHOAMI: $(whoami)" >> $STATUSLOG
echo " USER: $USER" >> $STATUSLOG
echo " HOME: $HOME" >> $STATUSLOG
echo " PWD: $PWD" >> $STATUSLOG
echo "--------------------------------------------------------------------------------------" >> $STATUSLOG
crontab -l >> $STATUSLOG
echo "--------------------------------------------------------------------------------------" >> $STATUSLOG
df -BM >> $STATUSLOG
echo "--------------------------------------------------------------------------------------" >> $STATUSLOG
uptime_limit=21
buildbot_state="idle"
buildbot_pid=$(cat $PIDFILE_BUILDBOT 2>/dev/null)
if [ -n "$buildbot_pid" ]; then
if ps -p $buildbot_pid >/dev/null; then
uptime_limit=28
buildbot_state="active"
else
uptime_limit=0
buildbot_state="dead"
fi
echo "Buildbot instance ${buildbot_pid} is ${buildbot_state}." >> $STATUSLOG
echo "--------------------------------------------------------------------------------------" >> $STATUSLOG
fi
system_uptime_days=$(expr $(sed -e "s/\..*//" /proc/uptime) / 86400)
echo "System uptime: $system_uptime_days days, reboot after $uptime_limit days" >> $STATUSLOG
echo "--------------------------------------------------------------------------------------" >> $STATUSLOG
remove_source "gcc-linaro" "gcc-linaro-4.9-2016.02.tar.xz"
cat $STATUSLOG $LOGS/$REPONAME/rsync.$DATE.log | xz -z > $LOGS/$REPONAME/1-rsync.$DATE.log.xz
sendlogs
sendsnapshot
sendsnapshotlink
log "End of rsync"
# Reboot system periodically
if [ $system_uptime_days -gt $uptime_limit ]; then
sudo reboot
fi
rm -f $PIDFILE
exit 0