Friday, October 07, 2005

How do I restore to a different location the contents of a tarfile created with absolute pathnames

Subject: 10.4) How do I restore to a different location the contents of a
tarfile created with absolute pathnames?

Tarfiles should not normally be created with absolute pathnames, only
with relative pathnames. Do not type "tar c /path/name" to create a tar
archive, type "(cd /path; tar c name)" instead.

Note: if you do "(cd /path/name; tar c .)", you will indeed avoid absolute
pathnames, but beware that the tarfile created may silently overwrite the
permissions of the current directory when unpacked. That's OK if you
unpack it via:
"mkdir name; cd name; tar xf /my/tarfile.tar
That's not OK if you unpack it via:
"cd /tmp; tar xf /my/tarfile.tar" -- you will change the permissions
of /tmp.

If you do have an archive created with absolute pathnames, you can unpack
it in a different location by using GNU's version of tar, which will strip
off the leading /.

Alternatively, you can use pax to strip off the leading /, as follows:

pax -r -s '/^\///' <abspath.tar

Or you can use chroot and a statically linked version of tar, as follows:

cp /usr/sbin/static/tar /tmp/restore
# cd /tmp/restore
# cat abspath.tar | chroot /tmp/restore /tar xf -

0 Comments:

Post a Comment

<< Home