source: TOOLS/SURPACK_IPSL/archive_debug.sh @ 2138

Last change on this file since 2138 was 2138, checked in by acosce, 11 years ago

fix a bug in archive_debug for surpack tool

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