Operating System - HP-UX
1824971 Members
3265 Online
109678 Solutions
New Discussion юеВ

Can't preserve file ownership using tar

 
Phillip Latham_1
Occasional Contributor

Can't preserve file ownership using tar

When I 'un-tar' an archive that I created as root, the file ownership is not being preserved. The usernames and uid's exist on the 'target' system and if I do a tar -tvf of the archive the ownership is correctly recorded. However, when extracting, the ownership of files are reset to root (any directories seem to preserve their ownership). I have tried using the -N and -p options (even though man informs me that these are the default when running tar as root). I can work around this problem by 'chown'ing but I would love to know what I'm doing wrong for tar not to work 'as advertised'.

Thanks for any help
Phill
8 REPLIES 8
James R. Ferguson
Acclaimed Contributor

Re: Can't preserve file ownership using tar

Phillip:

I would expect the name & group to be "correctly" restored if in fact the uid & gid of the files are present on both system and map to the same names.

...JRF...
Rick Garland
Honored Contributor

Re: Can't preserve file ownership using tar

I would opt for the use of cpio.
To do cpio from one FS area to another FS area:
cd
find ls . | cpio -pmuldv /

This will preserve all ownerships and permissions.

(Can also be done system to system across the network - but with the above listed syntax)
Jim Welch
Respected Contributor

Re: Can't preserve file ownership using tar

You can use shar also. It has switches to preserve modification and access times (-m) as well as uid/gid (-o).
Any sufficiently advanced technology is indistinguishable from Magic - Arthur C. Clarke
Manju Kampli
Trusted Contributor

Re: Can't preserve file ownership using tar

Phillip,

First thing you should check is do you have same user on both the systems and same UID's. Tar takes the backup of UIDs and restores them in the similar manner. From your question it looks like you are using the root user for this and I do not see the problem with this.
The second thing you should also look for is the umask for user you are using for restore. Some times I have noticed, during file restore, the file permissions are based on umask.

good luck
Never stop "LEARNING"
ESC Team
Advisor

Re: Can't preserve file ownership using tar

Try pax

man pax

That might help. It's unusual that tar doesn't work. You don't have any acl's
or it's an nfs filesystem?
Where are you try to extract to?

Greg
ESC Team
Phillip Latham_1
Occasional Contributor

Re: Can't preserve file ownership using tar

I'm actually trying to move some users home directories from one box to another. I'm creating the archive (as root) using relative paths from /home
I'm then extracting the archive, from /home on the target machine (again as root).
The usernames, uid's and gid's are identical on both machines and the uid/gid is recorded correctly in the archive (as seen by tar tvf).
When the archive is extracted, all directories seem to have the correct ownership but files within those directories are now owned by root. The permissions of the files (i.e rwx) are preserved correctly.
The permissions of the /home directory on the target machine is as follows...
drwxr-xr-x root root

Thank you all for your suggestions for alternative approaches - I'm looking into them now, but I would really like to get to the bottom of why tar won't work.

Cheers
Phill
John Palmer
Honored Contributor

Re: Can't preserve file ownership using tar

Have you tried restoring the tar dump to a different place on the original server to see if that is ok?

I must confess that I've never seen this problem before. What versions of HP-UX are involved? Is anything special configured eg trusted systems etc?

Regards,

John
Phillip Latham_1
Occasional Contributor

Re: Can't preserve file ownership using tar

In case anyone is interested, I've worked out why it wasn't working...

tar cannot cope with uid's greater than 60000 which, of course is exactly what we use here!

Thanks for all your suggestions
Phill