1830862 Members
2568 Online
110017 Solutions
New Discussion

Re: TAR RESTORE ISSUE

 
Omprakash_2
Frequent Advisor

TAR RESTORE ISSUE

Hi,

How can we restore a file from the tape, to different location.
For Eg:-
#tar -xvf /dev/rmt/0m /etc/hosts. While giving this command it will extract in the same location i.e, /etc/hosts (overwrite).

Note: I have already check by giving #tar -tvf -tvf /dev/rmt/0m.

I required this file to extract in different location. Can any one help me for this senario...
10 REPLIES 10
Suraj K Sankari
Honored Contributor

Re: TAR RESTORE ISSUE

Hi,
Did you tried like this
go to a perticular directory suppose /tmp/dump

cd /tmp/dump
then give tar -xvf /dev/rmt/0mn .

Suraj
Steven Schweda
Honored Contributor

Re: TAR RESTORE ISSUE

Step one would be to use a relative path
(like "etc/hosts") instead of an absolute
path (like "/etc/hosts") when creating the
archive.

If you're stuck with an archive which was
created with absolute paths, then you can
use "pax" or GNU "tar". A Forum search for
keywords like:
pax gnu tar absolute relative
should find several examples of each.


On a bad day, you could probably find a way
to use chroot, too, but that wouldn't be my
first choice.
Omprakash_2
Frequent Advisor

Re: TAR RESTORE ISSUE

Hi suraj,

I have tried by cd /tmp, but its extract only on the same location.
Sherif A. Louis
Valued Contributor

Re: TAR RESTORE ISSUE

cd /tmp
tar xvf /dev/rmt/0m etc/hosts

use a RELATIVE path not an absolute
Steven Schweda
Honored Contributor

Re: TAR RESTORE ISSUE

> I have tried by cd /tmp, but its extract
> only on the same location.

Not amazing, if you have an archive with
absolute paths.

> tar xvf /dev/rmt/0m etc/hosts
>
> use a RELATIVE path not an absolute

This might be useful advice when the archive
is being created, but did you actually try
that "tar" command, or are you only guessing
that it will do something useful?

For some potentially less useless advice:

http://www.gnu.org/software/tar/manual/html_node/transform.html#SEC108
T G Manikandan
Honored Contributor

Re: TAR RESTORE ISSUE

YOu can use pax command for this like
if you want to restore into /opt

# cd /opt
# pax -r -s '|/etc/*||' -f /dev/rmt/0m

When you use gnu tar it strips of the leading slash so which always becomes relative on extraction.
T G Manikandan
Honored Contributor

Re: TAR RESTORE ISSUE

to be specific

#pax -r -s '|/etc/hosts||' -f /dev/rmt/0m
V. Nyga
Honored Contributor

Re: TAR RESTORE ISSUE

Hi,

you can also use 'backup and recovery' in 'sam'.
First backup in sam.
Then, with an interactive recovery you can choose a different path.

HTH
Volkmar
*** Say 'Thanks' with Kudos ***
Steven Schweda
Honored Contributor

Re: TAR RESTORE ISSUE

> When you use gnu tar it strips of[f] the
> leading slash so which always becomes
> relative on extraction.

It does? Can you demonstrate this?
Steven Schweda
Honored Contributor

Re: TAR RESTORE ISSUE

> It does? Can you demonstrate this?

Ooh. You're right. More manual reading
required.

dy # gtar cfv test.tar /root/sp.c
gtar: Removing leading `/' from member names
/root/sp.c

dy # gtar tfv test.tar
-rw-r--r-- root/sys 103 2008-10-22 11:08 root/sp.c

There's an option, if you really want it done
the dangerous way:

dy # gtar --absolute-names -c -v -f test2.tar /root/sp.c
/root/sp.c

dy # gtar tfv test2.tar
gtar: Removing leading `/' from member names
-rw-r--r-- root/sys 103 2008-10-22 11:08 /root/sp.c

And yes, without "--absolute-names", it
_will_ strip the leading slash when it
extracts/restores the archive.

Around here:

dy # uname -a
HP-UX dy B.11.11 U 9000/785 2012616114 unlimited-user license

dy # gtar --version
tar (GNU tar) 1.18
[...]

Well, that was educational.