-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcheck_bckp.sh
More file actions
executable file
·172 lines (146 loc) · 4.51 KB
/
check_bckp.sh
File metadata and controls
executable file
·172 lines (146 loc) · 4.51 KB
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
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env bash
usage() {
cat << EOT >&2
Usage:
${0##*/} [-l] [-r] [-n NB] [-o MODEL1 -o MODEL2 ...] EXP
Check the backup of EVERY legs of one run, by listing
output and restart directories that are not empty.
Options are:
-b : [B]asic, ie check that the logs report success
-l : list non-empty [L]ocal dirs and their size
-r : list [R]emote dirs and number of file (or files themselves in case of restart tarballs and tm5 output)
-o model : limit to ouput from model. Can be several. Default is all possible.
-n LEG_NUMBER : leg [N]umber, for which the output/restart files are also listed (case of -r or -l)
EOT
}
set -e
. ./config.cfg
# -- options
omodels=
full=0
while getopts "vbrlo:n:h?" opt; do
case "$opt" in
h|\?)
usage
exit 0
;;
b) basic=1 ;;
l) local=1 ;;
o) omodels="$OPTARG $omodels" ;;
r) remote=1 ;;
n) full=$OPTARG ;;
v) verbose=1 ;;
esac
done
shift $((OPTIND-1))
# -- Arg
if [ "$#" -ne 1 ]; then
echo; echo " NEED ONE ARGUMENT, NO MORE, NO LESS!"; echo
usage
exit 0
fi
if [[ -z $omodels ]] # default to all models
then
omodels="ifs nemo tm5 oasis lpjg co2box pism_grtes"
#exit 0
fi
# -- Utils
not_empty_dir () {
[[ ! -d "$1" ]] && return 1
[ -n "$(ls -A $1)" ] && return 0 || return 1
}
# -- check
if (( basic ))
then
# Assumption about the log file specified when calling
# sbatch -o logfile backup_ece3.sh ...
# is
# log/$1-$(printf %03d $i).out
#
for log in log/$1-*.out
do
if [[ -f $log ]]
then
(( verbose )) && { echo; echo " -- Check $log --" ;
grep "ECMWF.*INFO.*ExitCode" $log ;
grep "ECMWF.*INFO.*State" $log ; }
excode=$(sed -nr "s|.*INFO.* ExitCode *: ||"p $log)
status=$(sed -nr "s|.*INFO.*State *: ||"p $log)
second=$(sed -nr "s|.*INFO.* ElapsedRaw *: ||"p $log)
if [[ $excode = '0:0' && $status = COMPLETED ]]; then
(( verbose )) && echo "Looks like it went ok."
echo -n "$log - Runtime (hh:mm:ss): "
echo $second | awk '{printf "%d:%02d:%02d\n", $1/3600, ($1/60)%60, $1%60}'
else
echo "$log - Still running (I guess)"
fi
else
echo "submit script log not found: $log"
fi
done
fi
if (( local ))
then
for model in $omodels
do
for ff in output restart
do
if [ -d ${runs_dir}/$1/${ff}/${model} ]
then
echo ; echo "*II* checking ${model} ${ff} [dir_size leg_nb]" ; echo
cd ${runs_dir}/$1/${ff}/${model}
#quick-but-not-rigourous: du -sh * | grep -v "^4.0K"
for ddd in *
do
if not_empty_dir $ddd
then
du -sh $ddd
(( $full )) && [[ $(printf %03d $full) == $ddd ]] && \
ls ${runs_dir}/$1/${ff}/${model}/$(printf %03d $full)
fi
done
fi
done
done
fi
if (( remote ))
then
# echo ; echo "*II* checking REMOTE top dir" ; echo
# els -l $ecfs_dir/$1
# -- Output
for model in ${omodels//tm5}
do
[[ $model == oasis ]] && continue
for ff in output
do
echo ; echo "*II* checking REMOTE ${model} ${ff} [leg_nb/ nb_files]" ; echo
#els -l $ecfs_dir/$1/${ff}/${model}
for ddd in $(els $ecfs_dir/$1/${ff}/${model})
do
if (( $full )) && [[ $(printf %03d/ $full) = $ddd ]]
then
echo $ddd
els -l $ecfs_dir/$1/${ff}/${model}/$ddd
else
echo $ddd $(els $ecfs_dir/$1/${ff}/${model}/$ddd | wc -w)
fi
done
done
done
if [[ $omodels =~ tm5 ]]
then
echo ; echo "*II* checking REMOTE tm5 output" ; echo
els -l $ecfs_dir/$1/output.tm5.*.tar*
fi
# -- Restart
for model in ${omodels//tm5}
do
echo ; echo "*II* checking REMOTE RESTART for ${model}" ; echo
els -l $ecfs_dir/$1/restart.${model}.*.tar || :
done
if [[ $omodels =~ tm5 ]]
then
echo ; echo "*II* checking REMOTE RESTART for tm5" ; echo
els -l $ecfs_dir/$1/tm5-restart-*.tar
fi
fi