Operating System - HP-UX
1748259 Members
3621 Online
108760 Solutions
New Discussion юеВ

re-directing tar extract to another directory

 
SOLVED
Go to solution
Kwahae_1
Regular Advisor

re-directing tar extract to another directory

Hi, Have created a tar file using:

# tar cvf /dev/rmt/0m /apps/xx

Now I am trying to restore the archive to a different directory so I get for example
/apps/ora/xx

What command should I use? Thnxs.
8 REPLIES 8
Robert-Jan Goossens_1
Honored Contributor

Re: re-directing tar extract to another directory

Hi,

It is easier if you create a tar file without the leading slash /.

# cd path
# tar cvf /dev/rmt/0m apps/xx

Regards,
Robert-Jan
James R. Ferguson
Acclaimed Contributor
Solution

Re: re-directing tar extract to another directory

Hi:

As Robert-Jan has already noted, don't use absolute paths in making your archive. If you have, or are presented this case, you can use 'pax' to rename the directory during recovery:

# cd /newapps
# pax -r -s '|/apps/*||' -f /dev/rmt/0m

...will recover the files as /newapps/xx

Regards!

...JRF...
Steven Schweda
Honored Contributor

Re: re-directing tar extract to another directory

A Forum search for, say,
GNU tar pax
should find many previous similar threads.
Kwahae_1
Regular Advisor

Re: re-directing tar extract to another directory

Hi Fergusson,

Will test this later but could you explain the role of the double pipe in the -s replacement string.

Thanks
James R. Ferguson
Acclaimed Contributor

Re: re-directing tar extract to another directory

Hi (again):

> Will test this later but could you explain the role of the double pipe in the -s replacement string.

The pipe symbol was simply my choice for a delimiter in the substitution expression. The "double pipe" reduces to "substitute nothing" meaning for "/apps/*" substitute an empty string.

Regards!

...JRF...
Ganesan R
Honored Contributor

Re: re-directing tar extract to another directory

Hi,

Whenever you want to restore into alternate location do not use absolute path. Instead you should go to that dir and take backup.

#cd /apps/xx
#tar cvf /dev/rmt/0m .

When you restore it will not create the path /apps/xx . You can restore it anywhere.
Best wishes,

Ganesh.
Kwahae_1
Regular Advisor

Re: re-directing tar extract to another directory

Thanks so much. The pax command works
Kwahae_1
Regular Advisor

Re: re-directing tar extract to another directory

pax worked.