Link to home
Start Free TrialLog in
Avatar of javagair
javagairFlag for United States of America

asked on

linux tape script will not run mt commands

I have the following script that combines three directories into one and then writes the single directory to a tape.  Even though some of the lines now rewind tape this is only to test script.  I want to write to tape till tape is full so I should have a new directory for every date.  Directories overwrite  one another so only newest is on tape.  the only mt commands I can get to work consistently are any that take the tape off line such as
mt -f /dev/st0 offline or mt-f /dev/st0 rewoffl
doesn't appear to be any updates for the mt command
suggestions???

#!/bin/sh
declare NEWDATE
echo "tape file backup start time" > /var/log/FILE.log
date >> /var/log/FILE.log
cd /
mt -f /dev/nst0 eod     #moves to the end of directories I HOPE.
NEWDATE=$(date +%Y%m%d)
mkdir /$NEWDATE
tar -cvf /$NEWDATE/doc.tar /WCUBACKUP  #tars first dir to date dir
tar -cvf /$NEWDATE/email.tar /WCUEMAIL
tar -cvf /$NEWDATE/loan.tar /WCULOAN
tar -cvf /dev/st0 /$NEWDATE     #writes dir out to tape
mt -f /dev/nst0 rewind               #rewinds to see what is on tape
tar -tzf /dev/st0 >> /var/log/FILE.log    #sends list of files to log file  NOTHING SHOWS UP
mt -f /dev/nst0 rewind                         #again only for test
rm -fR /$NEWDATE                           #removes created dir from harddrive  THIS WORKS
tar -xvf /dev/st0                                  #writes dir back to harddrive as a test   DOES NOT HAPPEN
mt -f /dev/nst0 rewind                        #only for test
#mt -f /dev/nst0 eod                           #should move to end of data for next day
echo "tape FILE backup end time" >> /var/log/FILE.log
date >> /var/log/FILE.log


gary
Avatar of arnold
arnold
Flag of United States of America image

A few peculiar things:
1) You are not compressing the tar files when you create them.
2) you are moving the tape to the eod before you write your directory still uncompressed
3) you rewind the tape presumably to the beginning and then you have a typo in your script.  The tape is /dev/nst0 but you use /dev/st0 in both instances where you point out that it does not work.
You should address the tape device the same way through out.  Depending which tape device you are using, there are those that the change in how you address the tape device changes the hardware compression on the tape.
Hmm,

The /dev/nst0 = no-rewind scsi tape 0
/dev/st0 = scsi tape 0

So if you want don't want to rewind the tape before use you should use nst0.

Also the 'eod'  is not a mt option, I think you are looking for 'eom'  (end of media).


'tar -tzf /dev/st0 >> /var/log/FILE.log' is wrong, it should be 'tar -tvf'.

Finally I don't really understand why you create tar-balls before you write then to tape?! You could run the script like this if you wanted to.

#/bin/bash
# Simple backup script

# rewind tape
/bin/mt -f /dev/st0 rewind

# put files on tape
/bin/tar -cvf /dev/st0 /dir1 /dir2 /dir3...

# Did it get written? (verify)
/bin/mt -f /dev/st0 rewind
/bin/tar -tvf /dev/st0


Good luck!
I don't think it's a problem mixing /dev/nst0 and /dev/st0 as long as you're doing it with an awareness that the former is the non-rewinding device, and the latter is the rewinding device (it would definitely be a bit dubious to use the other st0 devices, like st0a and st0l, though)

AS cj17 points out, you should be using tar -tvf to list what's on the tape; you'd only use the z option (software compression) if you'd already used it when creating the tar archive in the first place. It's a bad idea to use software compression when writing to tape anyway, for a variety of reasons; as most modern drives use a very efficient hardware compression, you don't save any space on the tape, and if you lose a block and have to recover the data, it's a lot, LOT easier getting your data back from a TAR archive if it's uncompressed.

If you are wanting to verify only the last tar archive on the tape (ie, the one you've just written), you shouldn't be rewinding the drive all the way back to the beginning, but only reversing its position to the previous file mark (check out option bsfm).
Avatar of javagair

ASKER

guys

the reason I am taring tar files into tar file is that I want each directory to be a date for easy search later.
sorry about the "z" meant "v"

there is no eom option but there is a eod and seod option, tried both.
if you note the output of the script the tape never moves off   0  
mt -f /dev/st0 status
even though it obviously writes the dir and puts it back on the harddrive.  

still the directory gets over written on each date, so only the last one is on tape.

the reason I was rewinding and not backup is to see what was on the tape and as you can see there is only the date I am doing on each pass through the script (change date for each execution)

#!/bin/sh
declare NEWDATE
echo "tape file backup start time" > /var/log/FILE.log
date >> /var/log/FILE.log
cd /
echo "first status" >> /var/log/FILE.log
mt -f /dev/st0 status >> /var/log/FILE.log
mt -f /dev/st0 seod
echo "2nd status" >> /var/log/FILE.log
mt -f /dev/st0 status >> /var/log/FILE.log
NEWDATE=$(date +%Y%m%d)
mkdir /$NEWDATE
tar -cvf /$NEWDATE/doc.tar /WCUBACKUP
tar -cvf /$NEWDATE/email.tar /WCUEMAIL
tar -cvf /$NEWDATE/loan.tar /WCULOAN
tar -cvf /dev/st0 /$NEWDATE
echo "3rd status" >> /var/log/FILE.log
mt -f /dev/st0 status >> /var/log/FILE.log
mt -f /dev/st0 rewind
echo "4th status" >> /var/log/FILE.log
mt -f /dev/st0 status >> /var/log/FILE.log
tar -tvf /dev/st0 >> /var/log/FILE.log
echo "5th status" >> /var/log/FILE.log
mt -f /dev/st0 status >> /var/log/FILE.log
mt -f /dev/st0 rewind
echo "6th status" >> /var/log/FILE.log
mt -f /dev/st0 status >> /var/log/FILE.log
rm -fR /$NEWDATE
tar -xvf /dev/st0
echo "7th status" >> /var/log/FILE.log
mt -f /dev/st0 status >> /var/log/FILE.log
mt -f /dev/st0 rewind
echo "8th status" >> /var/log/FILE.log
mt -f /dev/st0 status >> /var/log/FILE.log
echo "tape FILE backup end time" >> /var/log/FILE.log
date >> /var/log/FILE.log




tape file backup start time
Sun Oct 19 11:38:26 MDT 2008
first status
SCSI 2 tape drive:
File number=0, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x8c (EXB-8505 compressed).
Soft error count since last status=0
General status bits on (41010000):
 BOT ONLINE IM_REP_EN
2nd status
SCSI 2 tape drive:
File number=0, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x8c (EXB-8505 compressed).
Soft error count since last status=0
General status bits on (41010000):
 BOT ONLINE IM_REP_EN
3rd status
SCSI 2 tape drive:
File number=0, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x8c (EXB-8505 compressed).
Soft error count since last status=0
General status bits on (41010000):
 BOT ONLINE IM_REP_EN
4th status
SCSI 2 tape drive:
File number=0, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x8c (EXB-8505 compressed).
Soft error count since last status=0
General status bits on (41010000):
 BOT ONLINE IM_REP_EN
drwxr-xr-x root/root         0 2008-10-19 11:39 20081019/
-rw-r--r-- root/root    133120 2008-10-19 11:39 20081019/loan.tar
-rw-r--r-- root/root    133120 2008-10-19 11:39 20081019/doc.tar
-rw-r--r-- root/root    133120 2008-10-19 11:39 20081019/email.tar
5th status
SCSI 2 tape drive:
File number=0, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x8c (EXB-8505 compressed).
Soft error count since last status=0
General status bits on (41010000):
 BOT ONLINE IM_REP_EN
6th status
SCSI 2 tape drive:
File number=0, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x8c (EXB-8505 compressed).
Soft error count since last status=0
General status bits on (41010000):
 BOT ONLINE IM_REP_EN
7th status
SCSI 2 tape drive:
File number=0, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x8c (EXB-8505 compressed).
Soft error count since last status=0
General status bits on (41010000):
 BOT ONLINE IM_REP_EN
8th status
SCSI 2 tape drive:
File number=0, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x8c (EXB-8505 compressed).
Soft error count since last status=0
General status bits on (41010000):
 BOT ONLINE IM_REP_EN
tape FILE backup end time
Sun Oct 19 11:41:23 MDT 2008
If you want to store multiple files on the same tape, you need to use the fsfm or the asf option to get the tape into position where the new data will be written.  You need to keep track of how many files you've written and reset the count if the tape is erased (which it should be if you are stating from the begining rather than relying on the new file will fit within the same space as the former.)  
Going to end of media (remember to use the non-rewinding device!) should be fine for appending to a tape.
ASKER CERTIFIED SOLUTION
Avatar of TapeDude
TapeDude
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

Just to make things clear on the  'nst' device,

If you use it it will not rewind the tape after the writing is completed, thus appending files is just a matter of doing the same command again.

An example:

tar -cvf /dev/nst0 /var/tmp/tarball1.tar   # 1:st write session
tar -cvf /dev/nst0 /var/tmp/tarball1.tar   # 2:st write session

if you rewind the tape and list the files you will have two files. Obviously it will not work if you eject the tape.

Cheers
sorry about not getting back, vacation
cut the script to a simple form
change the date on computer run script, change the date on computer, run script 5 times
do:  mt -f /dev/st0 rewoffl
reinsert the tape and do a tar to show what is on tape
only the first rwrite is there, not the next four days.

#!/bin/bash
declare NEWDATE
echo "tape file backup start time" > /var/log/FILE.log
date >> /var/log/FILE.log
cd /
NEWDATE=$(date +%Y%m%d)
mkdir /$NEWDATE
tar -cvf /$NEWDATE/doc.tar /WCUBACKUP
tar -cvf /$NEWDATE/email.tar /WCUEMAIL
tar -cvf /$NEWDATE/loan.tar /WCULOAN
tar -cvf /dev/nst0 /$NEWDATE
rm -fR /$NEWDATE
echo "tape FILE backup end time" >> /var/log/FILE.log
date >> /var/log/FILE.log

the way I look at script I should have five dir by date name, but don't

gary
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
decided to give up on the tape drive, no scripting seems to make this tape drive do what would only seem reasonable.  have tried everything suggested here and more, it seems to write but not read back.
gary