ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/Processing/bin/fixFile.sh
Revision: 1.2
Committed: Fri Jan 18 22:55:24 2013 UTC (12 years, 3 months ago) by paus
Content type: application/x-sh
Branch: MAIN
CVS Tags: Mit_032, Mit_031, Mit_030, Mit_029c, Mit_030_pre1, Mit_029a, HEAD
Changes since 1.1: +21 -18 lines
Log Message:
Adjustments.

File Contents

# User Rev Content
1 paus 1.1 #!/bin/bash
2     #===================================================================================================
3     # Assume a local files is found to be broken. Go through a full recovery:
4     # + check they are really broken
5     # + check they are not broken on Tier-2
6     # + remove broken file from Tier-3 and download the proper one from Tier-2
7     # + in case also Tier-2 is broken check CERN and download even back to Tier-2
8     #===================================================================================================
9     MIT_LOC="/mnt/hadoop/cms/store/user/paus"
10     CERN_LOC="/castor/cern.ch/user/p/paus"
11    
12     FILE="$1"
13     FLAG="$2"
14    
15     fullFile="$FILE"
16     file=`basename $fullFile`
17     dir=`dirname $fullFile`
18     dset=`basename $dir`
19     tmp=`dirname $dir`
20     version=`basename $tmp`
21     tmp=`dirname $tmp`
22     cfg=`basename $tmp`
23    
24     test=`list $dir/$file 2> /dev/null`
25     if [ "$test" != "" ]
26     then
27     echo ""
28     echo " TEST - File exists, check integrity."
29     echo " $dir/$file"
30     test=`catalogFile.sh $dir $file 2> /dev/null | grep XX-CATALOG-XX`
31     if [ "$test" != "" ]
32     then
33     echo " STOP - File seems to be fine?! Leave it."
34     echo " $dir/$file"
35     echo ""
36     exit 0
37     else
38     echo " File is really broken. Remove it."
39 paus 1.2 remove --exe --catalog $dir/$file
40 paus 1.1 fi
41     else
42     echo ""
43     echo " TEST - File does not exist."
44     echo " $dir/$file"
45     fi
46    
47     # once we arrive here, the file is gone and we are recovering
48    
49     echo " Start recovery from Tier-2."
50     test=`catalogFile.sh $MIT_LOC/$cfg/$version/$dset $file 2> /dev/null | grep XX-CATALOG-XX`
51     if [ "$test" != "" ]
52     then
53     echo ""
54     echo " GOOD - File seems to be fine on Tier-2. Grab it."
55     #echo "downloadFile.sh $MIT_LOC/$cfg/$version/$dset/$file $dir/$file"
56     downloadFile.sh $MIT_LOC/$cfg/$version/$dset/$file $dir/$file >& /dev/null
57     echo " -> Download status: $?"
58     test=`catalogFile.sh $dir $file 2> /dev/null | grep XX-CATALOG-XX`
59     if [ "$test" != "" ]
60     then
61     echo ""
62     echo " GOOD - Recovery completed successfully."
63     echo " $dir/$file"
64     echo ""
65     else
66     echo " ERRO - File is broken again. Removing it."
67     echo " $dir/$file"
68     echo ""
69 paus 1.2 remove --exe --catalog $dir/$file
70 paus 1.1 fi
71     else
72     echo ""
73     echo " STOP - File seems to be broken on Tier-2."
74     # in case both Tier-2 and Tier-3 broken and requested removed both
75     if [ "$FLAG" == "remove" ]
76     then
77     remove --exe --catalog $dir/$file
78     remove --exe --catalog $MIT_LOC/$cfg/$version/$dset/$file
79     fi
80     echo " Start recovery from CERN."
81     test=`list $CERN_LOC/$cfg/$version/$dset/$file 2> /dev/null`
82     if [ "$test" != "" ]
83     then
84     echo ""
85     echo " GOOD - File seems to be available at CERN. Grab it."
86     downloadFile.sh $CERN_LOC/$cfg/$version/$dset/$file $dir/$file >& /dev/null
87     echo " -> Download status: $?"
88     test=`catalogFile.sh $dir $file 2> /dev/null | grep XX-CATALOG-XX`
89     if [ "$test" != "" ]
90     then
91     echo ""
92     echo " GOOD - Recovery completed successfully from CERN."
93     echo " $dir/$file"
94 paus 1.2 # try to recover Tier-2 from CERN if that is required
95     if [ "$MIT_LOC/$cfg/$version/$dset/$file" != "$dir/$file" ]
96 paus 1.1 then
97 paus 1.2 echo " Start recovery on Tier-2."
98     downloadFile.sh $CERN_LOC/$cfg/$version/$dset/$file $MIT_LOC/$cfg/$version/$dset/$file \
99     >& /dev/null
100     echo " -> Download (to Tier-2) status: $?"
101     test=`catalogFile.sh $MIT_LOC/$cfg/$version/$dset $file 2> /dev/null | grep XX-CATALOG-XX`
102     if [ "$test" != "" ]
103     then
104     echo ""
105     echo " GOOD - Recovery on Tier-2 completed successfully from CERN."
106     echo " $MIT_LOC/$cfg/$version/$dset/$file"
107     echo ""
108     else
109     echo " ERRO - File on tier-2 is still broken. Stop process"
110     echo " $MIT_LOC/$cfg/$version/$dset/$file"
111     echo ""
112     fi
113     fi
114 paus 1.1 else
115     echo " ERRO - File is broken again. Removing it."
116     echo " $dir/$file"
117     echo ""
118     rm -f $dir/$file
119     fi
120     else
121     echo ""
122     echo " STOP - File seems not to be available at CERN."
123     echo ""
124     fi
125     fi
126    
127     exit 0