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