rsync Windows to unix File Permissions

By Xah Lee. Date:

File permission has always been a ass. Often, when our system was deployed elsewhere by others, and something mysteriously doesn't work, chances are, it's file permissions. The unix file perm system is particularly faaked up. Here's some notes about using rsync between Windows and unix.

• In Windows 7 (ACL), to make a dir accessible to all, you need to add the “other” user, with this syntax: ‹comp name›\Users. For example, on my PC, it is h3-HP\Users. This corresponds to the unix's notion of “other”. (to change file perm, get properties on the dir, then “Security” tab. The GUI is rather confusing if you are not familiar with ACL.)

• When you rsync from Windows to unix, adding the “-p” for preserve permission does not seem to work. For example, my source dir on Windows is readable by all users. On the unix web server, of course i want dir to be 755 and files to be 644. But rsync with “-p” won't work.

To make sure the uploaded files have the right perm with rsync, you can use the “chmod” option. Example:

rsync -z -r -v -t --chmod=Dugo+x --chmod=ugo+r ~/web/ 

The --chmod=Dugo+x means: for all dir, add the execute bit, for all {user,group,other}. The --chmod=ugo+r means: for all files, add the read bit, for all {user,group,other}.

• The unix terms {user, group, other} and their abbrevs {u,g,o} always confused me. For example, “user” could mean all users. The “o” could mean “owner”. (The entire unix is the most incompetent shit possible.)

• In unix, for a file to be readable by anyone, the parent dir must have the execute bit (x) on. This is another major idiocy that often trip newbs. The reason it's like that because unix usually goes by crass implementation simplicity, as opposed to thinking on what things should be . Here, it sterm from the fact that a dir in unix is just a file. [see The Nature of the Unix Philosophy]

• For rsync to work its magic of being fast across a dir with 5 thousand files, you must have the “-t” (--times) option on, otherwise it is excruciatingly slow (even if both source and dest dir are local); it's probably doing a file by file comparison. This is a bit odd, because for all the acclaim you hear about rsync's syncing algorithm, you'd think it's something other than just comparing timestamps. If you rely on timestamp, than the problem of determining which file needs to be updated becomes rather trivial.

• rsync syncs only in one direction. I was a bit surprised when i first learned this. Because, you'd think that the word “sync” implies 2-way sync. If just one way, then it's rather trivial. (but remember, rsync is a tool invented in the 1990s. At the time, it was big deal, because otherwise you'll have to use just “rcp” that copies EVERY file across network and is not secure.) If you want 2-way sync, use “unison”. [see Unison Tutorial (Sync Files)]