1753823 Members
8878 Online
108805 Solutions
New Discussion юеВ

Re: query on tar command

 
SOLVED
Go to solution
ng_7
Regular Advisor

query on tar command

hi, friends

Can please tell me how to extract tar backup by extracting files without extracting leading directories. For example, to recover
/prod/applprod/test.txt to /test/applprod, I want tar to extract only test.txt to /test/applprod instead of the whole directory structure /prod/applprod/test.txt

thank you
16 REPLIES 16
Ninad_1
Honored Contributor

Re: query on tar command

Hi,

To be able to extract to a location different than from where you took the backup usingtar - needs backup to be taken with relative path names rather than absolute path names.
Thus if you have take tar like e.g.
tar cvf xyz.tar ./prod/*
Only then you can goto some other directory and extract it there using tar xvf .

Next - if you want to extract only a particular file - then as er your e.g.
cd /test/applprod
tar xvf xyz.tar /prod/applprod/test.txt

But again as I said earlier only if you have taken backup using relative names, then would you be able to extract it to /test/applprod , not otherwise.

Regards,
Ninad
skt_skt
Honored Contributor

Re: query on tar command

These are the limits when we backup the systems using unix commands. It would be been eaiser if there are external backup software/tools like netbackup or DP(data protector)..
Steven Schweda
Honored Contributor

Re: query on tar command

Dennis Handly
Acclaimed Contributor
Solution

Re: query on tar command

No need to relative paths or foreign devil tools.
You can use the POSIX standard pax(1). After decades I finally set up a script to use pax -s to rename the files.
Ninad_1
Honored Contributor

Re: query on tar command

Hi,

Sorry, probably I did not interpret you question correctly.
As Dennis suggested, you can use pax to extract the file you want and to a directory other than from where you backed it up, as below
pax -r -d -s ',/prod/applprod/,/test/applprod/,' -f xyz.tar /prod/applprod/test.txt

Regards,
Ninad
tsf_1
Frequent Advisor

Re: query on tar command

The ways/options available when recover is very much depends on how you backup.

Example 1 (can restore to other directory; no full path is needed as backup is not taken at full path)
During backup
# cd /home/user1
# tar cvf /dev/rmt/0m color1
During recover
# cd /tmp
# tar xvf /dev/rmt/0m color1

Example 2 (restore required full path as backup was taken in full path)
During backup
# tar cvf /dev/rmt/0m /home/user1/color1
During restore
# tar xvf /dev/rmt/0m /home/user1/color1

Hope this make a clear difference.
be willing to do, be happy to bear
Dennis Handly
Acclaimed Contributor

Re: query on tar command

>tsf: The ways/options available when recover is very much depends on how you backup.

This is true if you just use the standard tar. But as I said, you can tar with absolute path and use pax to restore to any path.

# cd /home/user1
# tar cvf /dev/rmt/0m color1

You can also optimize this by:
# tar cvf /dev/rmt/0m -C /home/user1 color1
(Multiple -C paths are possible.)
ng_7
Regular Advisor

Re: query on tar command

hi, I don't know what is the mistake i made, please advise me on below.

1. I do the backup on *.tmp
on /prod/applprod/prodora/8.0.6
- cd /prod/applprod/prodora/8.0.6
- tar -cvf /u01/123.tar -i *.tmp

2. I verify my backup by :
tamcoapp:/u01# tar -tvf /u01/123.tar
rw-rw-rw- 0/3 0 Jul 30 10:02 2007 alson.tmp
rwxr-xr-x 108/102 2251 Jun 11 11:54 2002 forms60.csh.tmp
rwxr-xr-x 108/102 2796 Jun 11 11:54 2002 forms60.sh.tmp
rwxr-xr-x 108/102 5565 Jun 11 11:54 2002 forms60_server.tmp
rwxr-xr-x 108/102 2371 Jun 11 11:54 2002 reports60.csh.tmp
rwxr-xr-x 108/102 2897 Jun 11 11:54 2002 reports60.sh.tmp
rwxr-xr-x 108/102 3139 Jun 11 11:54 2002 reports60_server.tmp

2. then I restore it in u01/applhprod/hprodora/8.0.6

app:#/u01/applhprod/hprodora/8.0.6/pax -r -d -s ',/prod/applprod/prodora/8.0.6/,/u01/applhprod/hprodora/8.0.6/,' -f /u01/123.tar /prod/applprod/prodora/8.0.6/*.tmp


And I get this error message :

tamcoapp:/u01/applhprod/hprodora/8.0.6# a/8.0.6/alson.tmp not found in archive <
pax: /prod/applprod/prodora/8.0.6/alson.tmp not found in archive
pax: /prod/applprod/prodora/8.0.6/forms60.csh.tmp not found in archive
pax: /prod/applprod/prodora/8.0.6/forms60.sh.tmp not found in archive
pax: /prod/applprod/prodora/8.0.6/forms60_server.tmp not found in archive
pax: /prod/applprod/prodora/8.0.6/reports60.csh.tmp not found in archive
pax: /prod/applprod/prodora/8.0.6/reports60.sh.tmp not found in archive
pax: /prod/applprod/prodora/8.0.6/reports60_server.tmp not found in archive
Steven Schweda
Honored Contributor

Re: query on tar command

The shell expands this wildcard, because it's
not quoted:

/prod/applprod/prodora/8.0.6/*.tmp

Try quoting it, or, better yet, leave it out.
Everything in your archive is a *.tmp. If
you specify no pattern, you should get
everything in the archive, which would seem
to be what you want.