Operating System - HP-UX
1834346 Members
2152 Online
110066 Solutions
New Discussion

how to recovery the specify file?

 
SOLVED
Go to solution
kittyf
New Member

how to recovery the specify file?

I use the tar cvf command to backup one dir (tar cvf xxx.tar /xxx), and then i want to recovery the file /xxx/aaa/bbb.pl from the tar file to directory /yyy/aaa,
Can you help me?
8 REPLIES 8
Luc Bussieres_1
Trusted Contributor
Solution

Re: how to recovery the specify file?

Hi,

With the tar command you have used to create the tar archive (tar cvf xxx.tar /xxx) I see no easy way to extract it directly to /yyy/aaa.

Using the hpux version of tar command extracting the file "tar xvf xxx.tar /xxx/aaa/bbb.pl" will be keeping with the leading / so you won't be able to restore it elsewhere.

What I would suggest is to create the tar file with the following command:

cd /xxx; tar cvf ../xxx.tar .

This will create a tar file with all the files in the current directory which is now /xxx because of the cd.

Now to extract the file you just need to cd in the /yyy directory and then execute the following tar command:
tar xvf /xxx.tar ./aaa/bbl.pl

Note that now your files are prefixed with ./ instead of /xxx/ this way they could be extracted in the current directory.

regards
Luc
Bill Hassell
Honored Contributor

Re: how to recovery the specify file?

tar has a very crude interface and since it appears you saved the file with the leading / (ie, a full pathname), then tar will restore it exactly where it came from. There are some tricks using chroot but it isn't simple. If you have a choice, resave the file with:

cd /somedirectory
tar cvf /dev/rmt/XXX somefile

Now you can cd to a different directory and restore the file. tar provides no option to override the path saved with the file. You might to look at fbackup for a more fully featured backup tool.


Bill Hassell, sysadmin
steven Burgess_2
Honored Contributor

Re: how to recovery the specify file?

Hi

If you have created the tar file using absolute path names you will not be able to.

You can if you created the file in the relative directory

tar cvf /.

Regards

Steve
take your time and think things through
Michael Tully
Honored Contributor

Re: how to recovery the specify file?

Hi,

To recover a file from the tar tape:

If the tar archive has been backed using
absolute path names then tar will want to
restore it to the same directory.

You have two options.
1. Recover the file to a different system.

2. Move the existing file to another file
name and then recover it from tape using
# tar xvf /dev/rmt/0m /xxx/filename (substitute you your tape device)

If you must use 'tar' always backup with
using the ./directory instead of /directory

HTH
~Michael~
Anyone for a Mutiny ?
kittyf
New Member

Re: how to recovery the specify file?

Thanks all!
steven Burgess_2
Honored Contributor

Re: how to recovery the specify file?

Kittyf

I notice you are a new member of the forums

You can assign points to your replies by clicking on the 'assign points' tab

A pleasure to help you

Regards

Steve
take your time and think things through
Olav Baadsvik
Esteemed Contributor

Re: how to recovery the specify file?


Hi,

Here is a method you may use. It may be useful
if you receive a tar-tape written with
absolute path:
1- Logon as root
2- cd to directory : cd /newdir
3- cp tar to newdir
cp /sbin/tar /newdir
It is important that you copy
/sbin/tar and not /usr/bin/tar as
/sbin/tar does not depend on shared
libs
4- make sure about tar owner
and group : chown bin:bin tar
5- copy the device-file /dev/rmt/0m /newdir
6- chroot /newdir tar xvf 0m
will copy all files and the directory
structure to /newdir

Regards
Olav

RAC_1
Honored Contributor

Re: how to recovery the specify file?

If GNU tar helps in this regard? I had a tough time with tar taken with absolute path.

Regards,
There is no substitute to HARDWORK