Nathan Heagy wrote:
> 
> I'm trying to setup a simple cron backup. Here's the script as it is:
> 
> ftmt -f /dev/nqft0 reten
> tar czvf /dev/nqft0 /
> ftmt -f /dev/nqft0 rewind
> 
> which isn't working because the tape keeps filling, with this error:
> 
> [167] 0        ftape-rw.c (skip_reverse) - Still at EOT while reverse
> seeking :-(.
> [168] 0   fdc-isr.c (determine_progress) - Error "overrun" at 101897/13.
> [169] 0    ftape-write.c (ftape_write_segment) - write error, retry 1
> (101897).
> 
<snip...>

Two parts to my comments. 
 
1) the overrun and write errors seem familiar to those I
experienced until I slowed down my Ditto Max drive - set the
rate_limit parameter in conf.modules against the ftape entry
(refer to the various HOWTOs for more information). A copy of my
conf.modules is appended.
 
2) also appended is a script (parts from ftape HOWTOs) I wrote as
an experiment to generate, control and interact with native tar
backups onto tape. The script can be called manually or from cron.
I pipe the results to email so I am informed of backup outcomes
remotely.

General comment: any script gurus want to comment on my script and
offer suggestions for
improvements/corrections? Linux newbies like myself can learn a
lot from such discussions.

# conf.modules #

alias eth0 ne
options ne io=0x300 
alias sdla sdla 
alias char-major-27 zftape 
options ftape -f ft_fdc_driver=ftape-internal,none,none,none
ft_tracings=3,3,3,3,3
options zftape -f ft_major_device_number=27
options ftape-internal -f ft_fdc_fc10=0 ft_fdc_mach2=0
ft_fdc_base=0x210 ft_fdc_irq=9 ft_fdc_dma=3
ft_fdc_rate_limit=2000 # ft_fdc_threshold=15
#pre-install ftape-internal /sbin/swapout 16 


# Backup script #
# don't copy this from a DOS/WIN machine onto Linux, Win CR/LF
differs from Unix! #
# and messes up scripts in peculiar ways (bitter personal
experience) #

#!/bin/bash
#
# Backup control script V1.00
# written by Andy Corteen 1999-08-19
# - run manually or via cron -
#

# ###################################
#
# Initialise global variables
#

TAPEDEV=/dev/tape  #must be a non-rewinding ftape device
DIFFFILE=BACKUP.DIFF.FILE
TEMPFILE=BACKUP.TMP
FILEDIR=$(sh -c "/usr/bin/dirname $0")
FILESTORE=$(echo -e "$FILEDIR/$DIFFFILE")
TEMPSTORE=$(echo -e "$FILEDIR/$TEMPFILE")
DIFFDATE=$(sh -c '/bin/date +"%Y-%m-%d"')
HDATE=$(sh -c '/bin/date +"%a %Y-%m-%d %T %Z"')

# ###################################
#
# Function definitions
#

### Abnormal exit

ABEXIT () {
 ABTIME=$(sh -c '/bin/date +"%T %Z"')
 echo -e "\n!FAILED! at $ABTIME - $1"
 exit 1
}

### Validate command line

VALIDATECMD () {
 if [ $# -gt 1 ] || [ $# -lt 1 ]
  then
   # wrong number of parameters - abort
   echo -e "Command line error: $0 $@ ($#)"
   echo -e "Usage: [path]backups {Full|Diff|Status}"
   ABEXIT "should be 1 parameter, not $#"
  elif [ $1 = "Full" ] || [ $1 = "Diff" ] || [ $1 = "Status" ]
  then 
   # all seems well, carry on...
   return 0
  else 
   # unrecognised command line parameter
   echo -e "Command line error: $0 $@"
   echo -e "Usage: [path]backups {Full|Diff|Status}"
   ABEXIT "parameter not recognised (we are case sensitive)"
  fi
}

### Validate tape device

VALIDATEDEV () {
 if ! [ -c $TAPEDEV ]
  then 
   # referred device problem!
   echo -e "$TAPEDEV is not a character device"
   ABEXIT "script and/or $TAPEDEV setup broken"
 else 
  # all seems well, carry on...
  return 0
 fi
}

### Move to & confirm root directory
CHECKROOT () {
 # move to root "/"
 cd /

 # check move worked
 PWDSTRING=$(sh -c /bin/pwd)
 if [ $PWDSTRING != "/" ]
  then
   # change to root failed!
   echo -e "Unable to change to root directory"
   ABEXIT "cannot verify if not in root"

  else
   # all seems well, carry on...
   return 0
  fi
}

### Rewind the tape
REWIND () {
  if ! /usr/bin/ftmt -f $TAPEDEV rewind
   then
    # rewind failed - maybe no tape in drive?
    echo -e "Rewind of $TAPEDEV failed"
    ABEXIT "no tape? drive open? drive busy? bad tape?"
   else
    # all seems well, carry on...
    return 0
  fi
}

### DO-STATUS report on tape
DOSTATUS () {
 # header bumph
 echo -e "\nSTATUS: Contents of $TAPEDEV"
 /usr/bin/printf "%11s%12s%20s%20s\n" \
   "File Number" "Block Size" "Volume Size" "Tape Space"

 # dump temporary file, if it exists
 trap "rm -f $TEMPSTORE"

 # process tape volinfo reports one by one
 while true
  do
   # read volume info from tape & pre-parse
   if ! foo=$(/usr/bin/ftmt -f $TAPEDEV volinfo | /usr/bin/cut -f
2 -d =)
    then
     # volinfo command failed
      echo -e "volinfo command &/or parsing failed"
    ABEXIT "cannot proceed"
    fi

   # separate parsed data into variables
   echo $foo > $TEMPSTORE  #echo $foo >
   read file blksz used usedunit size sizeunit < $TEMPSTORE

   # position tape header to next volume
   if ! /usr/bin/ftmt -f $TAPEDEV fsf 1 >/dev/null
    then
     # no more volumes on tape, so current one is status info
     echo -e "\nRemaining space: $used $usedunit"
     echo -e "Tape block size: $blksz"

     # all safely done, so return
     return 0
    fi

   # not on last volume, so print stats from previous read
   /usr/bin/printf "%6d            %5d  %20s%20s\n" \
     $file $blksz "$size $sizeunit" "$used $usedunit"

  done # while loop
}

### Differential backups
DODIFF () {
 # Set block size
 /usr/bin/ftmt setblk 10240

 # Set to end of used media
 /usr/bin/ftmt eom

 # ascertain diff date
 read DIFFDATE < $FILESTORE
 if ! echo $DIFFDATE | /usr/bin/grep \
    [1-2][0-9][0-9][0-9][-][0-9][0-9][-][0-9][0-9] >/dev/null
  then
   # read failed for some reason - warn operator but continue
   # with Diff backup using today's date as a default...wise?
   DIFFDATE=$(sh -c '/bin/date +"%Y-%m-%d"')
   echo -e "unable to read $FILESTORE, using $DIFFDATE as default"
  fi

 # Advise operation and date
 echo -e "\nDiff: backup (append) with verify, using $DIFFDATE\n"

 # perform standard "tar" backup with options as follows
 # c=create W=verify B=re-block N=after date -C=start in dir
 # --ignore-failed-read=soldier on --exclude=omit file or folder
 # can't use compression because verify excludes compression
 if ! /bin/tar -cWBf $TAPEDEV --totals --ignore-failed-read -C / \
    --exclude /proc -N $DIFFDATE /
  then
   # report the errors, but don't ABEXIT
   echo -e "Tar reported errors during backup"
  fi

 # exit normally
 return 0
}

### Full backups
DOFULL () {
 # set block size
 /usr/bin/ftmt setblk 10240

 # erase tape, retension first as defence against tape stretch
 /usr/bin/ftmt retension
 /usr/bin/ftmt erase

 # Advise operation
 echo -e "\nFull: backup (overwrite) with verify\n"

 # write date control file
 echo $DIFFDATE > $FILESTORE
 
 # perform standard "tar" backup with options as follows
 # c=create  W=verify  B=re-block --ignore-failed-read=soldier on
 # --exclude=omit file or folder -C=start in dir
 # can't use compression because verify excludes compression
 if ! /bin/tar -cWBf $TAPEDEV --totals --ignore-failed-read -C / \
    --exclude /proc /
  then
   # report the errors, but don't ABEXIT
   echo -e "Tar reported errors during backup"
  fi

 # exit normally
 return 0
}

# ###################################
#
# Main Program Thread
#

# welcome banner
echo -e "Backup Report for $TAPEDEV on $HDATE"

# sanity checks - these do not return if errors found
VALIDATECMD $@
VALIDATEDEV
CHECKROOT

# command processing...
case $1 in

 "Status")
  # status report
  REWIND
  DOSTATUS
  REWIND
  ;;

 "Diff")
  # differential backup
  REWIND
  DODIFF
  REWIND
  DOSTATUS
  REWIND
  ;;

 "Full")
  # full backup
  REWIND
  DOFULL
  REWIND
  DOSTATUS
  REWIND
  ;;

 *)
  # bad command somehow slipped through!
  echo -e "Internal command error"
  ABEXIT "nothing was written to the tape"
  ;;

 esac

# Last of all, spit out the date/time we finished
ETIME=$(sh -c '/bin/date +"%T %Z"')
HOURS=$[$SECONDS / 3600]
MINS=$[$[$SECONDS / 60] % 60]
SECS=$[$SECONDS % 60]
echo -e "\nCompleted at $ETIME with $HOURS:$MINS:$SECS elapsed\n"

Reply via email to