forked from amereghe/SixDesk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecall_workspace
executable file
·665 lines (572 loc) · 15.4 KB
/
recall_workspace
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
#!/bin/sh
#
# Recalls a workspace.
# Requires the backup name as $1
# Must be run in .. of sixjobs
# May be a new different workspace........
castorr()
{
#MACRO mymess 0 Recalling $cin
sixdeskmesslevel=0
sixdeskmess="Recalling $cin"
sixdeskmess
#MACRO mymess
castor_recall $cin $cout >> $sixdeskhome/../castor_recall.log 2>&1
if test $? -ne 0
then
if test "$nomessages" = ""
then
#MACRO mymess 0 castor_recall failed!! See castor_recall.log.
sixdeskmesslevel=0
sixdeskmess="castor_recall failed!! See castor_recall.log."
sixdeskmess
#MACRO mymess
myexit99
else
echo "castor_recall failed!! See castor_recall.log."
exit 99
fi
fi
}
check_dir()
{
if test ! -d $LHCDescrip
then
#MACRO mymess 0 Recall of $LHCDescrip in $mystudy has failed!!!
sixdeskmesslevel=0
sixdeskmess="Recall of $LHCDescrip in $mystudy has failed!!!"
sixdeskmess
#MACRO mymess
#MACRO mymess 0 See castor_recall.log and inform [email protected].
sixdeskmesslevel=0
sixdeskmess="See castor_recall.log and inform [email protected]."
sixdeskmess
#MACRO mymess
#MACRO myexit 98
sixdeskexitparam=98
sixdeskexit
#MACRO myexit
fi
}
# We have no sixjobs possibly so set nomessages
nomessages="true"
# This should always be defined
if test "$CASTOR_HOME" = ""
then
echo "The variable CASTOR_HOME is undefined!!!"
echo "Do you have a CASTOR account?"
exit 1
fi
# The backup must be specified
if test $# -eq 0
then
echo "You must specify the backup name in workspace_backups"
echo "(Just do an nsls workspace_backups for a list.)"
exit 2
fi
bname=$1
cname=$CASTOR_HOME/workspace_backups
echo $bname | grep "%" > /dev/null 2>&1
if test $? -ne 0
then
echo "The backup name does not have a '%'...!!!"
exit 3
fi
nsls workspace_backups/$bname > /dev/null 2>&1
if test $? -ne 0
then
echo "Specified backup file can not be found!"
echo "'nsls workspace_backups' will list all existing CASTOR backups"
exit 4
fi
bworkspace=`echo $bname | cut -d"%" -f 1`
bdate=`echo $bname | cut -d"%" -f 2`
# and where are we
currentws=`basename $PWD`
if test "$currentws" = "sixjobs"
then
echo "recall_workspace must be in run in the workspace, the .. of sixjobs!!!"
exit 5
fi
if test ! -h ~/$currentws
then
echo "Link in $HOME to $currentws does not exist!!!"
exit 6
fi
# and set up to use sixdesklogdir in sixjobs/..
sixdesklogdir="."
touch sixdesk.log
touch castor_recall.log
if test ! -s recall_workspace.list
then
# We are starting a new recall
# So first get sixjobs (c.f. recall_study)
if test -d sixjobs
then
echo "There is an existing sixjobs directory!!!"
echo "There is an existing sixjobs directory!!!" >> sixdesk.log
echo "Please remove everything or use an empty workspace."
exit 95
fi
# Might be the same or different
echo "Recalling sixjobs for $bworkspace to $currentws"
echo "Recalling sixjobs for $bworkspace to $currentws" >> sixdesk.log
cin=$cname/$bname/sixjobs
cout=.
castor_recall $cin $cout >> castor_recall.log 2>&1
if test $? -ne 0
then
echo "castor_recall failed!! See castor_recall.log."
echo "castor_recall failed!! See castor_recall.log." >> sixdesk.log
exit 97
fi
if test -d "sixjobs"
then
echo "sixjobs recalled successfully."
echo "sixjobs recalled successfully." >> sixdesk.log
else
echo "Problem with recall of sixjobs!!!"
echo "Problem with recall of sixjobs!!!" >> sixdesk.log
echo "Please check the castor_recall.log"
exit 96
fi
# List of all studies to recall
if test ! -d sixjobs/studies
then
echo "There is no sixjobs/studies directory!!!"
echo "There is no sixjobs/studies directory!!!" >> sixdesk.log
echo "Please check the castor_recall.log"
exit 7
fi
cd sixjobs
# First are we recalling to a different workspace or not........
if test "$bworkspace" != "$currentws"
then
# and now edit all the studies/study/sixdeskenv and ./sixdeskenv
# to reflect the new workspace
sed -e 's/\( *export *workspace=\).*/\1'$currentws'/' sixdeskenv > tmp$$
if test $? -ne 0
then
echo "Problem editing sixdeskenv!!!"
exit 8
fi
mv tmp$$ sixdeskenv
rm -f tmp$$ tmp2$$
ls -tr studies > tmp$$
while read myitem
do
if test -d studies/"$myitem"
then
echo "$myitem" >> tmp2$$
fi
done < tmp$$
rm tmp$$
while read mynewstudy
do
sed -e 's/\( *export *workspace=\).*/\1'$currentws'/' studies/$mynewstudy/sixdeskenv > tmp$$
if test $? -ne 0
then
echo "Problem editing sixdeskenv for study $mynewstudy !!!"
exit 8
fi
mv tmp$$ studies/$mynewstudy/sixdeskenv
# Remove (if they exist) CPSS TaskGroupId/ProgramId no longer valid
# as they are for the old workspace
rm -f studies/$mynewstudy/ProgramId
rm -f studies/$mynewstudy/TaskGroupId
done < tmp2$$
rm tmp2$$
fi
# and back to .. of sixjobs
cd ..
# and setup for restart
rm -f recall_workspace.finished
touch recall_workspace.finished
# and list only directories (not e.g. sixdesklock!)
rm -f tmp$$ tmp2$$
ls -tr sixjobs/studies > tmp$$
while read myitem
do
if test -d sixjobs/studies/"$myitem"
then
echo "$myitem" >> tmp2$$
fi
done < tmp$$
rm tmp$$
# and a final move (done this way in case we are interrupted CNTRLC)
mv tmp2$$ recall_workspace.list
echo "The following studies will be recalled"
cat recall_workspace.list
else
# We are restarting an existing recall (sixjobs has been done)
echo "Restarting recall of studies in $bworkspace to $currentws"
# and touch recall_workspace.finished in case I deleted it by hand
touch recall_workspace.finished
fi
# Get the subroutines (we have never done a dot_env)
if test ! -s ./sixjobs/dot_profile
then
echo "dot_profile is missing!!!"
exit 1
fi
. ./sixjobs/dot_profile
# and set some defaults
nomessages=""
export sixdesklevel=1
export sixdeskecho="yes!"
# A bit late, but we will lock .. now
# sixjobs was already locked by the backup!!
#MACRO mylock
sixdesklockdir=
sixdesklock
#MACRO mylock
if test "$bworkspace" != "$currentws"
then
cout="."
else
cout=""
fi
# and now we can process the list of studies
#MACRO mymess 0 Recalling the following studies
sixdeskmesslevel=0
sixdeskmess="Recalling the following studies"
sixdeskmess
#MACRO mymess
myss=""
while read mystudy
do
myss="$myss $mystudy"
done < recall_workspace.list
#MACRO mymess 0 $myss
sixdeskmesslevel=0
sixdeskmess="$myss"
sixdeskmess
#MACRO mymess
while read mystudy
do
grep '^'$mystudy'$' recall_workspace.finished > /dev/null
if test $? -eq 0
then
#MACRO mymess 0 Skipping recall of $mystudy as it is already complete
sixdeskmesslevel=0
sixdeskmess="Skipping recall of $mystudy as it is already complete"
sixdeskmess
#MACRO mymess
else
# but switch to sixjobs now
cd sixjobs
sixdesklogdir=".."
# we have not finished this case so [re-]start it
# For each study, we do logs, sixtrack_input, track, and work.
# we don't LOCK the workspace as it was locked for the backup........
# and set mystudy/myworkspace for messages
# Now switch to this study
# but first NULLIFY the key variables
#MACRO mymess 0 Now recalling study $mystudy
sixdeskmesslevel=0
sixdeskmess="Now recalling study $mystudy"
sixdeskmess
#MACRO mymess
export sixdesktrack=""
export sixtrack_input=""
export sixdeskwork=""
if test ! -e ./studies/$mystudy/sixdeskenv -o ! -e ./studies/$mystudy/sysenv
then
#MACRO mymess 0 The sixdeskenv/sysenv files for $mystudy are missing!!!
sixdeskmesslevel=0
sixdeskmess="The sixdeskenv/sysenv files for $mystudy are missing!!!"
sixdeskmess
#MACRO mymess
#MACRO myunlock
sixdesklockdir=
sixdeskunlock
#MACRO myunlock
#MACRO myunlock ..
sixdesklockdir=..
sixdeskunlock
#MACRO myunlock
#MACRO myexit 5
sixdeskexitparam=5
sixdeskexit
#MACRO myexit
fi
. ./studies/$mystudy/sixdeskenv
. ./studies/$mystudy/sysenv
mysixdesklogdir="$sixdesklogdir"
sixdesklogdir=".."
if test "$workspace" != "$currentws"
then
# I already edited the sixdeskenv files
#MACRO mymess 0 BUG! The sixdeskenv workspace $workspace is different to $currentws !!!
sixdeskmesslevel=0
sixdeskmess="BUG! The sixdeskenv workspace $workspace is different to $currentws !!!"
sixdeskmess
#MACRO mymess
#MACRO myunlock
sixdesklockdir=
sixdeskunlock
#MACRO myunlock
#MACRO myunlock ..
sixdesklockdir=..
sixdeskunlock
#MACRO myunlock
#MACRO myexit 15
sixdeskexitparam=15
sixdeskexit
#MACRO myexit
fi
myworkspace=$currentws
if test "$mystudy" != "$LHCDescrip"
then
#MACRO mymess 0 Bug!!! The sixdeskenv LHCDescrip $LHCDescrip is different to mystudy $mystudy !!!
sixdeskmesslevel=0
sixdeskmess="Bug!!! The sixdeskenv LHCDescrip $LHCDescrip is different to mystudy $mystudy !!!"
sixdeskmess
#MACRO mymess
#MACRO myunlock
sixdesklockdir=
sixdeskunlock
#MACRO myunlock
#MACRO myunlock ..
sixdesklockdir=..
sixdeskunlock
#MACRO myunlock
#MACRO myexit 16
sixdeskexitparam=16
sixdeskexit
#MACRO myexit
fi
# and make a logdir to
if test "$mysixdesklogdir" != ""
then
mkdir -p $mysixdesklogdir
fi
#MACRO mymess 0 Recalling Study $mystudy from $bworkspace to $myworkspace at `date +%d%m%y`/`date +%T`
sixdeskmesslevel=0
sixdeskmess="Recalling Study $mystudy from $bworkspace to $myworkspace at `date +%d%m%y`/`date +%T`"
sixdeskmess
#MACRO mymess
# We do logs, sixtrack_input, track, and work.
for nextd in logs cronlogs sixtrack_input track work
do
#MACRO mymess 0 Recalling $nextd at `date +%d%m%y`/`date +%T`
sixdeskmesslevel=0
sixdeskmess="Recalling $nextd at `date +%d%m%y`/`date +%T`"
sixdeskmess
#MACRO mymess
if test "$nextd" = "logs"
then
nsls $cname/$bname/logs/$LHCDescrip.1.tar > /dev/null 2>&1
if test $? -eq 0 -a "$mysixdesklogdir" != ""
then
#MACRO mymess 0 Recalling logs
sixdeskmesslevel=0
sixdeskmess="Recalling logs"
sixdeskmess
#MACRO mymess
cin=$cname/$bname/logs/$LHCDescrip
cd $mysixdesklogdir
cd ..
if test "$cout" != ""
then
rm -rf $LHCDescrip
fi
castorr
check_dir
cd $sixdeskhome
else
#MACRO mymess 0 Skipping logs.
sixdeskmesslevel=0
sixdeskmess="Skipping logs."
sixdeskmess
#MACRO mymess
fi
elif test "$nextd" = "cronlogs"
then
nsls $cname/$bname/cronlogs/$LHCDescrip.1.tar > /dev/null 2>&1
if test $? -eq 0 -a "$cronlogdir" != ""
then
#MACRO mymess 0 Recalling cronlogs
sixdeskmesslevel=0
sixdeskmess="Recalling cronlogs"
sixdeskmess
#MACRO mymess
mkdir -p $cronlogdir
cd $cronlogdir
cd ..
cin=$cname/$bname/cronlogs/$LHCDescrip
if test "$cout" != ""
then
rm -rf $LHCDescrip
fi
castorr
check_dir
cd $sixdeskhome
else
#MACRO mymess 0 Skipping cronlogs
sixdeskmesslevel=0
sixdeskmess="Skipping cronlogs"
sixdeskmess
#MACRO mymess
fi
elif test "$nextd" = "track"
then
nsls $cname/$bname/track/$LHCDescrip.1.tar > /dev/null
if test $? -eq 0
then
#MACRO mymess 0 Recalling track
sixdeskmesslevel=0
sixdeskmess="Recalling track"
sixdeskmess
#MACRO mymess
mkdir -p $sixdesktrack/$LHCDescrip
cd $sixdesktrack/$LHCDescrip
cd ..
cin=$cname/$bname/track/$LHCDescrip
if test "$cout" != ""
then
rm -rf $LHCDescrip
fi
castorr
check_dir
cd $sixdeskhome
else
#MACRO mymess 0 Skipping track
sixdeskmesslevel=0
sixdeskmess="Skipping track"
sixdeskmess
#MACRO mymess
fi
elif test "$nextd" = "sixtrack_input"
then
nsls $cname/$bname/sixtrack_input/$LHCDescrip.1.tar > /dev/null 2>&1
if test $? -eq 0
then
#MACRO mymess 0 Recalling sixtrack_input
sixdeskmesslevel=0
sixdeskmess="Recalling sixtrack_input"
sixdeskmess
#MACRO mymess
mkdir -p $sixtrack_input
cd $sixtrack_input
cd ..
cin=$cname/$bname/sixtrack_input/$LHCDescrip
if test "$cout" != ""
then
rm -rf $LHCDescrip
fi
castorr
check_dir
cd $sixdeskhome
else
#MACRO mymess 0 Skipping sixtrack_input
sixdeskmesslevel=0
sixdeskmess="Skipping sixtrack_input"
sixdeskmess
#MACRO mymess
fi
elif test "$nextd" = "work"
then
nsls $cname/$bname/work/$LHCDescrip.1.tar > /dev/null 2>&1
if test $? -eq 0
then
#MACRO mymess 0 Recalling work
sixdeskmesslevel=0
sixdeskmess="Recalling work"
sixdeskmess
#MACRO mymess
mkdir -p $sixdeskwork
cd $sixdeskwork
cd ..
cin=$cname/$bname/work/$LHCDescrip
if test "$cout" != ""
then
rm -rf $LHCDescrip
fi
castorr
check_dir
cd $sixdeskhome
else
#MACRO mymess 0 Skipping work
sixdeskmesslevel=0
sixdeskmess="Skipping work"
sixdeskmess
#MACRO mymess
fi
else
#MACRO mymess 0 BUG!!! Trying to recall unknown data!!!
sixdeskmesslevel=0
sixdeskmess="BUG!!! Trying to recall unknown data!!!"
sixdeskmess
#MACRO mymess
#MACRO myunlock
sixdesklockdir=
sixdeskunlock
#MACRO myunlock
#MACRO myunlock ..
sixdesklockdir=..
sixdeskunlock
#MACRO myunlock
#MACRO myexit 99
sixdeskexitparam=99
sixdeskexit
#MACRO myexit
fi
done
# Should be in sixjobs....
cd $sixdeskhome
# and finally?! update the fort.2|8|16 links in the track tree
if test "$bworkspace" != "$currentws"
then
#MACRO mymess 0 Updating the input links fort.2|8|16
sixdeskmesslevel=0
sixdeskmess="Updating the input links fort.2|8|16"
sixdeskmess
#MACRO mymess
while read aline
do
Runnam=`echo $aline | cut -d " " -f1`
#MACRO myrundir $Runnam Rundir
runnamename=$Runnam
sixdeskrundir
Rundir=$rundirname
#MACRO myrundir
where=$sixdesktrack/$Rundir
seed=`echo $Runnam | cut -d% -f2`
cd $where
ln -sf $sixtrack_input/fort.2_${seed}.gz fort.2.gz
ln -sf $sixtrack_input/fort.8_${seed}.gz fort.8.gz
ln -sf $sixtrack_input/fort.16_${seed}.gz fort.16.gz
cd $sixdeskhome
done < $sixdeskwork/taskids
fi
cd ..
sixdesklogdir="."
rm -f $sixdeskstudy/deleted
echo "$mystudy" >> recall_workspace.finished
#MACRO mymess 0 Recall of $mystudy finished at `date +%d%m%y` `date +%T`
sixdeskmesslevel=0
sixdeskmess="Recall of $mystudy finished at `date +%d%m%y` `date +%T`"
sixdeskmess
#MACRO mymess
fi
done < recall_workspace.list
rm recall_workspace.finished
rm recall_workspace.list
#MACRO myunlock sixjobs
sixdesklockdir=sixjobs
sixdeskunlock
#MACRO myunlock
#MACRO myunlock
sixdesklockdir=
sixdeskunlock
#MACRO myunlock
#MACRO mymess 0 Recall of $bworkspace to $myworkspace finished
sixdeskmesslevel=0
sixdeskmess="Recall of $bworkspace to $myworkspace finished"
sixdeskmess
#MACRO mymess
#MACRO myexit 0
sixdeskexitparam=0
sixdeskexit
#MACRO myexit