Permissions wrong if rsync terminates prematurely

Matti Haavikko haavikko at gmail.com
Tue Feb 21 13:54:03 MST 2012


Hello,

We use rsync to synchronize a large folder hierarchy between servers.
Sometimes we notice that the permissions of some directories end up
being wrong after rsync is run. The source directory has permissions
755 while target permissions sometimes end up being 700. We are using
the --timeout option of rsync, and we have additional watchdog process
that will terminate the process if a total running time limit is
exceeded.

In actual scenario, the folder hierarchy contains thousands of
folders. The example below illustrates the problem.

$ find mytest/ -ls
1533304    4 drwxr-xr-x   5 mhaa     mhaa         4096 Feb 21 21:11 mytest/
1533322    4 drwxr-xr-x   2 mhaa     mhaa         4096 Feb 21 21:11 mytest/foo3
1533321    4 drwxr-xr-x   2 mhaa     mhaa         4096 Feb 21 21:11 mytest/foo1
1533318    4 drwxr-xr-x   3 mhaa     mhaa         4096 Feb 21 21:02 mytest/foo2
1533320    4 drwxr-xr-x   2 mhaa     mhaa         4096 Feb 21 21:02
mytest/foo2/bar
1443165    4 -rw-r--r--   1 mhaa     mhaa            4 Feb 21 21:02
mytest/foo2/bar/baz

I ran rsync with strace as follows:

$ strace -f -ff -o /tmp/rsync-strace rsync -axv --temp-dir=/tmp
--timeout=20 mytest /tmp/mytesttarget

strace output shows that the directories are at first created with 700
permissions and the correct permissions are assigned later:
(lots of output omitted)

rsync-strace.5640:mkdir("mytest/foo1", 0700) = 0
rsync-strace.5640:mkdir("mytest/foo2", 0700)                               = 0
rsync-strace.5640:mkdir("mytest/foo3", 0700)      = 0
rsync-strace.5640:chmod("mytest/foo1", 0755)        = 0
rsync-strace.5640:chmod("mytest/foo2", 0755) = 0
rsync-strace.5640:chmod("mytest/foo3", 0755) = 0

Same sequence occurs with ordinary files.

It seems likely that a timeout is triggered in the watchdog process
while the directories are being created. Rsync is terminated and the
directories end up with wrong permissions. In our use case it might
take a long time to scan/create the large directory tree so the time
window for this problem to appear is at least several minutes.

Is this expected behavior or bug and is there any way to work around this?

Best regards,

 - Matti Haavikko


More information about the rsync mailing list