1833777 Members
1886 Online
110063 Solutions
New Discussion

TAR Restore

 
SOLVED
Go to solution
Vogra
Regular Advisor

TAR Restore

Hi All!
again... When I try to restore files from a tape using tar command, I write:
tar xvf /dev/rmt/3m /local/name_of_file
than the file is restored in original location, but I need to put it in another local. How can I do?
Thanx.
We are spirits in the material world
4 REPLIES 4
MANOJ SRIVASTAVA
Honored Contributor

Re: TAR Restore

Hi Claudio

The tar extracts files back in the Path they were written as , ie in cae you used to back them up using tar cvf /dev/rmt /etc/passwd then it can restored only in /etc/passwd . There is one other way in case you can take the back up again take it as go to that directory and issue tar cvf /dev/rmt , so that the files are stored w/o the path , then you can restore it back by going to that directory and giving the xvf command.
Ofcourse you have the option to the move the files in case there is no other way.


Manoj Srivastava
Victor BERRIDGE
Honored Contributor

Re: TAR Restore

Hi,
There may be not much to do other than move the file yourself, because it seems you saved with absolute path...
The only solution I see is if the file already exists, is to move it somewhere else, then restore from the tape the one from TAR...

Good luck

Victor
Rodney Hills
Honored Contributor

Re: TAR Restore

You might be able to use the "pax" utility instead. It can read tar save tapes, and has the additional option of changing the name paths as it restores. example-

pax -r -f mysave.tar -s:^/usr/etc:/newpath:

It will still be an absolute path, but you can restore it to a different location!
There be dragons...
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: TAR Restore

Hi Claudio,

There is a way using pax which can read a tar archive. As had been mentioned, you should make your backups using relative paths to make life simpler.

For my example, I assume that I originally did a tar backup of /home which contains many directories.

e.g. tar cvf /dev/rmt/3m /home

Now lets say that I want just /home/cstephen (and all of his files) but not /home/user1, /home/user2, ...
AND
I want to restore cstephen's files to
/tmp/acs

This is very much like your situation. Here's the command:

pax -r -f /dev/rmt/3m -s ',/home/cstephen,/tmp/acs,' /home/cstephen

The effect of this command is to do an extract from device /dev/rmt/3m (which CAN be a previous tar or a cpio) and match the /home/cstephen files. The -s argument tells it to substitute /tmp/acs anytime it matches /home/cstephen. The commas are used as delimiters rather than the typical slash but you can choose other delimiters id comma's are embedded in your filenames.

Man pax for details.

This should do the trick, Clay

If it ain't broke, I can fix that.