Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tar command and permissions.

1,266 views
Skip to first unread message

brumik

unread,
Apr 15, 2012, 2:57:59 PM4/15/12
to

I have an interesting problem (this is on Sun tar)

If I do the following command as root user:

cd /

tar cvpf ./backup.tar ./export/home/user1

When I extract the tar file, the permissions of user1 are the same as
they were.

If I do the following command to just backup one file, and /export/
home/user1 does *not* exist

cd /
tar cvpf ./backup.tar ./export/home/user1/.ssh/authorized_keys

if I extract the tar file, export/home/user1 is owned by "root"

Only the actual file "authorized keys" was owned by user1.

Is there a way for tar to preserve sub directory permissions? or how
can I preserve permission of sub directory.


















Cydrome Leader

unread,
Apr 15, 2012, 4:26:05 PM4/15/12
to
I've never seen the p flag used before, so did man tar and saw this

-p (x mode only) Preserve file permissions. Attempt to restore
the
full permissions, including owner, file modes, file flags and
ACLs, if available, for each item extracted from the archive.
By
default, newly-created files are owned by the user running
tar,
the file mode is restored for newly-created regular files,
and
all other types of entries receive default permissions. If
tar
is being run by root, the default is to restore the owner
unless
the -o option is also specified.

so it's not valid for creating a tar file in the first place.

creat your tar without and see what happens without all the p flags.

brumik

unread,
Apr 15, 2012, 5:31:11 PM4/15/12
to
On Apr 15, 10:26 pm, Cydrome Leader <prese...@MUNGEpanix.com> wrote:
Yep I tried without the p flag and same result.

The issue seems to be when I tar up an individual file, and I extract
it on another system, if the sub directory does not exist on the other
system, it creates the subdir with root permissions (or the user that
extracted it). I guess this is beacuse the sub directory info is not
saved in the archive? Also when restoring it on another system, if
there is an existing subdir of the file owned by another user, it
overwrites the subdir permissions with the user that extracted it,
unless the -o flag is supplied. Not sure if there is a way for tar to
save the subdirectory information and save that as well.






Geoff Clare

unread,
Apr 16, 2012, 8:59:37 AM4/16/12
to
In order for tar to set ownership and permissions of higher-level
directories on extraction, there has to be a record of their ownership
and permissions in the tar archive. In the first case it was there
(because you archived everything below ./export/home/user1); in the
second case it was not, because the _only_ thing recorded in the tar
archive was the details of that one file.

To do what you want, you need to create a tar archive that has
records for ./export/home/user1, ./export/home/user1/.ssh and
./export/home/user1/.ssh/authorized_keys, but I don't think Sun tar
has any way to archive a directory without also archiving the files
below it.

Solution: use pax (with -d option) to create the archive instead.

pax -w -d -x ustar ./export/home/user1 ./export/home/user1/.ssh \
./export/home/user1/.ssh/authorized_keys > backup.tar

--
Geoff Clare <net...@gclare.org.uk>

brumik

unread,
Apr 16, 2012, 12:41:47 PM4/16/12
to
On Apr 16, 2:59 pm, Geoff Clare <ge...@clare.See-My-Signature.invalid>
wrote:
> Geoff Clare <netn...@gclare.org.uk>

Thanks I tried this out and it works - the permissions were retained.
I guess it could also be scriped. to avoid adding all the sub dir's
manually.
I have a file list of files I want to keep after a jumpstart restore.
so for example one entry in the file is
/export/home/user1/.ssh/authorized_keys
i guess I could script it to automatically add each subdir and pass it
to pax.




David Combs

unread,
May 28, 2012, 8:59:20 PM5/28/12
to
In article <6a8c585e-f95a-497a...@r9g2000yqd.googlegroups.com>,
I've heard (here on this group) that the program STAR (s-tar, for Schilly-tar,
I think) is really, really good. Try that, maybe.

Myself, I'm defeated by the ENORMOUS number of options and 50 page man-page,
so I've never tried it.

I do recall a *long* thread here some years ago about Sun tar vs Gnu tar, with,
I think, no clear winner: neither were perfect. Although I do believe that
in that thread, STAR did come out (way?) ahead.

---

Would sure be nice if star's man page had a section with only a few options
and a few examples of how to do just the most common things.


David


0 new messages