LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-10-2011, 09:59 AM   #1
brent21090
LQ Newbie
 
Registered: Feb 2011
Posts: 3

Rep: Reputation: 0
Moving Data from Tape to System directory


I need help writing a script that will copy everything from tape to system directory. I have a Linux box with 3 TB of Hardware space. I am using the following commands
1) mt f /dev/st0 rewind
2) tar xvf /dev/st0
3) tar xvf /dev/st0 fsf 1 (Using this to move to the next segment of the tape)
and then
4) tar -xvf/dev/st0

I keep repeating steps 3 and 4.
Thank you for your help
 
Old 02-10-2011, 10:12 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,029

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
Code:
while [ 1 ]
do
 ...
done
 
Old 02-10-2011, 10:26 AM   #3
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,606

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Quote:
Originally Posted by brent21090 View Post
I need help writing a script that will copy everything from tape to system directory. I have a Linux box with 3 TB of Hardware space. I am using the following commands
1) mt -f /dev/st0 rewind
2) tar -xvf /dev/st0
3) tar -xvf /dev/st0 fsf 1 (Using this to move to the next segment of the tape)
and then
4) tar -xvf/dev/st0

I keep repeating steps 3 and 4.
Thank you for your help
Hi,

do you actually mean
Code:
mt -f /dev/st0 fsf 1
instead of
Code:
tar -xvf /dev/st0 fsf 1  # I *think* this is wrong
Anyway, I do not have a tape drive. So I will have to make some assumptions here, i.e. if the last record has been read then
Code:
mt -f /dev/st0 fsf 1
will exit with error-status 2.

So here goes:
Code:
#!/bin/bash
mt -f /dev/st0 rewind
if [[ $? == 0 ]]; then
   while [[ $? == 0 ]];do
      tar -xvf /dev/st0
      mt -f /dev/st0 fsf 1 # Using this to move to the next segment of the tape
   done
else
   echo 'Error: Could not rewind device: /dev/st0'
fi
UNTESTED! Obviously, since I do not have a tape drive!

And here is something to read about positional parameters if you have more than one tape device or the device name changes for some reason.
http://tldp.org/LDP/abs/html/othertypesv.html

You could then rewrite the script to take the device name as parameter.

Last edited by crts; 02-10-2011 at 12:32 PM.
 
Old 02-10-2011, 11:47 AM   #4
brent21090
LQ Newbie
 
Registered: Feb 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Hi CRTS
Yes I actually meant mt -f /dev/st0 fsf 1
Question: I am not clear as to what '[[$? ==0]];' means.
I have one tape device.
Since this is my 1st time using Linux commands what does 'if' mean at the end of the script you provided?
Thanks for your help.
 
Old 02-10-2011, 12:32 PM   #5
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,606

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Quote:
Originally Posted by brent21090 View Post
Hi CRTS
Yes I actually meant mt -f /dev/st0 fsf 1
Question: I am not clear as to what '[[$? ==0]];' means.
Ok, first of all you use a "funny" sign to pass the options. It is supposed to be a '-' (minus) when specifying options. Yours was longer. I copy+pasted your text and so I had that error in the above script, too. But I corrected that now.

As for your questions:
Code:
[[$? ==0]]
This is not correct. The spaces are important; otherwise you will get an error. As for the meaning of
Code:
[[ $? == 0 ]]
  ^       ^ spaces are important
This is simply a test. The '$?' holds the exit value of the last executed command. A value of 0 usually indicates that the command succeeded. We check this value to determine if the mt command succeeded. I assume that it will set an exit status of 2 if there are no more files on the tape. See the manpage of mt for that:
Code:
man mt
So the while-loop will keep executing until mt has read the last file.
The test-condition for the loop is
Code:
[ $? == 0 ]
This is nearly the same as '[[ $? == 0 ]]'. Thinking about it, this test should also be in double brackets '[['. They are more 'robust' then the single ones. I corrected that, too.
Quote:
what does 'if' mean at the end of the script you provided?
Thanks for your help.
That is NOT a mistyped 'if' but it is indeed a 'fi'. It simply indicates the end of the 'if' construct. Its c++ equivalent, e.g, would be the closing curly brace '}'.

Last edited by crts; 02-10-2011 at 12:34 PM.
 
Old 02-11-2011, 03:45 PM   #6
brent21090
LQ Newbie
 
Registered: Feb 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Running the Script

Resolved. Thanks

Last edited by brent21090; 02-11-2011 at 05:28 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
backing up 50 GB data on 40GB tape ? zivota Red Hat 3 09-06-2006 12:46 PM
The postgresql data directory content in the pgsql directory is lost (empty data dir) kisembo Linux - Software 1 02-13-2006 02:11 PM
tape data recovery vetrimani Linux - Hardware 5 12-28-2005 11:59 AM
Restoring data from tape backups enygma Linux - General 8 11-11-2004 02:29 PM
copying/moving stalls when moving a lot of data to a usb stick =X= Linux - Hardware 10 07-30-2004 06:29 AM


All times are GMT -5. The time now is 05:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration