Solved

linux tape script will not run mt commands

Posted on 2008-10-20
11
1,117 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:javagair
  • 3
  • 3
  • 3
  • +1
11 Comments
 
LVL 76

Expert Comment

by:arnold
ID: 22764570
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.
0
 
LVL 14

Expert Comment

by:cjl7
ID: 22764718
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!
0
 
LVL 12

Expert Comment

by:TapeDude
ID: 22766178
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).
0
 

Author Comment

by:javagair
ID: 22769883
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
0
 
LVL 76

Expert Comment

by:arnold
ID: 22770041
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.)  
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 12

Expert Comment

by:TapeDude
ID: 22770238
Going to end of media (remember to use the non-rewinding device!) should be fine for appending to a tape.
0
 
LVL 12

Accepted Solution

by:
TapeDude earned 250 total points
ID: 22770361
The reason you're always at block 0 is because you're using the rewinding device (/dev/st0), which means every time you do an operation on the tape drive, it rewinds back to zero. Use /dev/nst0 when you don't want this to happen.

Also - just noticed you're using an Exabyte. I also see you're using it in variable block mode - just out of curiosity, try

    mt -f /dev/st0 setblk 10240

before your script, and use the -b 20 option in TAR. TAR usually defaults to 512 byte blocks, which, written in variable mode, will be sloooooowwwwww. So,

   tar -cvfb /dev/nst0 20 <files>


0
 
LVL 14

Expert Comment

by:cjl7
ID: 22773691
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
0
 

Author Comment

by:javagair
ID: 22882244
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
0
 
LVL 14

Assisted Solution

by:cjl7
cjl7 earned 250 total points
ID: 22883571
Well,

If you eject the tape it will rewind, that is the way it works.

The nst driver will only work if you are going to leave the tape in the drive.

In order to append to the tape you need to use the -r (--append) flag.

tar -rvf /dev/st0 /$NEWDATE

(if you eject the tape in between there is no need to use the nst driver)

//jonas
0
 

Author Closing Comment

by:javagair
ID: 31508107
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
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now