source: TOOLS/PACK_IPSL/archive_debug.sh @ 1834

Last change on this file since 1834 was 1822, checked in by aclsce, 12 years ago

Modifications done by Guillaume P :

  • error handling for the whole script
  • check of nco version
  • restart tool for list script
  • progress visualization for both scripts
  • "force" option -f added for both scripts
  • timing information added for pack script
  • Property svn:executable set to *
File size: 6.0 KB
Line 
1#!/bin/bash
2
3
4#on veut archiver les fichiers Debug.
5#Ils seront tous regroupes dans un repertoire DEBUG commun 
6# on les renommes (repertoire DEBUG) de la meme maniere que les fichiers restart
7# puis on les archive via tar par periode
8#Creation des listes dans un repertoire debug_tar
9
10config_card=${1}
11LISTE_DMNFS=${2}
12
13
14export JOB_DIR=${JOB_DIR:-${PWD}}
15export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM}
16export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp}
17mkdir -p ${IGCM_DEM}
18mkdir -p ${IGCM_TMP}
19clean_tmp=${clean_tmp:-yes}
20EXE_DIR=$(dirname ${0})
21SCRIPT_NAME=$(basename ${0} )
22
23source ${EXE_DIR}/DEM_utilities.sh
24
25# gpdebug : verif si le present script a ete execute jusqu'au bout #########
26MonitoringInfo="${SCRIPT_NAME}-->OK"
27simuMonitoring_check "$MonitoringInfo" "$config_card"
28
29DEM_log -0 "Demarrage de ${SCRIPT_NAME}"
30
31
32#### 0- lecture de config.card
33#### on veut les renseignements suivants :
34#### JobName, PATH_SIMUL, DateBegin et DateEnd
35eval $(grep JobName ${config_card}) 
36eval $(grep PATH_SIMUL_FULL ${config_card}) 
37eval $(grep DateBegin ${config_card}) 
38eval $(grep DateEnd ${config_card}) 
39eval $(grep IGCM_DEM_SIMU ${config_card})
40
41
42#### Preparation de l'environnement
43# repertoire dans lequel seront renommes les fichiers de debug
44STORE_DEBUG=$IGCM_DEM_SIMU/DEBUG
45mkdir -p ${STORE_DEBUG}
46
47# repertoire dans lequel nous stockerons les listes de debug a archiver
48DEBUG_TAR=$IGCM_DEM_SIMU/debug_tar
49mkdir -p ${DEBUG_TAR}
50STORE_CP=$IGCM_DEM_SIMU/store_cp
51mkdir -p ${STORE_CP}
52
53# lecture de periodpack dans ${IGCM_DEM_SIMU}/period_pack.txt
54period_pack=`awk '{print $0} ' ${IGCM_DEM_SIMU}/period_pack.txt`
55
56#### 1- renommer les fichiers ######
57DEM_log -1 "Renommer les fichiers de Debug"
58
59cd ${STORE_DEBUG}
60rm -rf *
61
62# On copie les fichiers de Debug sur le scratchdir en changeant le nom et conservant la date
63grep ${PATH_SIMUL_FULL} ${LISTE_DMNFS} | grep Debug | awk '{print $3}' | sed '/^.*Debug$/d' >> ${IGCM_TMP}/${$}.liste_debug_files.txt
64
65# cas particulier : les fichiers Bands sont conserves sans etre archives
66grep ${JobName}_Bands ${IGCM_TMP}/${$}.liste_debug_files.txt >> ${STORE_CP}/cp_files.list
67sed "/${JobName}_Bands/d" ${IGCM_TMP}/${$}.liste_debug_files.txt > ${IGCM_TMP}/${$}.liste_debug_files.txt_tmp
68mv ${IGCM_TMP}/${$}.liste_debug_files.txt_tmp ${IGCM_TMP}/${$}.liste_debug_files.txt
69 
70gawk -F/ '{dest_name=$(NF-2)("_") $(NF); system("ln -s " $0 " "dest_name)}' ${IGCM_TMP}/${$}.liste_debug_files.txt
71
72#on fait de meme avec les fichiers out_gcm.e stockes dans le repertoire Out/ qui seront prefixes par Out_
73rm -f ${IGCM_TMP}/${$}.liste_debug_files.txt
74grep ${PATH_SIMUL_FULL} ${LISTE_DMNFS} | grep -w Out | awk '{print $3}' | sed '/^.*Out$/d' > ${IGCM_TMP}/${$}.liste_debug_files.txt
75gawk -F/ '{dest_name=$(NF-1)("_") $(NF); system("ln -s " $0 " "dest_name)}' ${IGCM_TMP}/${$}.liste_debug_files.txt
76
77
78ls -l ${STORE_DEBUG} > ${IGCM_TMP}/${$}.new_liste_debug_files.txt
79
80### 2- creer les listes de fichiers par periode ####
81DEM_log -1 "Creation des listes de fichiers par periode"
82### 2.1- extraire l'annee et le mois de DateBegin ###
83date_begin=${DateBegin}
84date_end=${DateEnd}
85
86year_begin=$(echo ${date_begin} | cut -c 1-4 )
87month_begin=$(echo ${date_begin} | cut -c 5-6 )
88year_end=$(echo ${date_end} | cut -c 1-4 )
89month_end=$(echo ${date_end} | cut -c 5-6 )
90
91
92### 2.2- creation des listes ###
93date_begin_pack=${date_begin}
94date_end_simulation=${date_end}
95
96month_begin_pack=${month_begin}
97year_begin_pack=${year_begin}
98
99number_pack=1
100
101while [ ${date_begin_pack} -le ${date_end_simulation} ]
102do
103
104DEM_log -1 "On calcule la date de fin du pack "
105
106   month_end_pack=${month_begin_pack}
107   year_end_pack=`expr ${year_begin_pack} + ${period_pack}`
108
109   if [ ${month_end_pack} -le 9 ]
110   then
111      date_end_pack=${year_end_pack}0${month_end_pack}01
112   fi
113   if [ ${month_end_pack} -gt 9 ]
114   then
115      date_end_pack=${year_end_pack}${month_end_pack}01   
116   fi
117
118 
119   for file in `awk '{print $9}' ${IGCM_TMP}/${$}.new_liste_debug_files.txt`; do
120   
121     extract_date_file=`echo ${file}  | sed -e "s/.*\${JobName}_//"`
122     date_file=`echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g'`
123
124
125     if [  ${date_file} -lt ${date_end_pack} ]
126     then
127        if [ ${date_file} -ge ${date_begin_pack} ]
128        then
129           echo ${file} >> ${IGCM_TMP}/${$}.liste_pack_debug_${number_pack}.txt
130        fi
131     fi
132   
133   done
134
135#on archive les debug - le nom de l'archive contiendra ${yearbegin}${monthbegin}_${yearend}${monthend} 
136# end etant la date du dernier fichier contenu et non pas la premiere date suivant
137DEM_log -1 "Recherche de la date de fin reel pour nommer l'archive "
138#On classe par ordre alphabetique les fichiers contenus dans liste_pack_debug
139#la date du dernier fichier donnera la date de fin du pack
140   sort ${IGCM_TMP}/${$}.liste_pack_debug_${number_pack}.txt > ${IGCM_TMP}/${$}.liste_pack_debug_${number_pack}.txt.tmp
141   last_file=$(tail -n 1 ${IGCM_TMP}/${$}.liste_pack_debug_${number_pack}.txt.tmp )
142   extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" )
143   DateEnd_Debug=$(   echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
144   mv ${IGCM_TMP}/${$}.liste_pack_debug_${number_pack}.txt.tmp ${DEBUG_TAR}/${JobName}_debug_${date_begin_pack}_${DateEnd_Debug}.list
145
146
147DEM_log -1 "Passage de la commande Tar pour archiver la liste creee"
148#   tar -cf ${JobName}_${date_begin_pack}_${DateEnd_Debug}_debug.tar --dereference  --files-from ${DEBUG_TAR}/tar_debug_${date_begin_pack}_${DateEnd_Debug}.list
149#   cat  ${DEBUG_TAR}/tar_debug_${number_pack}.list | xargs rm
150
151
152DEM_log -1 "On defini le datebegin de la  prochaine periode pack"
153#on defini la periode pack suivante
154   month_begin_pack=${month_end_pack}
155   year_begin_pack=${year_end_pack}
156
157   if [ ${month_begin_pack} -le 9 ]
158   then
159      date_begin_pack=${year_begin_pack}0${month_begin_pack}01
160   fi
161   if [ ${month_begin_pack} -gt 9 ]
162   then
163      date_begin_pack=${year_begin_pack}${month_begin_pack}01
164   fi
165
166
167   number_pack=`expr ${number_pack} + 1`
168
169done
170
171
172cd ${EXE_DIR}
173
174# gpdebug : le script n'a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi
175simuMonitoring_OK "$MonitoringInfo" "$config_card"
Note: See TracBrowser for help on using the repository browser.