1833843 Members
2241 Online
110063 Solutions
New Discussion

tar

 
Richard Buerger
New Member

tar

Can someone tell me how I can extract files from a tar created tape and put them to a different disk/directory than the disk/directory from where the files were originally located?
10 REPLIES 10
Thierry Poels_1
Honored Contributor

Re: tar

Hi,

not possible with tar if you used the full directory path when creating the tar backup.

tar -cf /dev/rmt/0m /tmp/file1
--> will be restored to /tmp/file1

cd /
tar -cf /dev/rmt/0m tmp/file1
--> can be restored below current working directory.


regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Sanjay_6
Honored Contributor

Re: tar

hi Richard,

If the files were archived with the leading edge, you cannot extract them to another directory.

Say you tarred using this format,

tar cvf /dev/rmt/0m /home

Now you cannot restore home to another directory. But if you tarred using this,

cd /
tar cvf /dev/rmt/0m home

you can restore it to any other directory, say /temp

cd /temp
tar xvf /dev/rmt/0m

You can also try the solution suggested by harry in the link below if you have backed up using absolute path,

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x38d6cf38d6bdd5118ff10090279cd0f9,00.html

Hope this helps.

Regds
Patrick Wallek
Honored Contributor

Re: tar

How were the files written to tape? Were they written using absolute paths (/somedir/somefile) or relative paths (somedir/somefile or ./somedir/somefile)? The answer depends.

If they were written with relative paths, then it is easy. You just cd to the dir you want to restore to and extract from the tape:

# cd /mydir
# tar -xvf /dev/rmt/0m somedir/somefile
or
# tar -xvf /dev/rmt/0m ./somedir/somefile

If the files were written to the tape using absolute paths, its a bit more difficult, but not impossible. You can try using pax for this ('man pax' for more info):

Here's an example from the pax man page:

To read the archive a.pax, with all files rooted in the directory /usr in the archive extracted relative to the current directory, enter:

# pax -r -s ',//*usr//*,,' -f a.pax
Helen French
Honored Contributor

Re: tar

Hi,

You need to use 'relative path' methord here. While backing up your data, you have to privide the relative paths. For eg: if you want to backup /home/dir1 and restore it to /usr1/dir1, then:
# cd /home/dir1
# tar -cvf /dev/rmt/0m .
# cd /usr1/dir1
# tar -xvf /dev/rmt/0m

This will restore the dir1 to the current directory. If you are using 'absolute path' for backing up data (tar -cvf /dev/rmt/0m /home/dir1), that will restore the data to the original location.

HTH,
Shiju
Life is a promise, fulfill it!
Marcin Wicinski
Trusted Contributor

Re: tar

Hi,
you can recover files from tar archive to relative path if the archive was created with relative path. Full path - to full path.
Later,
Marcin Wicinski
Helen French
Honored Contributor

Re: tar

Sanjay, it was Thierry ...not Harry ! =))

Shiju
Life is a promise, fulfill it!
Steve Steel
Honored Contributor

Re: tar

Hi

Confirm you cannot

Best is to copy the current contents to another place

restore tar

move restored files to new place

move back originals


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Darrell Allen
Honored Contributor

Re: tar

Hi Richard,

First use tar tvf to see if the tarfile was created with relative or absolute paths. If relative, cd to the directory you want and the files / dirs will be extracted relative to that directory.

If created with an absolute path, use pax (see Patrick's suggestion).

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Darrell Allen
Honored Contributor

Re: tar

Here's a link with more info:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x589bd5fab40ed6118ff40090279cd0f9,00.html

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Helen French
Honored Contributor

Re: tar