Image

Image

Search This Blog

Friday, November 21, 2008

tape backup

quick and dirty, ofc. adapted after pjl, whom adapted a script from sco sysV made in 1988. 

 #!/bin/sh 

# Local Variables recipient1=service@xxxxxxx.com recipient2=sandra@xxxxxxx.com printer=office TAPE=/dev/st0 # System variables LOCK=/var/autotback/backlock DEFAULTDIR=/var/autotback REPORTFILE=/var/autotback/backrep TEMPFILE=/var/autotback/backtmp TEMPFILE2=/var/autotback/backtmp2 # Check if another backup is running if [ -r $LOCK ] then echo “Another backup is running or the last backup has not finished well. Please check!” echo “Another backup is running or the last backup has not finished well. Please check!” | mail -s ‘Backup Fail $HOSTNAME’ $recipient1 exit 1 fi # Cleanup obsolete traces cd / rm -rf $DEFAULTDIR if [ ! -d $DEFAULTDIR ] then mkdir $DEFAULTDIR fi # Create lockfile echo “backup started”>$LOCK # Start backup banner “ Automatic Backup Report “>$REPORTFILE echo “(c)1991-2008 Xxxxxxx Services Inc.”>>$REPORTFILE echo “======================================================================================”>>$REPORTFILE echo “”>>$REPORTFILE echo “Backup of $HOSTNAME Started on `date` “>>$REPORTFILE echo “”>>$REPORTFILE # Exclude /proc /sys /tmp find . -depth -print >$DEFAULTDIR/list grep -v “./sys/” $DEFAULTDIR/list >$DEFAULTDIR/list2 grep -v “./proc/” $DEFAULTDIR/list2 >$DEFAULTDIR/list3 grep -v “./tmp/” $DEFAULTDIR/list3 >$DEFAULTDIR/list4 # Start saving echo “BACKUP OF `date`”>$TEMPFILE cat $DEFAULTDIR/list4 | cpio -ocvB >$TAPE 2>>$TEMPFILE backstat=$? tail $TEMPFILE >>$REPORTFILE echo “”>>$REPORTFILE echo “$backstat = exit status”>>$REPORTFILE echo “”>>$REPORTFILE if [ $backstat -ne 0 ] then echo “*** Backup may contain an error ***”>>$REPORTFILE fi echo “Tape Save completed on `date`”>>$REPORTFILE echo “”>>$REPORTFILE set `tail -1 $TEMPFILE` BACKTOT=$1 echo “Total of amount of Backup was $1 blocks Starting Verify”>>$REPORTFILE echo “”>>$REPORTFILE #Tape rewind / Verify cpio -icvtB <$TAPE >>$TEMPFILE 2>>$TEMPFILE2 verstat=$? tail $TEMPFILE2 >>$REPORTFILE echo “$verstat = exit status”>>$REPORTFILE echo “”>>$REPORTFILE if [ $verstat -ne 0 ] then echo “*** Verify may contain an error ***”>>$REPORTFILE echo “”>>$REPORTFILE fi echo “Verify completed for server $HOSTNAME `date` “>>$REPORTFILE echo “”>>$REPORTFILE set `tail -1 $TEMPFILE2` VERTOT=$1 if [ “$BACKTOT” != “$VERTOT” -o $backstat -ne 0 -o $verstat -ne 0 ] then echo “*** WARNING BACKUP TRANSFER TOTALS DID NOT MATCH ***”>>$REPORTFILE echo “*** PLEASE VERIFY ***”>>$REPORTFILE echo “”>>$REPORTFILE else echo “*** Transfer Totals Concur ***”>>$REPORTFILE echo “”>>$REPORTFILE fi # Send the report cat $REPORTFILE | mail -s ‘Backup Report $HOSTNAME’ $recipient1, $recipient2 #lp -d $printer $REPORTFILE # Remove lock and exit sleep 5 rm $LOCK exit 0

No comments:

Post a Comment

Blog Archive