[comp.unix.questions] extracting tar files with absolute pathnames relatively

todd@cfa250.harvard.edu (Todd Karakashian) (04/21/89)

Hi,

I am in posession of tapes containing tarfiles with absolute
pathnames.  What I would like to do is to extract these files into a
different tree structure than they were tarred from.  Thus, the
tarfile /usr/foo/file should go into the disk pathname /temp/file.  I
have been unable to find a way to do this -- does anyone know how?

I am running SunOS 3.5.  I apologize if this is too simple a question.
It seems like a simple enough concept, but I haven't been able to figure
out how to do it.

Thanks in advance!

			Todd Karakashian
	
			Internet: todd@cfa205.harvard.edu
			Bitnet: todd@cfa  
			Phone: (617) 495-7168

mjs@mentor.cc.purdue.edu (Mike Spitzer) (04/21/89)

In article <1501@cfa205.cfa250.harvard.edu> todd@cfa250.harvard.edu (Todd Karakashian) writes:
>I am in posession of tapes containing tarfiles with absolute
>pathnames.  What I would like to do is to extract these files into a
>different tree structure than they were tarred from.  Thus, the
>tarfile /usr/foo/file should go into the disk pathname /temp/file.  I
>have been unable to find a way to do this -- does anyone know how?
>
>I am running SunOS 3.5.  I apologize if this is too simple a question.

Without modifying tar, the easiest was to accomplish this is to use
chroot.  Lucky for you, SunOS (at least 4.0... I think that 3.? had
this too) has a chroot(8) command. Try something like this (you'll
have to be root):

	mkdir /tmp/newroot
	cp tarfile /tmp/newroot
	chroot /tmp/newroot tar xf /tarfile

If you don't have the chroot program, it's pretty simple to write.
See the chroot(2) man page for more information.

--
Michael J. Spitzer		Purdue University Computing Center
mjs@mentor.cc.purdue.edu	pur-ee!mentor.cc.purdue.edu!mjs

ray3rd@ssc-vax.UUCP (Ray E Saddler III) (04/22/89)

In article <1501@cfa205.cfa250.harvard.edu>, todd@cfa250.harvard.edu (Todd Karakashian) writes:
> I am in posession of tapes containing tarfiles with absolute
> pathnames.  What I would like to do is to extract these files into a
> different tree structure than they were tarred from.  Thus, the
> tarfile /usr/foo/file should go into the disk pathname /temp/file.  I
> have been unable to find a way to do this -- does anyone know how?

I've encountered the same scnerio and have used this trick:

Make a link (symbolic in my instance) in the /usr directory.  The
link name would be 'foo', and would simply point to /temp.

It works quite nicely.


-- 
Ray E. Saddler III       |    __  __ __       __ |          UseNet
Boeing Aerospace         |   / / / //   //| //   | uw-beaver!ssc-vax!ray3rd
P.O. Box 3999 m.s. 3R-05 |  /-< / //-  // |// _  |         PhoneNet
Seattle, Wa.  98124  USA | /__//_//__ //  //__/  |      1+206-657-2824

Kemp@dockmaster.arpa (04/22/89)

Todd,
  I don't know of any good way to restore files from a tar tape that was
created with absolute pathnames, but I do have a couple of bad ways (if
you can become superuser, or get the cooperation of one).

 1) If you want to extract only files rooted in a directory that does
not exist on your system, then create a symbolic link to where you want
them to go.  For example if you don't currently have /usr/bin/foo, and
you want to restore files /usr/bin/foo/...  into /temp/foo/...,

 cd /usr/bin
 ln -s /temp/foo

    Or if /temp/foo is to be in the same partition as /usr/bin/foo, you
could just restore the tape as is, and then

 cd /usr/bin
 mv foo /temp/foo

  2) If /usr/bin/foo already exists and you don't want to mess with it,
or if the tape contains lots of different first level directories, you
could chroot to /tmp, restore the tape, and then mv the files to where
you want them.


 DISCLAIMER: I have used method #1, but not #2.

 MORAL:  **Don't** write tar tapes with absolute pathnames, unless you
are distributing system software.

     Dave Kemp

rg@psgdc (Dick Gill) (04/23/89)

In article <2620@ssc-vax.UUCP> ray3rd@ssc-vax.UUCP (Ray E Saddler III) writes:
>In article <1501@cfa205.cfa250.harvard.edu>, todd@cfa250.harvard.edu (Todd Karakashian) writes:
>> I am in posession of tapes containing tarfiles with absolute
...
>
>Make a link (symbolic in my instance) in the /usr directory.  The
>link name would be 'foo', and would simply point to /temp.
>
>It works quite nicely.
>
This sounds to simple and straightforward to be true. Walk me
through this step by step, please.

Thanks.


-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dick Gill              Professional Solutions Group          ..uunet!psgdc!rg
The quality of the circus here in Washington depends on the clowns you elect.

ked@garnet.berkeley.edu (Earl H. Kinmonth) (04/23/89)

In article <2620@ssc-vax.UUCP> ray3rd@ssc-vax.UUCP (Ray E Saddler III) writes:
>In article <1501@cfa205.cfa250.harvard.edu>, todd@cfa250.harvard.edu (Todd Karakashian) writes:
>> I am in posession of tapes containing tarfiles with absolute
>> pathnames.  What I would like to do is to extract these files into a
>> different tree structure than they were tarred from.  Thus, the
>> tarfile /usr/foo/file should go into the disk pathname /temp/file.  I
>> have been unable to find a way to do this -- does anyone know how?

My version of GNU tar will do this very simply.  It has a -Pnn option
where nn is the number of path elements to strip off.  Although this
program was originally written to make tar archives under MSDOS, it will
also run under UNIX.  I use it on a Sun for precisely the task you
describe.

pdtar is available from the author for non-commercial, non-military uses,
in SCO Xenix, Ultrix, BSD UNIX, and MSDOS versions.

Earl H. Kinmonth
History Department
University of California, Davis
916-752-1636 (voice, fax [2300-0800 PDT])
916-752-0776 secretary

ucbvax!ucdavis!ucdked!cck

les@chinet.chi.il.us (Leslie Mikesell) (04/23/89)

In article <1501@cfa205.cfa250.harvard.edu> todd@cfa250.harvard.edu (Todd Karakashian) writes:

>I am in posession of tapes containing tarfiles with absolute
>pathnames.  What I would like to do is to extract these files into a
>different tree structure than they were tarred from.

GNUtar and PAX (both free but not public domain) will do this.  GNUtar
just strips the leading / if present, PAX lets you do a regex substitution
on the pathname.
Otherwise you have to set up a fake environment and chroot into it.

Les Mikesell

jpr@dasys1.UUCP (Jean-Pierre Radley) (04/28/89)

In article <1501@cfa205.cfa250.harvard.edu> todd@cfa250.harvard.edu (Todd Karakashian) writes:
>I am in posession of tapes containing tarfiles with absolute
>pathnames.  What I would like to do is to extract these files into a
>different tree structure than they were tarred from.

I'm at a slight disadvantage, this site has not got the original message,
but:
	
	I take it you're running some version of tar which does not have
	the 'A' option? Stripping leading '/' from a restore is precisely
	what that option does.
-- 
Jean-Pierre Radley		Honi soit		jpr@dasys1.UUCP
New York, New York		qui mal			...!hombre!jpradley!jpr
CIS: 76120,1341			y pense			...!hombre!trigere!jpr

ray3rd@ssc-vax.UUCP (Ray E Saddler III) (04/28/89)

In article <202@psgdc>, rg@psgdc (Dick Gill) writes:
> In article <2620@ssc-vax.UUCP> ray3rd@ssc-vax.UUCP (Ray E Saddler III) writes:
> >In article <1501@cfa205.cfa250.harvard.edu>, todd@cfa250.harvard.edu (Todd Karakashian) writes:
> >> I am in posession of tapes containing tarfiles with absolute
> ...
> >
> >Make a link (symbolic in my instance) in the /usr directory.  The
> >link name would be 'foo', and would simply point to /temp.
> >
> >It works quite nicely.
> >
> This sounds to simple and straightforward to be true. Walk me
> through this step by step, please.
> 
> Thanks.

First of all, we are concerned with remapping absolute pathnames in
a 'tar' file (be it tape or diskfile) to a filesystem.

The slight of hand is in creating a false pathname in the filesystem
which will redirect the directory names in the tar image as they are
extracted to disk.

For the sake of example, my home directory on our VAX is
/user4/ray3rd, but on my workstation, the home directory is
/usr/user/ray.  If I create a tar file on the VAX, I'll need to
create a bogus /user4/ray3rd on my workstation if I want to extract
the files directly onto my home directory.

Sample VAX tarfile:

rwxr-xr-x1221/737      0 Jun 29 09:09 1988 /user4/ray3rd/block/
rw-r--r--1221/737     96 Jun 29 09:08 1988 /user4/ray3rd/block/Makefile
rw-r--r--1221/737   1401 Jun 29 09:08 1988 /user4/ray3rd/block/block.c
rw-r--r--1221/737  17112 Jun 29 09:08 1988 /user4/ray3rd/block/data.c

Now I go to my workstation and:

cs2860 ray> su root
Password: 

cs2860 ray> mkdir /user4

cs2860 ray> ln -s /usr/user/ray /user4/ray3rd

cs2860 ray> chown ray /user4/ray3rd

cs2860 ray> ls -al /user4
total 3
drwxrwxrwx  2 root          512 Apr 27 09:57 .
drwxr-xr-x 16 root         1024 Apr 27 09:53 ..
lrwxrwxrwx  1 ray            13 Apr 27 09:57 ray3rd -> /usr/user/ray

cs2860 ray> cd /user4/ray3rd

cs2860 ray> pwd
/usr/user/ray

cs2860 ray> tar -xvf /tmp/sampletar
x /user4/ray3rd/block/Makefile, 96 bytes, 1 tape blocks
x /user4/ray3rd/block/block.c, 1401 bytes, 3 tape blocks
x /user4/ray3rd/block/data.c, 17112 bytes, 34 tape blocks

cs2860 ray> ls -al /user4/ray3rd/block/* /usr/user/ray/block/*
-rw-r--r--  1 1221           96 Jun 29  1988 /user4/ray3rd/block/Makefile
-rw-r--r--  1 1221         1401 Jun 29  1988 /user4/ray3rd/block/block.c
-rw-r--r--  1 1221        17112 Jun 29  1988 /user4/ray3rd/block/data.c
-rw-r--r--  1 1221           96 Jun 29  1988 /usr/user/ray/block/Makefile
-rw-r--r--  1 1221         1401 Jun 29  1988 /usr/user/ray/block/block.c
-rw-r--r--  1 1221        17112 Jun 29  1988 /usr/user/ray/block/data.c

And there we have it.  The next step would be to CHange OWNership of
the new files to 'ray' since I have different UID's on each system.

Simple, eh?

[Sorry to use so much bandwidth, but it seemed convenient to
 followup rather than directly mail to him!]
-- 
Ray E. Saddler III       |    __  __ __       __ |          UseNet
Boeing Aerospace         |   / / / //   //| //   | uw-beaver!ssc-vax!ray3rd
P.O. Box 3999 m.s. 3R-05 |  /-< / //-  // |// _  |         PhoneNet
Seattle, Wa.  98124  USA | /__//_//__ //  //__/  |      1+206-657-2824

ked@garnet.berkeley.edu (Earl H. Kinmonth) (04/28/89)

The simplest solution to this is to get a copy of pdtar from me.  pdtar
has several options to change file names.  -A simply removes the first
"/" to give a relative path name.  -Pnn allows specifying how many "/dir"
elements are to be removed.

pdtar runs under SCO Xenix, MSDOS, 2.9-4.3 UNIX, etc.

Disclaimer:	Programming is too important to leave to programmers!

Earl H. Kinmonth
History Department
University of California, Davis
916-752-1636 (voice, fax [2300-0800 PDT])
916-752-0776 secretary

ucbvax!ucdavis!ucdked!cck

ric@Apple.COM (Ric Urrutia) (04/29/89)

In article <202@psgdc> rg@psgdc.UUCP (Dick Gill) writes:
>In article <2620@ssc-vax.UUCP> ray3rd@ssc-vax.UUCP (Ray E Saddler III) writes:
>>In article <1501@cfa205.cfa250.harvard.edu>, todd@cfa250.harvard.edu (Todd Karakashian) writes:
>>> I am in posession of tapes containing tarfiles with absolute
>...
>>
>>Make a link (symbolic in my instance) in the /usr directory.  The
>>link name would be 'foo', and would simply point to /temp.
>>
>>It works quite nicely.
>>
>This sounds to simple and straightforward to be true. Walk me


The way that I do is is by using chroot(1m) to change my root directory for the tar command.  For example:  If I have a tar tape with absolute pathnames and 
wish to read them into a new directory, I can do the following:
	mkdir /new
	cp /bin/sh /new
	cp /usr/bin/tar /new
	chroot /new sh (invoke sh and make /new the new root)
	tar xvf ????
	exit the temporary shell by hitting ctrl/d (this puts you back to normal)
	rename your directory