1 | #!/bin/bash |
---|
2 | |
---|
3 | #on veut archiver les fichiers Debug. |
---|
4 | #Ils seront tous regroupes dans un repertoire DEBUG commun |
---|
5 | # on les renommes (repertoire DEBUG) de la meme maniere que les fichiers restart |
---|
6 | # puis on les archive via tar par periode |
---|
7 | #Creation des listes dans un repertoire debug_tar |
---|
8 | |
---|
9 | config_card=${1} |
---|
10 | LISTE_DMNFS=${2} |
---|
11 | |
---|
12 | |
---|
13 | export JOB_DIR=${JOB_DIR:-${TMP_MIGR_DATA}} |
---|
14 | export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM} |
---|
15 | export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp} |
---|
16 | mkdir -p ${IGCM_DEM} |
---|
17 | mkdir -p ${IGCM_TMP} |
---|
18 | clean_tmp=${clean_tmp:-yes} |
---|
19 | EXE_DIR=$(dirname ${0}) |
---|
20 | SCRIPT_NAME=$(basename ${0} ) |
---|
21 | |
---|
22 | source ${EXE_DIR}/DEM_utilities.sh |
---|
23 | |
---|
24 | # gpdebug : verif si le present script a ete execute jusqu'au bout ######### |
---|
25 | MonitoringInfo="${SCRIPT_NAME}-->OK" |
---|
26 | simuMonitoring_check "$MonitoringInfo" "$config_card" |
---|
27 | |
---|
28 | DEM_log -0 "Demarrage de ${SCRIPT_NAME}" |
---|
29 | |
---|
30 | #### 0- lecture de config.card |
---|
31 | #### on veut les renseignements suivants : |
---|
32 | #### JobName, PATH_SIMUL, DateBegin et DateEnd |
---|
33 | eval $(grep JobName ${config_card}) |
---|
34 | eval $(grep PATH_SIMUL_FULL ${config_card}) |
---|
35 | eval $(grep DateBegin ${config_card}) |
---|
36 | eval $(grep DateEnd ${config_card}) |
---|
37 | eval $(grep IGCM_DEM_SIMU ${config_card}) |
---|
38 | |
---|
39 | |
---|
40 | #### Preparation de l'environnement |
---|
41 | # repertoire dans lequel seront renommes les fichiers de debug |
---|
42 | STORE_DEBUG=$IGCM_DEM_SIMU/DEBUG |
---|
43 | mkdir -p ${STORE_DEBUG} |
---|
44 | |
---|
45 | # repertoire dans lequel nous stockerons les listes de debug a archiver |
---|
46 | DEBUG_TAR=$IGCM_DEM_SIMU/debug_tar |
---|
47 | mkdir -p ${DEBUG_TAR} |
---|
48 | STORE_CP=$IGCM_DEM_SIMU/store_cp |
---|
49 | mkdir -p ${STORE_CP} |
---|
50 | |
---|
51 | # lecture de periodpack dans ${IGCM_DEM_SIMU}/period_pack.txt |
---|
52 | period_pack=`awk '{print $0} ' ${IGCM_DEM_SIMU}/period_pack.txt` |
---|
53 | |
---|
54 | #### 1- renommer les fichiers ###### |
---|
55 | DEM_log -1 "Renommer les fichiers de Debug" |
---|
56 | |
---|
57 | cd ${STORE_DEBUG} |
---|
58 | if [ "x${STORE_DEBUG}" != "x" ] |
---|
59 | then |
---|
60 | rm -rf * |
---|
61 | fi |
---|
62 | |
---|
63 | # On copie les fichiers de Debug sur le scratchdir en changeant le nom et conservant la date |
---|
64 | grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep DEBUG | grep "f "| awk '{print $3}' | grep -e '.*/DEBUG/.*\..*' | sort >> ${IGCM_TMP}/${$}.liste_debug_files.txt |
---|
65 | grep -w "tar" ${IGCM_TMP}/${$}.liste_debug_files.txt > ${IGCM_DEM_SIMU}/liste_debug_files_config.txt |
---|
66 | |
---|
67 | # On les copie sur le scratchdir en changeant le nom et conservant la date |
---|
68 | for archive in `awk '{print $0}' ${IGCM_DEM_SIMU}/liste_debug_files_config.txt`; do |
---|
69 | ccc_hsm get $archive |
---|
70 | tar tf $archive >> ${IGCM_TMP}/${$}.new_liste_debug_files.txt |
---|
71 | tar xf $archive |
---|
72 | done |
---|
73 | |
---|
74 | # Test si il y a un repertoire Debug |
---|
75 | listDebugNbLines=`cat ${IGCM_TMP}/${$}.new_liste_debug_files.txt | wc -l ` |
---|
76 | if [ "x${listDebugNbLines}" == "x0" ] |
---|
77 | then |
---|
78 | DEM_log -0 "Pas de repertoire Debug pour cette simulation" |
---|
79 | else |
---|
80 | |
---|
81 | |
---|
82 | sort ${IGCM_TMP}/${$}.new_liste_debug_files.txt > ${IGCM_TMP}/${$}.order_new_liste_debug_files.txt |
---|
83 | ref=`awk -F_ '{if (NR==1) print $1}' ${IGCM_TMP}/${$}.order_new_liste_debug_files.txt` |
---|
84 | |
---|
85 | |
---|
86 | |
---|
87 | i=1 |
---|
88 | for new_file in `awk '{print $0}' ${IGCM_TMP}/${$}.order_new_liste_debug_files.txt`; do |
---|
89 | new_ref=$( echo ${new_file} | sed -e "s/_.*//") |
---|
90 | |
---|
91 | if [ ${new_ref} == ${ref} ]; then |
---|
92 | echo ${new_file} >> ${IGCM_TMP}/${$}.debug_list_${i}.txt |
---|
93 | else |
---|
94 | ref=${new_ref} |
---|
95 | (( i = $i + 1 )) |
---|
96 | echo ${new_file} >> ${IGCM_TMP}/${$}.debug_list_${i}.txt |
---|
97 | fi |
---|
98 | done |
---|
99 | |
---|
100 | j=1 |
---|
101 | while [[ $j -le $i ]]; do |
---|
102 | |
---|
103 | |
---|
104 | ### 2- creer les listes de fichiers par periode #### |
---|
105 | DEM_log -1 "Creation des listes de fichiers par periode" |
---|
106 | ### 2.1- extraire l'annee et le mois de DateBegin ### |
---|
107 | date_begin=${DateBegin} |
---|
108 | date_end=${DateEnd} |
---|
109 | |
---|
110 | year_begin=$(echo ${date_begin} | cut -c 1-4 ) |
---|
111 | month_begin=$(echo ${date_begin} | cut -c 5-6 ) |
---|
112 | year_end=$(echo ${date_end} | cut -c 1-4 ) |
---|
113 | month_end=$(echo ${date_end} | cut -c 5-6 ) |
---|
114 | |
---|
115 | |
---|
116 | ### 2.2- creation des listes ### |
---|
117 | date_begin_pack=${date_begin} |
---|
118 | date_end_simulation=${date_end} |
---|
119 | |
---|
120 | month_begin_pack=${month_begin} |
---|
121 | year_begin_pack=${year_begin} |
---|
122 | |
---|
123 | number_pack=1 |
---|
124 | |
---|
125 | while [ ${date_begin_pack} -le ${date_end_simulation} ] |
---|
126 | do |
---|
127 | |
---|
128 | DEM_log -1 "On calcule la date de fin du pack " |
---|
129 | month_end_pack=${month_begin_pack} |
---|
130 | year_end_pack=`expr ${year_begin_pack} + ${period_pack}` |
---|
131 | |
---|
132 | date_end_pack=${year_end_pack}${month_end_pack}01 |
---|
133 | for file in `awk '{print $1}' ${IGCM_TMP}/${$}.debug_list_${j}.txt`; do |
---|
134 | extract_date_file=`echo ${file} | sed -e "s/.*\${JobName}_//"` |
---|
135 | date_file=`echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g'` |
---|
136 | if [[ "x${date_file}" != "x" && ! -n ${date_file//[0-9]/} ]]; then |
---|
137 | if [ ${date_file} -lt ${date_end_pack} ] |
---|
138 | then |
---|
139 | if [ ${date_file} -ge ${date_begin_pack} ] |
---|
140 | then |
---|
141 | echo ${file} >> ${IGCM_TMP}/${$}.liste_pack_debug_${number_pack}.txt |
---|
142 | grep -v ${file} ${IGCM_TMP}/${$}.debug_list_${j}.txt > ${IGCM_TMP}/${$}.debug_list_${j}.txt.tmp |
---|
143 | mv ${IGCM_TMP}/${$}.debug_list_${j}.txt.tmp ${IGCM_TMP}/${$}.debug_list_${j}.txt |
---|
144 | |
---|
145 | fi |
---|
146 | fi |
---|
147 | fi |
---|
148 | if [ ${date_file} -gt ${date_end_pack} ] |
---|
149 | then |
---|
150 | break |
---|
151 | fi |
---|
152 | |
---|
153 | done |
---|
154 | month_begin_pack=${month_end_pack} |
---|
155 | year_begin_pack=${year_end_pack} |
---|
156 | |
---|
157 | date_begin_pack=${year_begin_pack}${month_begin_pack}01 |
---|
158 | |
---|
159 | number_pack=`expr ${number_pack} + 1` |
---|
160 | done |
---|
161 | |
---|
162 | ((j = $j + 1 )) |
---|
163 | done |
---|
164 | |
---|
165 | compt_pack=1 |
---|
166 | while [[ $compt_pack -le $number_pack ]]; do |
---|
167 | |
---|
168 | #on archive les debug - le nom de l'archive contiendra ${yearbegin}${monthbegin}_${yearend}${monthend} |
---|
169 | # end etant la date du dernier fichier contenu et non pas la premiere date suivant |
---|
170 | DEM_log -1 "Recherche de la date de fin reel pour nommer l'archive " |
---|
171 | #On classe par ordre alphabetique les fichiers contenus dans liste_pack_debug |
---|
172 | #la date du dernier fichier donnera la date de fin du pack |
---|
173 | if [[ -f ${IGCM_TMP}/${$}.liste_pack_debug_${compt_pack}.txt ]] ; then |
---|
174 | sort ${IGCM_TMP}/${$}.liste_pack_debug_${compt_pack}.txt > ${IGCM_TMP}/${$}.liste_pack_debug_${compt_pack}.txt.tmp |
---|
175 | |
---|
176 | first_file=$(head -n 1 ${IGCM_TMP}/${$}.liste_pack_debug_${compt_pack}.txt.tmp ) |
---|
177 | extract_date_file=$( echo ${first_file} | sed -e "s/.*${JobName}_//" ) |
---|
178 | DateBegin_Debug=$(echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g' ) |
---|
179 | |
---|
180 | last_file=$(tail -n 1 ${IGCM_TMP}/${$}.liste_pack_debug_${compt_pack}.txt.tmp ) |
---|
181 | extract_date_file=$( echo ${last_file} | sed -e "s/.*${JobName}_//" ) |
---|
182 | DateEnd_Debug=$( echo ${extract_date_file}| sed 's%.*\([0-9]\{8\}\)_.*$%\1%g' ) |
---|
183 | mv ${IGCM_TMP}/${$}.liste_pack_debug_${compt_pack}.txt.tmp ${DEBUG_TAR}/${JobName}_debug_${DateBegin_Debug}_${DateEnd_Debug}.list |
---|
184 | fi |
---|
185 | |
---|
186 | |
---|
187 | |
---|
188 | DEM_log -1 "On definit le datebegin de la prochaine periode pack" |
---|
189 | #on definit la periode pack suivante |
---|
190 | |
---|
191 | compt_pack=`expr ${compt_pack} + 1` |
---|
192 | done |
---|
193 | |
---|
194 | fi |
---|
195 | |
---|
196 | cd ${EXE_DIR} |
---|
197 | |
---|
198 | # gpdebug : le script n a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi |
---|
199 | simuMonitoring_OK "$MonitoringInfo" "$config_card" |
---|