#!/bin/sh # tape -- simple shell for OnStream DI-30 tape drive under RedHat Linux 6.2 # http://www.jpsdomain.org/linux/OnStream_DI-30-RedHat_Backup_mini-HOWTO.html # v0.9.0 2001-02-27 JP Vossen # v0.9.1 2001-06-06 JPV Added eject options # v0.9.2 2001-06-15 JPV Was "tar -tvbf 64 /dev..." but should have been # "tar tvb 64 -f /dev..." Thanks to David Burleigh for pointing this out. # v1.0.0 2001-11-25 # JPV Minor typo corrections MYVER="v1.1.0 2003-05-13" # JPV Added optional arguments to afio backup, # added local variables, pushd/popd. # Copyright 2001 JP Vossen # This script is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # In no event shall the author be liable for any damages whatsoever # (including, without limitation, damages for loss of business profits, # business interruption, loss of business information, or any other # pecuniary loss) arising out of the use of or inability to use this script. # NOTES: # 0. Requires afio if you use the afio options (duh!): # http://rpmfind.net/linux/rpm2html/search.php?query=afio&submit=Search+... # 1. Requires a symlink of /dev/tape and /dev/ntape to your tape device. # e.g. for an OnStream DI-30: # "ln -s /dev/ht0 /dev/tape && ln -s /dev/nht0 /dev/ntape" # 2. Assumes one archive per tape, but more can be added if you are # careful with the 'findnext' command. # 3. The DI-30 requires a block size of 32k in ALL operations. # e.g. tar uses blocks of 512b, so 32k=512b*64 # 4. The parameters specified here will work for the DI-30. Your mileage # may vary. # 5. See my "jpbackup" script for much better afio code. # 6. mt does not really need the "-f /dev/tape" if the TAPE environment # variable is correctly set. # Use variables to hard coded paths to prevent Bad Things(tm). AFIO='/usr/bin/afio' CAT='/bin/cat' ECHO='/bin/echo' FIND='/usr/bin/find' MT='/bin/mt' TAR='/bin/tar' MyTAPE='/dev/tape' MyNTAPE='/dev/ntape' # See how we were called. case "$1" in tbackup) if [ -z "$2" ]; then ${ECHO} "" ${ECHO} "Must specify a directory to backup!" exit 2 fi ${TAR} cvb 64 -f ${MyTAPE} $2 ;; ttoc) ${TAR} tvb 64 -f ${MyTAPE} ;; tverify) pushd . > /dev/nul cd / ${TAR} dvb 64 -f ${MyTAPE} popd ;; trestore) # not really needed ${MT} rewind # e.g. tape trestore # e.g. tape trestore root/mydoc* ${TAR} xvb 64 -f ${MyTAPE} $2 ;; backup) if [ -z "$2" ]; then ${ECHO} "" ${ECHO} "Must specify a directory to backup!" exit 2 fi # Note the '$3'!!! Optional arguments passed to afio. ${FIND} $2 | ${AFIO} -ovZ -b 32k -c 64 -M 10m -Q "-c6" $3 ${MyTAPE} ;; toc) ${AFIO} -tvxZ -b 32k -M 10m ${MyTAPE} ;; verify) pushd . > /dev/nul cd / ${AFIO} -rvxZ -b 32k -M 10m ${MyTAPE} popd ;; restore) # not really needed ${MT} rewind if [ -z "$2" ]; then # e.g. tape restore ${AFIO} -ivxZ -b 32k -M 10m ${MyTAPE} else # e.g. tape restore root/mydoc* ${AFIO} -ivxZ -b 32k -M 10m -y "$2" ${MyTAPE} fi ;; offline|eject) ${ECHO} "" ${ECHO} "Note: this will not eject the tape in IDE mode, but may help" ${ECHO} "allow you to manually eject it. It will eject in OSST mode." ${MT} -f ${MyTAPE} offline ;; erase) ${MT} -f ${MyTAPE} rewind ${MT} -f ${MyTAPE} erase ;; status) ${MT} -f ${MyTAPE} status ;; retension) # This spelling is correct ${MT} -f ${MyTAPE} retension ;; retention) ${ECHO} "" ${ECHO} "Next time you may want to spell it retension..." ${MT} -f ${MyTAPE} retension ;; rewind) ${MT} -f ${MyTAPE} rewind ;; findnext) if [ -z "$2" ]; then ${ECHO} "" ${ECHO} "Must specify the number of archives to skip!" exit 2 fi # Goto the start of the next archive. # See the mt man page: fsfm, bsf, bsfm, asf, eod, etc. # Note NON-rewinding device... ${MT} -f ${MyNTAPE} fsf $2 ;; end) # Goto the end of the existing data. # Note NON-rewinding device... ${MT} -f ${MyNTAPE} eod ;; *) ${ECHO} "$0 ${MYVER} Copyright 2001-2003 JP Vossen" ${ECHO} " http://www.jpsdomain.org/" ${ECHO} " Licensed under the GNU GENERAL PUBLIC LICENSE:" ${ECHO} " See http://www.gnu.org/copyleft/gpl.html for full text and details." ${ECHO} "" ${ECHO} "Usage:" ${ECHO} "- Using tar:" ${ECHO} " $0 [tbackup [dir]|ttoc|tverify|trestore [dir]]" ${ECHO} "- Using afio:" ${ECHO} " $0 [backup [dir] ('opts')|toc|verify|restore [dir]]" ${ECHO} "- Using tape device:" ${ECHO} " $0 [offline|eject|erase|status|retension|rewind|findnext|end]" ${ECHO} "" ${ECHO} "Notes:" ${ECHO} "1. You need to be in / for a verify to work" ${ECHO} " ($0 does this for you)..." ${ECHO} "2. If you are in / a restore will over-write the existing" ${ECHO} " directory. If not in /, a new structure will be created." ${ECHO} "3. findnext will find the next archive on the tape." ${ECHO} "4. You should really read this code and understand what it" ${ECHO} " does before trying to use it." ${ECHO} "5. The afio backup command takes optional arguments that are" ${ECHO} " passed directly to afio (e.g. '-E {no_compress_filename}')." ${ECHO} " Don't forget the quotes! See the afio manual for details." ${ECHO} "" exit 1 ;; esac