[net.unix-wizards] Need help preserving permissions when using tar?

ron@men1.UUCP (Ron Flax) (07/02/85)

Does anyone know of a way to preserve file and directory permissions
and ownerships when using tar?

When I archive the files I have umask set at 0, and say I tar a directory
or two.  When I go to restore these directories/files, the files seem to 
be in tact but the directories are of course 0777.  If I use a umask of 
say 0022 then the directory is set at 0755 as is expected with that umask
setting, but the files are then also masked accordingly.

I guess what I want is to have my cake and eat it too? Is this possible?

The reason this comes up is that I just spent the better part of today, 
tar'ing my old small disk to turn around and restore everything to a new
larger disk, well I had to fix every G*d Damned directory by hand!


--
Ron@men1	(Ron Flax)
MTACCS Engineering Network
..!{seismo,prometheus,prcrs,cal-unix}!men1!ron

gnu@sun.uucp (John Gilmore) (07/16/85)

> Does anyone know of a way to preserve file and directory permissions
> and ownerships when using tar?

The tar in 4.2bsd (and maybe other Berkeley releases) puts directory
permissions into the tar file and creates the directories with those
permissions when you read the tar file.

guy@sun.uucp (Guy Harris) (07/17/85)

> The tar in 4.2bsd (and maybe other Berkeley releases) puts directory
> permissions into the tar file and creates the directories with those
> permissions when you read the tar file.

It only creates the directories with those permissions if you use the "p"
flag when reading the tape in.  (It creates files with the permissions from
the tape under all circumstances, but it proceeds to change the mode of the
file from the mode it was created with to the very same mode if you specify
the "p" flag!  To add a bit of confusion, the System V Release 2 "tar" has
an "o" flag - conflicting, alas, with the Berkeley "o" flag which tells it
*not* to put directories on the tape - which tells it not to change the
owner and group owner of the files to the values from the tape.  I guess
this wasn't in V7 because only the super-user can change the ownership of a
file.  The only reason I can assume for why it wasn't changed in the first
USG release it was on is that none of the people using USG releases use
"tar" - they use "cpio" instead.  Having all files read in from a "tar" (or
"cpio"!) file from another site owned by whatever random users have the same
numeric user ID as the owner of the file at that site gets old *real*
quickly...

	Guy Harris

jtkohl@mit-priam.UUCP (John T. Kohl) (07/17/85)

In article <2424@sun.uucp> gnu@sun.uucp (John Gilmore) writes:
>> Does anyone know of a way to preserve file and directory permissions
>> and ownerships when using tar?
>
>The tar in 4.2bsd (and maybe other Berkeley releases) puts directory
>permissions into the tar file and creates the directories with those
>permissions when you read the tar file.

But it only sets ownerships if the user who extracts is root.


-- 
The opinions expressed above, if any, are mine.

John T. Kohl
	UUCP: ...!decvax!mit-athena!jtkohl
	ARPA: jtkohl@mit-athena.ARPA

robert@gitpyr.UUCP (Robert Viduya) (07/19/85)

> > Does anyone know of a way to preserve file and directory permissions
> > and ownerships when using tar?
> 
> The tar in 4.2bsd (and maybe other Berkeley releases) puts directory
> permissions into the tar file and creates the directories with those
> permissions when you read the tar file.

Unfortunately, this is only halfway true.  A couple of months ago I was
doing some development on a project using RCS.  RCS stored all it's files
in a subdirectory (called RCS) with all the files set to read-only to
everyone (including me).  Well, I did a number of archives (update archive,
not a full archive) to tape using tar about once a week.  When I finished
the project, I did one last archive and removed the whole directory off
disk.  Well, I had to upgrade this project about a month ago and so I
started to extract the directory from the tar tape.  Tar extracted the first,
and oldest copy of the directory and then proceeded to fail with every
other copy because it refused to write over a read-only file.  I was left
with the oldest version of the project.  I eventually managed to get the
latest version loaded (through the wonders of Berkeley job control), but
tar should at least have a flag that tells it to unconditionally reload
files regardless of what the permission modes on the disk copy are.

				robert
-- 
Robert Viduya							01111000
Georgia Institute of Technology

...!{akgua,allegra,amd,hplabs,ihnp4,masscomp,ut-ngp}!gatech!gitpyr!robert
...!{rlgvax,sb1,uf-cgrl,unmvax,ut-sally}!gatech!gitpyr!robert

guy@sun.uucp (Guy Harris) (07/22/85)

> >The tar in 4.2bsd (and maybe other Berkeley releases) puts directory
> >permissions into the tar file and creates the directories with those
> >permissions when you read the tar file.
> 
> But it only sets ownerships if the user who extracts is root.

That's because the "chown" system call is privileged in V7 and 4.xBSD and
"tar" doesn't run set-UID "root".  Be grateful; the "tar" in System III will
set ownerships under any circumstances because the "chown" system call isn't
privileged.  This is lousy because you may have gotten a "tar" tape from
another site, and you really don't want the files owned by whatever random
person has the same user ID as the person who owned the files on the
original machine.  The System V "tar" has a "o" flag (which, alas, conflicts
with the 4.xBSD "tar"s "o" flag, which tells it not to put directory
information on the tape) that tells it not to change the ownership of files.

	Guy Harris

mats@dual.UUCP (Mats Wichmann) (07/29/85)

> 
> That's because the "chown" system call is privileged in V7 and 4.xBSD and
> "tar" doesn't run set-UID "root".  Be grateful; the "tar" in System III will
> set ownerships under any circumstances because the "chown" system call isn't
> privileged.  This is lousy because you may have gotten a "tar" tape from
> another site, and you really don't want the files owned by whatever random
> person has the same user ID as the person who owned the files on the
> original machine.  The System V "tar" has a "o" flag (which, alas, conflicts
> with the 4.xBSD "tar"s "o" flag, which tells it not to put directory
> information on the tape) that tells it not to change the ownership of files.
> 
> 	Guy Harris

The sensible thing to do on Sys V seems to be to modify tar so
that only root gives files away, since only root is likely to
be loading tapes with stuff to be owned by someone else.
(Whaddaya mean, not everyone has the source?)

Mats Wichmann