#!/bin/sh # Archive ngetq/runget logfiles for the given month and year # # Written by Steven Mueller, January 10th, 2002 # Last Modified: January 10, 2002 01:16 Thursday LOGDIR=~/.nget3/log ARCHIVEDIR=$LOGDIR/archive if [ $# -ne 2 ]; then echo "Usage: $0 year month" exit 1 fi YEAR=$1 MONTH=$2 # Sanity check year and month if [ $YEAR -lt 2000 ] || [ $YEAR -gt 2015 ]; then echo "Year $YEAR is out of range. Edit $0 if you think it shouldn't be." exit 2 fi case $MONTH in [1-9] ) MONTH=0$MONTH ;; 0[1-9]|1[12] ) : ;; * ) echo "Month $MONTH is out of range. Specify month as an integer in the range 1..12." exit 2 ;; esac YEARMONTH=${YEAR}${MONTH} CURYM=`date +"%Y%m"` if [ $YEARMONTH = $CURYM ]; then echo "It's currently still $CURYM; cowardly refusing to archive logfiles; aborting." exit 3 elif [ $YEARMONTH -gt $CURYM ]; then echo "Cowardly refusing to archive files from the future: $YEARMONTH. It's still $CURYM. Aborting." exit 3 fi ARFILE=$ARCHIVEDIR/ngetq_logs$YEARMONTH.tar.bz2 # Check dirs if [ ! -d $LOGDIR ]; then echo "Logdir $LOGDIR not found, aborting." exit 4 fi if [ ! -d $ARCHIVEDIR ]; then echo "Archive dir $ARCHIVEDIR not found, aborting." exit 4 fi if [ ! -w $ARCHIVEDIR ]; then echo "Archive dir $ARCHIVEDIR not writable, aborting." exit 4 fi # Check if archive file already exists if [ -e $ARFILE ]; then echo "Archive for $YEAR, month $MONTH already exists: $ARFILE" echo "Aborting." exit 16 fi # check if there are logfiles to archive for this date range cd $LOGDIR FILES="*_${YEARMONTH}*.anthem ngetq_${YEARMONTH}*" arfilecount=`ls $FILES 2>/dev/null | wc -w` if [ $arfilecount -lt 1 ]; then echo "No files to archive, aborting..." exit 32 fi echo "Archiving $arfilecount files matching $FILES" set -e #tar --remove-files -jcvf $ARFILE $FILES tar -jcvf $ARFILE $FILES echo "Archived $arfilecount files to $ARFILE:" ls -al $ARFILE