source: TOOLS/PACK_IPSL/archive_debug.sh @ 1906

Last change on this file since 1906 was 1900, checked in by aclsce, 12 years ago

Modified to write log files in TMP_MIGR_DATA directory (instead of current directory)

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