Changes between Version 1 and Version 2 of Docs/MirroringStdAncilFiles


Ignore:
Timestamp:
11/02/16 13:47:08 (4 years ago)
Author:
willie
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Docs/MirroringStdAncilFiles

    v1 v2  
    8888link to my ARCHER directory. 
    8989 
    90 When the synchronization is complete, there are some files in the 
    91 ancillary tree that link to files on the Met Office computers.  These 
    92 are repaired using the clean_link script, 
    93  
    94 {{{ 
    95 find $DATADIR/ancil -type l -exec clean_link {} \; 
    96 }}} 
    97 The clean links script: 
    98 {{{ 
    99 #!/bin/ksh 
    100 # 
    101 # Author: W. McGinty, NCAS-CMS 
    102 # 11th Nov 2015 
    103 # 
    104 # Corrects links in the ancillary tree after a synch from the  
    105 # Met Office. 
    106 # 
    107 # Takes a file name, determines if it is a link, and corrects it if 
    108 # required. 
    109 # 
    110 # The Met Office has link targets of the form 
    111 # 
    112 # /projects/um1/ancil/ancil_versions/mc170130_flk/ancils 
    113 # 
    114 # which rsync replicates identically on ARCHER.  These need to be 
    115 #replaced either with an ARCHER absolute or relative reference.  This 
    116 #code uses the absolute method, which is distasteful, but a lot easier 
    117 #than working out the relative reference, which may be in another 
    118 #branch of the tree. 
    119 # 
    120 # 
    121 # program name 
    122 prog=${0##*/} 
    123  
    124 if  [[ $# != 1 &&  $# != 2 ]]  ; then 
    125   echo "Usage: $prog [-r] file_name" >&2 
    126   echo "The program does a dry run unless the -r option"\ 
    127     "is specified, when it corrects the link." >&2 
    128   exit 1 
    129 fi 
    130  
    131 mode="test" 
    132 while getopts  "r[run]" opt 
    133 do case $opt in 
    134  r)  mode="run";; 
    135  \?)  printf "Usage: %s [-r] [file name]\n" $prog 
    136      exit 1;; 
    137   esac 
    138 done 
    139 shift $((OPTIND-1)) 
    140  
    141 if (( ${#DATADIR} == 0 )); then 
    142  echo "DATADIR must be specified" >&2 
    143  exit 1 
    144 fi  
    145  
    146 if [[ ! -d $DATADIR ]] ; then 
    147  echo "$DATADIR must exist and be a directory." .&2 
    148  exit 1 
    149 fi 
    150  
    151  
    152 fn=$1 
    153  
    154 if [[ -L $fn ]]; then 
    155  
    156 # fn is a link 
    157   tgt=$(readlink $fn) 
    158  
    159 #Find those which start with an absolute directory 
    160   if [[ $tgt == /projects/um1/* ]]; then 
    161  
    162 #remove the absolute root /projects/um1/ 
    163     branch=${tgt#/projects/um1/} 
    164  
    165     if [ $mode == "test" ]; then 
    166 # Test it 
    167       echo  "link: " $fn 
    168       echo  "    target is " $tgt 
    169       echo  "    branch is " $branch 
    170       echo  "    New tgt would be " $DATADIR/$branch 
    171       echo  "    basename of link is " $(basename $fn) 
    172       echo  "    dirname of link is " $(dirname $fn) 
    173       echo  "   " ln -sfv $DATADIR/$branch $(basename $fn) 
    174     else 
    175 # Correct it 
    176       cd $(dirname $fn) 
    177       ln -sfv $DATADIR/$branch $(basename $fn) 
    178       cd - 1>/dev/null # make sure it is silent 
    179     fi 
    180   fi 
    181 fi 
    182  
    183 }}}