I need to backup some data with the "p" option on tar command. The problem is the place I'm going to restore this data will have all the same users, but those users may have different IDs. Does that make any difference to tar or will it restore permissions correctly by user name?
4 Answers
Summing up previous answers and adding some important information:
When creating archives,
tarwill always preserve files' user and group ID, unless told otherwise with--owner=NAME,--group=NAME. In either case, each file will always have an associated numeric user and group ID.GNU
tar, and perhaps other versions oftar, also store the user and group names, unless--numeric-owneris used.bsdtaralso stores user and group names by default, but it had no support for--numeric-owneroption when creating archives until version 3.0 (note that it supported the option when extracting archives since much longer).When extracting as a regular user, all files will always be owned by the user. And it can't be any different, since extracting a file means creating a new one on the filesystem, and a regular user cannot create a file and give ownership to someone else.
When extracting as root,
tarwill by default restore ownership of extracted files, unless--no-same-owneris used, which will give ownership to root himself.In GNU tar, bsdtar, and perhaps other versions of
tar, restored ownership is done by user (and group) name, if that information is in the archive and there is a matching user in the destination system. Otherwise, it restores by ID. If--numeric-owneroption is provided, user and group names are ignored and IDs are used. In either case, whenever numeric IDs are used, a matching user and group does not need to exist in the system.Permissions and timestamps are also saved to the archive, and restored by default, unless options
--no-same-permissionsand/or--touchare used. When extracted by the user, user'sumaskis subtracted from permissions unless--same-permissionsis used.--preserve-permissionsand--same-permissionsare aliases, and have the same functionality as-p
Hope this helps clarify the issue! :)
- 1,793
- 14
- 11
tar records permissions based on the UID and GID, not on the string associated with them. So if the UID on one server was 3300 and that was linked to 'bob', on the new server the file will be owned by the user who has the UID 3300.
Virtual everything (I want to say everything, but you can never be 100% sure) on UNIX uses the UID:GID values, because that's what is actually stored at the filesystem level. The name is just a simple lookup in the passwd file, the underlying checks are done using the numeric values.
- 8,437
- 9,441
- 1
- 37
- 47
If you are trying to transfer files between two systems, rsync will by default set the permissions by username instead of uid, looking at the usernames at both ends. Only if the user doesn't exist on one of the systems will it copy it with the uid, unless you tell it otherwise.
- 18,125
- 14
- 75
- 104
User the --same-owner option to GNU tar. See http://www.gnu.org/software/tar/manual/html_section/Attributes.html
- 299