#! /bin/csh # # tarraw - C shell script to tar raw mooring data into .tar.gz files # Note - this script then moves the raw files into directory # ./raw/erase. The intent is to allow ops/TSD folks to # inspect the *.dir files to make sure everything is tar'd # OK, and then erase the raw files from ./raw/erase. It does # this rather than rm'ing the files in order to allow recovery # from script/system errors. # Copyright (C) 2001 MBARI # Author: Kent Headley # MBARI provides this documentation and code "as is", with no warranty, # express or implied, of its quality or consistency. It is provided without # support and without obligation on the part of the Monterey Bay Aquarium # Research Institute to assist in its use, correction, modification, or # enhancement. This information should not be published or distributed to # third parties without specific written permission from MBARI. # 15May2013 rschramm - Added check to create base tar file if it doesnt already exist # - Only move files to erase if successfully tar'd # - Removed unused section that checked for yrday in leapyears # as it was unused, pos. left over for when script only moved files # from previous day? As currently written tar/moves all files NOT on # current day so day 366 doesnt really matter # - Cleanup and comment set OASIS = /oasis/test set mooringlist="m1 m46044 oa1 oa2" set TAR=$OASIS/raw/tar set RAW=$OASIS/raw set ERASE=$OASIS/raw/erase set UNZIP=/usr/mbari/bin/gunzip set ZIP=/usr/mbari/bin/gzip set dllog = "dlinfo" set nonomatch #for each mooring in the mooringlist above.... #makes string variable of todays yr+yrday, #cd's to the raw downloads directory and #does ls with grep with -v to build list of #all hourly download files for mooring that are NOT today. #walks that list to add files to the mooring tar #moves the download file to the erase subdir for later manual cleanup #also does a tar and move for the dlinfo files...r.schramm jun-2011 @ today = `date +%j` set filebase = `date +%Y``printf "%03d" $today` foreach mooring ($mooringlist) #if gzip tar exists for mooring then unzip it so we can add to it cd $TAR if ( -e $mooring.tar.gz ) \ $UNZIP $mooring.tar.gz >& /dev/null #which files need to be archived cd $RAW set filelist = `ls $mooring.*|grep -v $filebase` foreach file ($filelist) if ( -e $TAR/$mooring.tar ) then tar rvf $TAR/$mooring.tar $file >& /dev/null else tar cvf $TAR/$mooring.tar $file >& /dev/null endif # move file to erase dir if tar was sucessful... if($status) then echo "error adding file: $file to $TAR/$mooring.tar" else mv $file $ERASE endif end #foreach file #make an text 'directory' of the tar #then re-gzip the archive cd $TAR tar tvf $mooring.tar >& $mooring.dir $ZIP $mooring.tar >& /dev/null end #end foreach mooring #done with all moorings, now cleanup the dllog files as well.... cd $TAR #create the initial tar if it doesnt exist if ( !( -e $dllog.tar.gz ) ) then echo "Download Log Archive Created "`date` > log.start tar cvf $dllog.tar log.start $ZIP $dllog.tar rm -f log.start endif #unzip tar, add files, mv files, rezip if ( -e $dllog.tar.gz ) then $UNZIP $dllog.tar.gz >& /dev/null cd $RAW set filebase = `date +%Y``printf "%03d" $today` set filelist = `ls $dllog.2*|grep -v $filebase` foreach file ($filelist) tar rvf $TAR/$dllog.tar $file >& /dev/null mv $file $ERASE end cd $TAR tar tvf $dllog.tar >& $dllog.dir $ZIP $dllog.tar >& /dev/null endif