Operating System - HP-UX
1753767 Members
5394 Online
108799 Solutions
New Discussion юеВ

Re: Extract file in different directory using tar

 
SOLVED
Go to solution
Ashfak Mohmad Iqbal Sut
Occasional Advisor

Extract file in different directory using tar

Hi,

not able to extract file in different directory

e.g.
#cd /backup
#tar -cvf test.tar .
and then
#cd /test
#tar -xvf /backup/test.tar *

still its restoring files to /backup
10 REPLIES 10
SoorajCleris
Honored Contributor

Re: Extract file in different directory using tar

Hi,

After taking backup, what is tar -tvf saying??

Regards,
Sooraj
"UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity" - Dennis Ritchie
Ashfak Mohmad Iqbal Sut
Occasional Advisor

Re: Extract file in different directory using tar

# tar -tvf tapbak
rw-r--r-- 0/3 7 Dec 30 15:36 2009 /backup/tap/ta
#
rariasn
Honored Contributor

Re: Extract file in different directory using tar

Ashfak Mohmad Iqbal Sut
Occasional Advisor

Re: Extract file in different directory using tar

# pwd
/backup/test
# ls
doc1
# tar -cvf /backup/test/bak.tar .
a ./doc1 1 blocks
a ./bak.tar 0 blocks
# ls
bak.tar doc1
# cd /db_dev
# ls
lost+found pairsfile.txt rac_db_oh
# tar -xvf /backup/test/bak.tar *
# ls
lost+found pairsfile.txt rac_db_oh
#

please see the output
rariasn
Honored Contributor
Solution

Re: Extract file in different directory using tar

Hi,

Sample tar backup:

# cd /backup
# tar cfv test.tar ./*
# cd /test
# tar xvf /backup/test.tar .

rgs,
TTr
Honored Contributor

Re: Extract file in different directory using tar

You must not use the * at the end of the tar-extract command. The * tells tar to extract only files that match the ones in the current directory and there is no match with what you have in the tar file.
Ashfak Mohmad Iqbal Sut
Occasional Advisor

Re: Extract file in different directory using tar

wants to tar folder /db_test (space is not available on that filesystem

what is the method to create compressed file on different folder

eg :

Source folder : /db_test
targer folder : /db_dev

James R. Ferguson
Acclaimed Contributor

Re: Extract file in different directory using tar

Hi:

If you have a 'tar' archive that was made with absolute paths, use 'pax' to extract it to a different directory:

# pax -r -s '|/db_test/|/db_dev/|' -f /backup/test.tar

Regards!

...JRF...

Steven Schweda
Honored Contributor

Re: Extract file in different directory using tar

> You must not use the * [...]

That's the most important thing here.

> what is the method to create compressed
> file on different folder

Specify a different destination path in the
"tar" command? You did it for extraction
(with the defective "*"):

> #tar -xvf /backup/test.tar *

So you should be able to do it for creation:

cd /db_test
tar cf /db_dev/db_test.tar .

or:

cd /
tar cf /db_dev/db_test.tar db_test

depending on what you want in the archive.


> [...] use 'pax' [...]

Or GNU "tar". A Forum search for keywords
like, say,
gnu tar pax
should find many old threads on this topic.


Note that:

> #tar -cvf test.tar .

would create an archive containing relative
paths, while:

> # tar -tvf tapbak
> rw-r--r-- 0/3 7 Dec 30 15:36 2009 /backup/tap/ta

shows an archive containing an absolute path.
It looks as if you're doing too many
different things at one time, and getting
more confused than necessary.