[1709] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | #on veut archiver les fichiers restart |
---|
| 5 | #Dans le cadre du demenagement ils seront renommes |
---|
| 6 | #ATM/Restart/****.nc |
---|
| 7 | #OCE/Restart/****.nc |
---|
| 8 | #... |
---|
| 9 | #sous la forme |
---|
| 10 | #RESTART/ATM_****.nc |
---|
| 11 | #RESTART/OCE_****.nc |
---|
| 12 | #Attention de bien conserver les dates d'origines |
---|
| 13 | # |
---|
| 14 | #Dans le cadre de la production nouvelle chaine |
---|
| 15 | #ils auront directement le bon nom |
---|
| 16 | # |
---|
| 17 | #On veut egalement que l'archive soit par periode de temps |
---|
| 18 | # cette periode est definie par la taille du pack donc connue |
---|
| 19 | # en entree du script (1M, 1Y, 5Y, 10Y etc...) |
---|
| 20 | # |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | # $1= PATH/config_card d'une simulation avec |
---|
| 24 | # TagName/JobName/ExperimentName/SpaceName/DateBegin/DateEnd/PATH_SIMUL |
---|
| 25 | # $2=period_pack en M/m ou Y/y |
---|
| 26 | |
---|
| 27 | config_card=${1} |
---|
| 28 | LISTE_DMNFS=${2} |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | export JOB_DIR=${JOB_DIR:-${PWD}} |
---|
| 32 | export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM} |
---|
| 33 | export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp} |
---|
| 34 | mkdir -p ${IGCM_DEM} |
---|
| 35 | mkdir -p ${IGCM_TMP} |
---|
| 36 | clean_tmp=${clean_tmp:-yes} |
---|
| 37 | EXE_DIR=$(dirname ${0}) |
---|
| 38 | SCRIPT_NAME=$(basename ${0} ) |
---|
| 39 | |
---|
| 40 | source ${EXE_DIR}/DEM_utilities.sh |
---|
| 41 | |
---|
[1822] | 42 | # gpdebug : verif si le present script a ete execute jusqu'au bout ######### |
---|
| 43 | MonitoringInfo="${SCRIPT_NAME}-->OK" |
---|
| 44 | simuMonitoring_check "$MonitoringInfo" "$config_card" |
---|
| 45 | |
---|
[1709] | 46 | DEM_log -0 "Demarrage de ${SCRIPT_NAME}" |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | #### 0- lecture de config.card |
---|
| 50 | #### on veut les renseignements suivants : |
---|
| 51 | #### JobName, PATH_SIMUL, DateBegin et DateEnd |
---|
| 52 | eval $(grep JobName ${config_card}) |
---|
| 53 | eval $(grep PATH_SIMUL_FULL ${config_card}) |
---|
| 54 | eval $(grep DateBegin ${config_card}) |
---|
| 55 | eval $(grep DateEnd ${config_card}) |
---|
| 56 | eval $(grep IGCM_DEM_SIMU ${config_card}) |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | #### Preparation de l'environnement |
---|
[1728] | 60 | # repertoire dans lequel seront renommes les fichiers de restart |
---|
| 61 | STORE_RESTART=$IGCM_DEM_SIMU/RESTART |
---|
[1709] | 62 | mkdir -p ${STORE_RESTART} |
---|
| 63 | |
---|
[1728] | 64 | # repertoire dans lequel nous stockerons les listes de restart a archiver |
---|
| 65 | RESTART_TAR=$IGCM_DEM_SIMU/restart_tar |
---|
| 66 | mkdir -p ${RESTART_TAR} |
---|
| 67 | |
---|
[1709] | 68 | # lecture de periodpack dans ${IGCM_DEM_SIMU}/period_pack.txt |
---|
| 69 | period_pack=`awk '{print $0} ' ${IGCM_DEM_SIMU}/period_pack.txt` |
---|
| 70 | |
---|
[1754] | 71 | DEM_log -1 "Period pack = ${period_pack}" |
---|
[1709] | 72 | #### 1- renommer les fichiers ###### |
---|
| 73 | DEM_log -1 "Renommer les fichiers de Restart" |
---|
| 74 | |
---|
| 75 | cd ${STORE_RESTART} |
---|
| 76 | rm -rf * |
---|
| 77 | |
---|
| 78 | # On les copie sur le scratchdir en changeant le nom et conservant la date |
---|
[1754] | 79 | awk '{print $2}' ${IGCM_DEM_SIMU}/liste_restart_files_config.txt > ${IGCM_TMP}/${$}.liste_restart_files.txt |
---|
| 80 | #grep ${PATH_SIMUL_FULL} ${LISTE_DMNFS} | grep Restart | awk '{print $3}' | sed '/^.*Restart$/d' >> ${IGCM_TMP}/${$}.liste_restart_files.txt |
---|
[1709] | 81 | |
---|
| 82 | |
---|
[1730] | 83 | gawk -F/ '{dest_name=$(NF-2)("_") $(NF); system("ln -s " $0 " "dest_name)}' ${IGCM_TMP}/${$}.liste_restart_files.txt |
---|
[1709] | 84 | |
---|
[1730] | 85 | ls -l ${STORE_RESTART} > ${IGCM_TMP}/${$}.new_liste_restart_files.txt |
---|
[1709] | 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 | |
---|
[1754] | 117 | date_end_pack=${year_end_pack}${month_end_pack}01 |
---|
| 118 | |
---|
[1730] | 119 | for file in `awk '{print $9}' ${IGCM_TMP}/${$}.new_liste_restart_files.txt`; do |
---|
[1709] | 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 | |
---|
[1754] | 124 | # DEM_log "date_file = ${date_file}" |
---|
[1709] | 125 | if [ ${date_file} -lt ${date_end_pack} ] |
---|
| 126 | then |
---|
| 127 | if [ ${date_file} -ge ${date_begin_pack} ] |
---|
| 128 | then |
---|
[1754] | 129 | # DEM_log "${file} ${date_file} dans ${date_begin_pack} ${date_end_pack} " |
---|
[1709] | 130 | echo ${file} >> ${IGCM_TMP}/${$}.liste_pack_restart_${number_pack}.txt |
---|
| 131 | fi |
---|
| 132 | fi |
---|
| 133 | |
---|
| 134 | done |
---|
| 135 | |
---|
| 136 | #on archive les restart - le nom de l'archive contiendra ${yearbegin}${monthbegin}_${yearend}${monthend} |
---|
| 137 | # end etant la date du dernier fichier contenu et non pas la premiere date suivant |
---|
| 138 | DEM_log -1 "Recherche de la date de fin reel pour nommer l'archive " |
---|
| 139 | #On classe par ordre alphabetique les fichiers contenus dans liste_pack_restart |
---|
| 140 | #la date du dernier fichier donnera la date de fin du pack |
---|
| 141 | sort ${IGCM_TMP}/${$}.liste_pack_restart_${number_pack}.txt > ${IGCM_TMP}/${$}.liste_pack_restart_${number_pack}.txt.tmp |
---|
| 142 | last_file=$(tail -n 1 ${IGCM_TMP}/${$}.liste_pack_restart_${number_pack}.txt.tmp ) |
---|
| 143 | extract_date_file=$( echo ${last_file} | sed -e "s/.*${JobName}_//" ) |
---|
| 144 | DateEnd_Restart=$( echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' ) |
---|
[1755] | 145 | mv ${IGCM_TMP}/${$}.liste_pack_restart_${number_pack}.txt.tmp ${RESTART_TAR}/${JobName}_restart_${date_begin_pack}_${DateEnd_Restart}.list |
---|
[1709] | 146 | |
---|
| 147 | |
---|
| 148 | DEM_log -1 "Passage de la commande Tar pour archiver la liste creee" |
---|
[1728] | 149 | # tar -cf ${JobName}_${date_begin_pack}_${DateEnd_Restart}_restart.tar --dereference --files-from ${RESTART_TAR}/tar_restart_${date_begin_pack}_${DateEnd_Restart}.list |
---|
| 150 | # cat ${RESTART_TAR}/tar_restart_${number_pack}.list | xargs rm |
---|
[1709] | 151 | |
---|
| 152 | |
---|
| 153 | DEM_log -1 "On defini le datebegin de la prochaine periode pack" |
---|
| 154 | #on defini la periode pack suivante |
---|
| 155 | month_begin_pack=${month_end_pack} |
---|
| 156 | year_begin_pack=${year_end_pack} |
---|
| 157 | |
---|
[1754] | 158 | date_begin_pack=${year_begin_pack}${month_begin_pack}01 |
---|
[1709] | 159 | |
---|
| 160 | number_pack=`expr ${number_pack} + 1` |
---|
| 161 | |
---|
| 162 | done |
---|
| 163 | |
---|
| 164 | |
---|
[1728] | 165 | cd ${EXE_DIR} |
---|
[1822] | 166 | |
---|
| 167 | # gpdebug : le script n'a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi |
---|
| 168 | simuMonitoring_OK "$MonitoringInfo" "$config_card" |
---|