[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 | |
---|
| 25 | DEM_log -0 "Demarrage de ${SCRIPT_NAME}" |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | #### 0- lecture de config.card |
---|
| 29 | #### on veut les renseignements suivants : |
---|
| 30 | #### JobName, PATH_SIMUL, DateBegin et DateEnd |
---|
| 31 | eval $(grep JobName ${config_card}) |
---|
| 32 | eval $(grep PATH_SIMUL_FULL ${config_card}) |
---|
| 33 | eval $(grep DateBegin ${config_card}) |
---|
| 34 | eval $(grep DateEnd ${config_card}) |
---|
| 35 | eval $(grep IGCM_DEM_SIMU ${config_card}) |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | #### Preparation de l'environnement |
---|
| 39 | # repertoire dans lequel seront renommes les fichiers de debug |
---|
| 40 | STORE_DEBUG=$IGCM_DEM_SIMU/DEBUG |
---|
| 41 | mkdir -p ${STORE_DEBUG} |
---|
| 42 | |
---|
| 43 | # repertoire dans lequel nous stockerons les listes de debug a archiver |
---|
| 44 | DEBUG_TAR=$IGCM_DEM_SIMU/debug_tar |
---|
| 45 | mkdir -p ${DEBUG_TAR} |
---|
[1730] | 46 | STORE_CP=$IGCM_DEM_SIMU/store_cp |
---|
| 47 | mkdir -p ${STORE_CP} |
---|
[1728] | 48 | |
---|
| 49 | # lecture de periodpack dans ${IGCM_DEM_SIMU}/period_pack.txt |
---|
| 50 | period_pack=`awk '{print $0} ' ${IGCM_DEM_SIMU}/period_pack.txt` |
---|
| 51 | |
---|
| 52 | #### 1- renommer les fichiers ###### |
---|
| 53 | DEM_log -1 "Renommer les fichiers de Debug" |
---|
| 54 | |
---|
| 55 | cd ${STORE_DEBUG} |
---|
| 56 | rm -rf * |
---|
| 57 | |
---|
| 58 | # On les copie sur le scratchdir en changeant le nom et conservant la date |
---|
[1730] | 59 | grep ${PATH_SIMUL_FULL} ${LISTE_DMNFS} | grep Debug | awk '{print $3}' | sed '/^.*Debug$/d' >> ${IGCM_TMP}/${$}.liste_debug_files.txt |
---|
| 60 | grep ${JobName}_Bands ${IGCM_TMP}/${$}.liste_debug_files.txt > ${STORE_CP}/cp_bands.list |
---|
| 61 | sed "/${JobName}_Bands/d" ${IGCM_TMP}/${$}.liste_debug_files.txt > ${IGCM_TMP}/${$}.liste_debug_files.txt_tmp |
---|
| 62 | mv ${IGCM_TMP}/${$}.liste_debug_files.txt_tmp ${IGCM_TMP}/${$}.liste_debug_files.txt |
---|
[1728] | 63 | |
---|
[1730] | 64 | gawk -F/ '{dest_name=$(NF-2)("_") $(NF); system("ln -s " $0 " "dest_name)}' ${IGCM_TMP}/${$}.liste_debug_files.txt |
---|
[1728] | 65 | |
---|
[1730] | 66 | ls -l ${STORE_DEBUG} > ${IGCM_TMP}/${$}.new_liste_debug_files.txt |
---|
[1728] | 67 | |
---|
| 68 | ### 2- creer les listes de fichiers par periode #### |
---|
| 69 | DEM_log -1 "Creation des listes de fichiers par periode" |
---|
| 70 | ### 2.1- extraire l'annee et le mois de DateBegin ### |
---|
| 71 | date_begin=${DateBegin} |
---|
| 72 | date_end=${DateEnd} |
---|
| 73 | |
---|
| 74 | year_begin=$(echo ${date_begin} | cut -c 1-4 ) |
---|
| 75 | month_begin=$(echo ${date_begin} | cut -c 5-6 ) |
---|
| 76 | year_end=$(echo ${date_end} | cut -c 1-4 ) |
---|
| 77 | month_end=$(echo ${date_end} | cut -c 5-6 ) |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | ### 2.2- creation des listes ### |
---|
| 81 | date_begin_pack=${date_begin} |
---|
| 82 | date_end_simulation=${date_end} |
---|
| 83 | |
---|
| 84 | month_begin_pack=${month_begin} |
---|
| 85 | year_begin_pack=${year_begin} |
---|
| 86 | |
---|
| 87 | number_pack=1 |
---|
| 88 | |
---|
| 89 | while [ ${date_begin_pack} -le ${date_end_simulation} ] |
---|
| 90 | do |
---|
| 91 | |
---|
| 92 | DEM_log -1 "On calcule la date de fin du pack " |
---|
| 93 | |
---|
| 94 | month_end_pack=${month_begin_pack} |
---|
| 95 | year_end_pack=`expr ${year_begin_pack} + ${period_pack}` |
---|
| 96 | |
---|
| 97 | if [ ${month_end_pack} -le 9 ] |
---|
| 98 | then |
---|
| 99 | date_end_pack=${year_end_pack}0${month_end_pack}01 |
---|
| 100 | fi |
---|
| 101 | if [ ${month_end_pack} -gt 9 ] |
---|
| 102 | then |
---|
| 103 | date_end_pack=${year_end_pack}${month_end_pack}01 |
---|
| 104 | fi |
---|
| 105 | |
---|
| 106 | |
---|
[1730] | 107 | for file in `awk '{print $9}' ${IGCM_TMP}/${$}.new_liste_debug_files.txt`; do |
---|
[1728] | 108 | |
---|
| 109 | extract_date_file=`echo ${file} | sed -e "s/.*\${JobName}_//"` |
---|
| 110 | date_file=`echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g'` |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | if [ ${date_file} -lt ${date_end_pack} ] |
---|
| 114 | then |
---|
| 115 | if [ ${date_file} -ge ${date_begin_pack} ] |
---|
| 116 | then |
---|
| 117 | echo ${file} >> ${IGCM_TMP}/${$}.liste_pack_debug_${number_pack}.txt |
---|
| 118 | fi |
---|
| 119 | fi |
---|
| 120 | |
---|
| 121 | done |
---|
| 122 | |
---|
| 123 | #on archive les debug - le nom de l'archive contiendra ${yearbegin}${monthbegin}_${yearend}${monthend} |
---|
| 124 | # end etant la date du dernier fichier contenu et non pas la premiere date suivant |
---|
| 125 | DEM_log -1 "Recherche de la date de fin reel pour nommer l'archive " |
---|
| 126 | #On classe par ordre alphabetique les fichiers contenus dans liste_pack_debug |
---|
| 127 | #la date du dernier fichier donnera la date de fin du pack |
---|
| 128 | sort ${IGCM_TMP}/${$}.liste_pack_debug_${number_pack}.txt > ${IGCM_TMP}/${$}.liste_pack_debug_${number_pack}.txt.tmp |
---|
| 129 | last_file=$(tail -n 1 ${IGCM_TMP}/${$}.liste_pack_debug_${number_pack}.txt.tmp ) |
---|
| 130 | extract_date_file=$( echo ${last_file} | sed -e "s/.*${JobName}_//" ) |
---|
| 131 | DateEnd_Debug=$( echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' ) |
---|
| 132 | mv ${IGCM_TMP}/${$}.liste_pack_debug_${number_pack}.txt.tmp ${DEBUG_TAR}/tar_debug_${date_begin_pack}_${DateEnd_Debug}.list |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | DEM_log -1 "Passage de la commande Tar pour archiver la liste creee" |
---|
| 136 | # tar -cf ${JobName}_${date_begin_pack}_${DateEnd_Debug}_debug.tar --dereference --files-from ${DEBUG_TAR}/tar_debug_${date_begin_pack}_${DateEnd_Debug}.list |
---|
| 137 | # cat ${DEBUG_TAR}/tar_debug_${number_pack}.list | xargs rm |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | DEM_log -1 "On defini le datebegin de la prochaine periode pack" |
---|
| 141 | #on defini la periode pack suivante |
---|
| 142 | month_begin_pack=${month_end_pack} |
---|
| 143 | year_begin_pack=${year_end_pack} |
---|
| 144 | |
---|
| 145 | if [ ${month_begin_pack} -le 9 ] |
---|
| 146 | then |
---|
| 147 | date_begin_pack=${year_begin_pack}0${month_begin_pack}01 |
---|
| 148 | fi |
---|
| 149 | if [ ${month_begin_pack} -gt 9 ] |
---|
| 150 | then |
---|
| 151 | date_begin_pack=${year_begin_pack}${month_begin_pack}01 |
---|
| 152 | fi |
---|
| 153 | |
---|
| 154 | |
---|
| 155 | number_pack=`expr ${number_pack} + 1` |
---|
| 156 | |
---|
| 157 | done |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | cd ${EXE_DIR} |
---|