-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathows-archive
executable file
·161 lines (137 loc) · 3.63 KB
/
ows-archive
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
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
#set -x
#################### Config Variables ########################
DEFAULTS=${DEFAULTS:-"/etc/default/ows"}
if [ -x "$DEFAULTS" ]; then
echo "OWS not fully configured. Check $DEFAULTS"
exit 0
fi
# Read configuration variable file if it is present
[ -r $DEFAULTS ] && . $DEFAULTS
######################################################################
function cleanup() {
echo "you hit Ctrl-C/Ctrl-\, now exiting..";
echo "Kill all subprocesses"
[[ -z "$(jobs -pr)" ]] || kill $(jobs -pr);
exit
}
trap 'cleanup' SIGINT SIGQUIT
function archive {
local age=$(date --date="-$1 days" '+%s')
local dir=$2
cd $dir
for i in $dir/*; do
d=$(basename $i)
if [[ $d == 20* ]]; then
date=$(date --date "$d" '+%s')
if [ $? = 0 ]; then
if [ $date -le $age ]; then
echo "Create Archive archive/$d.tgz"
GZIP='--rsyncable' tar zcf archive/$d.tgz $i
rm -Rf $i
fi
fi
fi
done
lastday=$(ls -d1 ????-??-?? | sort -r | head -1)
if [ -d ${REPORTDIR}/$lastday ]; then
if [ -f ${REPORTDIR}/$lastday/commits ]; then
lastcommit=$(cat ${REPORTDIR}/$lastday/commits | head -1)
if [ -f $lastday/$lastcommit/index.html ]; then
echo "Update Latest sym link $lastday/$lastcommit"
if [ -d $lastday/$lastcommit ]; then
rm -Rf latest
mkdir -p latest
ln -s ../$lastday/$lastcommit latest/today
else
echo "$lastday/$lastcommit does not exists. OWS could be outdated"
fi
else
echo "$lastday/$lastcommit/index.html does not exists. OWS could be outdated"
fi
else
echo "${REPORTDIR}/$lastday/commits does not exists. OWS could be outdated"
fi
else
echo "Nothing new. Carry On"
fi
if [ ! -e latest/today ]; then
echo "Symlink BROKEN. SITE DOWN"
fi
}
function archive-reports {
local age=$(date --date="-$1 days" '+%s')
local dir=$2
cd $dir
mkdir -p $dir/archive
for i in $dir/*; do
d=$(basename $i)
if [[ $d == 20* ]]; then
date=$(date --date "$d" '+%s')
if [ $? = 0 ]; then
if [ $date -le $age ]; then
echo "Create Archive archive/$d.tgz"
GZIP='--rsyncable' tar zcf archive/$d.tgz $i
rm -Rf $i
fi
fi
fi
done
}
# Usage info
show_help() {
cat << EOF
Usage: ${0##*/} [-h] [-a AGE] [DIR]
Archive old ows reports
-h display this help and exit
-a AGE AGE is an integer expressing the age of ows
reports (default 11 days).
DIR is the directory containing the html ows reports.
EOF
}
age=""
verbose=0
OPTIND=1
while getopts "ha:" opt; do
case "$opt" in
h)
show_help
exit 0
;;
a)
age=$OPTARG
;;
'?')
show_help >&2
exit 1
;;
esac
done
shift "$((OPTIND-1))" # Shift off the options and optional --.
dir=${TARGETDIR}
age=${age:-"11"}
if [ -d $dir ]; then
mkdir -p $dir/archive
else
echo "$dir : Not such directory"
show_help >&2
exit 1
fi
if hash optipng 2>/dev/null ; then
if [ -d ${TARGETDIR}/$(date +%Y-%m-%d) ]; then
echo "PNG compression"
find ${TARGETDIR}/$(date +%Y-%m-%d) -name plot.png -exec optipng {} \;
fi
fi
if hash hardlink 2>/dev/null ; then
if [ pgrep "hardlink" 2> /dev/null ]; then
echo "Skip hardlink : already running"
else
echo "Remove duplicates file"
hardlink ${TARGETDIR}
fi
fi
echo "Archiving all reports older then $age days in $dir/archive"
archive $age $dir
archive-reports $age /srv/data/ows/reports
#rsync -avz html/ hazel.rocq.inria.fr:web/public_html/tmp/html/