rsyncing feeling

Tim Writer tim-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org
Thu Jul 22 12:32:35 UTC 2004


daniel <danstemporaryaccount-FFYn/CNdgSA at public.gmane.org> writes:

> On July 21, 2004 08:16 pm, David J Patrick wrote:
> > rsync !
> > Just what I need to keep my USB-key files in sync with the laptop and
> > the desktop.
> > But what's this ? A fly in my ointment ! A big hairy one !
> > It's name is "permissions"; I have no idea how to reconcile files for
> > users of multiple systems.
> > It seems not to be enough that "dave" is the log-in name on all
> > machines, or that he is a member of the "office" group. I know this must
> > be absurdly simple, and long dealt with, un unix days of old. but, once
> > again, I could use a clue.
> > thank you,
> > djp
> 
> you're right, the problem is very old, and not as easily solved without 
> complication.  see, the problem you're (probably) having is that user "dave" 
> is UID 1000 on one box, and say, UID 1002 on another.  redhat machines start 
> their new users at UID 500, so that can lead to issues accross linuxes.

While you're right that the general problem of maintaining consistent UIDs
and GIDs across multiple Linux/*NIX systems is a difficult one, I think
there's a simple solution for this specific application.

Every USB key I've seen comes preformatted with a vfat (or dos) file system
While you can put any file system you want on them, most people leave them
vfat to facilitate transferring files to/from Windows systems.  Since vfat
has no notion of users and permissions, you cannot record users and
permissions on a vfat formatted USB key.  This might seem like a problem but
if you're using the USB key to store only your own files, i.e. you're using
rsync to manage a subtree (or set of subtrees) of your home directory, you
don't need user and group information as you know these files are yours.
Similarly with permissions as the vast majority of files within a user's home
directory all have the same permission, i.e. the defaults based on your
umask.

If you have an entry for your USB key in your /etc/fstab, like this:

    /dev/sda1   /usb    vfat    noauto,user     0 0

you can copy your files to your USB key like this:

    % mount /usb
    % cd
    % rsync dir1 dir2 ... /usb

If you have a similar entry in /etc/fstab on the target system, you can then
update dir1 and dir2 like this:

    % mount /usb
    % cd
    % rsync /usb/ .

As long as you use the "user" option (or alternatively the "owner" option) in
/etc/fstab, there's no need for you to become root.

You may have a few files where ownership or (more likely) permissions are
important, ~/.ssh comes to mind.  For those files, use tar instead.  In other
words, you can copy files to your USB key, maintaining a complete record of
ownership and permissions, using:

    % mount /usb
    % cd
    % tar cfz /usb/archive.tgz .ssh special_dir other_special_dir ....

And you can extract this on the target system, like this:

    % mount /usb
    % cd
    % tar xfz /usb/archive.tgz

Since you're running as yourself on both system, this will "just work"
regardless of your actual login name, uid, and gid on the respective systems.

> linux doesn't care what name you give yourself.  it only cares what number you 
> are, so that's why these UID's are so important.  if you want to know what 
> your UID is, just do this:
> 
>   dave at localhost $ echo $UID

A more portable way to get this is:

    % id

> and you'll get some number.  now, if you want files saved with "dave" as the 
> user to be owned by "dave" on another box, you have to change the UIDs on the 
> appropriate machines.  that value is in /etc/passwd and is relatively easy to 
> switch over as long as it's not a multi-user system where someone else 
> already has your id...  then things get ugly.
> 
> in the case of this ugliness, you might have to look at NIS (look it up on the 
> linux documentation project) or, probably easier, a simple script that 
> updates all the file ownerships upon transfer.  something like this:
> 
> 
>   find <path> -uid 500 -print0 | xargs -0 --replace chown dave:users {}

Careful! That will change your group to "users" which might not be what you
want.  You can belong to multiple groups so, while all of your files are (by
definition) owned by your uid, they may not all have the same gid.  A general
solution must examine the gid of each file and map it to the corresponding
gid on the target system.  Too much work for this paricular application.

-- 
tim writer <tim-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org>                                  starnix inc.
905.771.0017 ext. 225                           thornhill, ontario, canada
http://www.starnix.com              professional linux services & products
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list