LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 08: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, 09:12 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

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

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
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 11:32 AM.
 
Old 02-10-2011, 10: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, 11:32 AM   #5
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
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 11:34 AM.
 
Old 02-11-2011, 02: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 04:28 PM.
 
  


Reply



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 11:46 AM
The postgresql data directory content in the pgsql directory is lost (empty data dir) kisembo Linux - Software 1 02-13-2006 01:11 PM
tape data recovery vetrimani Linux - Hardware 5 12-28-2005 10:59 AM
Restoring data from tape backups enygma Linux - General 8 11-11-2004 01:29 PM
copying/moving stalls when moving a lot of data to a usb stick =X¥®µ§= Linux - Hardware 10 07-30-2004 05:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:59 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
Open Source Consulting | Domain Registration