source: TOOLS/PACK_IPSL/archive_debug.sh @ 1921

Last change on this file since 1921 was 1913, checked in by aclsce, 12 years ago
  • Fixed some bugs
  • Property svn:executable set to *
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# 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# Test si il y a un repertoire Debug
65listDebugNbLines=`cat ${IGCM_TMP}/${$}.liste_debug_files.txt | wc -l `
66if [ "x${listDebugNbLines}" == "x0" ]
67then
68    DEM_log -0 "Pas de repertoire Debug pour cette simulation"
69else
70# cas particulier : les fichiers Bands sont conserves sans etre archives
71    grep ${JobName}_Bands ${IGCM_TMP}/${$}.liste_debug_files.txt >> ${STORE_CP}/cp_files.list
72    sed "/${JobName}_Bands/d" ${IGCM_TMP}/${$}.liste_debug_files.txt > ${IGCM_TMP}/${$}.liste_debug_files.txt_tmp
73    mv ${IGCM_TMP}/${$}.liste_debug_files.txt_tmp ${IGCM_TMP}/${$}.liste_debug_files.txt
74    gawk -F/ '{dest_name=$(NF-2)("_") $(NF); system("ln -s " $0 " "dest_name)}' ${IGCM_TMP}/${$}.liste_debug_files.txt
75
76#on fait de meme avec les fichiers out_gcm.e stockes dans le repertoire Out/ qui seront prefixes par Out_
77    rm -f ${IGCM_TMP}/${$}.liste_debug_files.txt
78    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep -w Out | awk '{print $3}' | sed '/^.*Out$/d' > ${IGCM_TMP}/${$}.liste_debug_files.txt
79    gawk -F/ '{dest_name=$(NF-1)("_") $(NF); system("ln -s " $0 " "dest_name)}' ${IGCM_TMP}/${$}.liste_debug_files.txt
80
81
82    ls -l ${STORE_DEBUG} > ${IGCM_TMP}/${$}.new_liste_debug_files.txt
83### 2- creer les listes de fichiers par periode ####
84    DEM_log -1 "Creation des listes de fichiers par periode"
85### 2.1- extraire l'annee et le mois de DateBegin ###
86    date_begin=${DateBegin}
87    date_end=${DateEnd}
88
89    year_begin=$(echo ${date_begin} | cut -c 1-4 )
90    month_begin=$(echo ${date_begin} | cut -c 5-6 )
91    year_end=$(echo ${date_end} | cut -c 1-4 )
92    month_end=$(echo ${date_end} | cut -c 5-6 )
93
94
95### 2.2- creation des listes ###
96    date_begin_pack=${date_begin}
97    date_end_simulation=${date_end}
98
99    month_begin_pack=${month_begin}
100    year_begin_pack=${year_begin}
101
102    number_pack=1
103
104    while [ ${date_begin_pack} -le ${date_end_simulation} ]
105    do
106
107        DEM_log -1 "On calcule la date de fin du pack "
108
109        month_end_pack=${month_begin_pack}
110        year_end_pack=`expr ${year_begin_pack} + ${period_pack}`
111
112        date_end_pack=${year_end_pack}${month_end_pack}01   
113
114        if [ "x${ON_IDRIS}" == "xno" ]
115        then
116            for file in `awk '{print $9}' ${IGCM_TMP}/${$}.new_liste_debug_files.txt`; do
117                extract_date_file=`echo ${file}  | sed -e "s/.*\${JobName}_//"`
118                date_file=`echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g'`
119
120                if [  ${date_file} -lt ${date_end_pack} ]
121                then
122                    if [ ${date_file} -ge ${date_begin_pack} ]
123                    then
124                        echo ${file} >> ${IGCM_TMP}/${$}.liste_pack_debug_${number_pack}.txt
125                    fi
126                fi
127            done
128        else
129            for file in `awk '{print $8}' ${IGCM_TMP}/${$}.new_liste_debug_files.txt`; do
130                extract_date_file=`echo ${file}  | sed -e "s/.*\${JobName}_//"`
131                date_file=`echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g'`
132
133                if [  ${date_file} -lt ${date_end_pack} ]
134                then
135                    if [ ${date_file} -ge ${date_begin_pack} ]
136                    then
137                        echo ${file} >> ${IGCM_TMP}/${$}.liste_pack_debug_${number_pack}.txt
138                    fi
139                fi
140            done 
141        fi
142
143#on archive les debug - le nom de l'archive contiendra ${yearbegin}${monthbegin}_${yearend}${monthend} 
144# end etant la date du dernier fichier contenu et non pas la premiere date suivant
145DEM_log -1 "Recherche de la date de fin reel pour nommer l'archive "
146#On classe par ordre alphabetique les fichiers contenus dans liste_pack_debug
147#la date du dernier fichier donnera la date de fin du pack
148   sort ${IGCM_TMP}/${$}.liste_pack_debug_${number_pack}.txt > ${IGCM_TMP}/${$}.liste_pack_debug_${number_pack}.txt.tmp
149   last_file=$(tail -n 1 ${IGCM_TMP}/${$}.liste_pack_debug_${number_pack}.txt.tmp )
150   extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" )
151   DateEnd_Debug=$(   echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
152   mv ${IGCM_TMP}/${$}.liste_pack_debug_${number_pack}.txt.tmp ${DEBUG_TAR}/${JobName}_debug_${date_begin_pack}_${DateEnd_Debug}.list
153
154
155DEM_log -1 "Passage de la commande Tar pour archiver la liste creee"
156#   tar -cf ${JobName}_${date_begin_pack}_${DateEnd_Debug}_debug.tar --dereference  --files-from ${DEBUG_TAR}/tar_debug_${date_begin_pack}_${DateEnd_Debug}.list
157#   cat  ${DEBUG_TAR}/tar_debug_${number_pack}.list | xargs rm
158
159
160DEM_log -1 "On defini le datebegin de la  prochaine periode pack"
161#on defini la periode pack suivante
162   month_begin_pack=${month_end_pack}
163   year_begin_pack=${year_end_pack}
164
165   date_begin_pack=${year_begin_pack}${month_begin_pack}01
166
167   number_pack=`expr ${number_pack} + 1`
168
169done
170
171fi
172
173cd ${EXE_DIR}
174
175# gpdebug : le script n'a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi
176simuMonitoring_OK "$MonitoringInfo" "$config_card"
Note: See TracBrowser for help on using the repository browser.