1827807 Members
3013 Online
109969 Solutions
New Discussion

Re: Question about tar

 
SOLVED
Go to solution
R.O.
Esteemed Contributor

Question about tar

Hi,

I´m doing a tar of the full system:

tar cvf /dev/st0 /

When I want to restore a single file in a directory different of the original, i.e:

cd /tmp
tar xvf /dev/st0 home/user1/myfile.txt

I have the file with the full path : /tmp/home/user1/myfile.txt

How can I restore the file directly in /tmp?

Th
"When you look into an abyss, the abyss also looks into you"
5 REPLIES 5
John Waller
Esteemed Contributor
Solution

Re: Question about tar

Sorry, in this case you can not do this. Because you created the tar by specifying / all files will restore under /. You can see this with tar tvf /dev/st0. To fix, change your command to create the tar so it performs tar cvf /dev/st0 ./ (make sure you do a cd / before you start), so when you extract a file it will recover relative to your pwd.
Vitaly Karasik_1
Honored Contributor

Re: Question about tar

I afraid you can't do this

Vitaly
Stuart Browne
Honored Contributor

Re: Question about tar

That's very odd.

Most versions of GNU's tar automatically strip the leading /, realising that it's a bad idea, and requires the '-P' switch (--absolute-paths) in order to forcibly save it.

Care to tell us what version of tar you are using ? (tar --version)

In any case, the quick solutions are these:

- use a chroot environment to restore it.
- change the backup routine to 'cd /;tar cvf /dev/st0 .' instead.

Hope this helps.
One long-haired git at your service...
Virgil Chereches_2
Frequent Advisor

Re: Question about tar

If you have gnu tar you can use -C option to put the file in a different directory (you change only the root directory, the directory structure will be recreated in the new directory instead of /).
You can also use pax (man pax) which is a very powerfull archive reader (read tar and cpio archives).
I hope that's help,
Virgil
Virgil Chereches_2
Frequent Advisor

Re: Question about tar

Sorry for the last post.
I didn't get very well the question.
Use option "-s" at pax! It would do the trick.
Virgil.