5

In dry-run-mode, the log file does not contain changed/ updated regular files, and no deletions at all. It only contains changed and created directories. Yet, when executed without dry-run, the log file does contain all kinds of changes.

A small example: When running the command

rsync -a --delete-delay --progress --itemize-changes --stats --dry-run --log-file="/tmp/rsync-dry.txt" /tmp/mySource/ /tmp/myDest/

the log-file looks like this (3 items, all of them related to directories):

2015/08/26 17:18:04 [5812] building file list
2015/08/26 17:18:04 [5812] .d..t...... ./
2015/08/26 17:18:04 [5812] .d..t...... sub1/
2015/08/26 17:18:04 [5812] cd+++++++++ sub2/
2015/08/26 17:18:04 [5812] Number of files: 11 (reg: 8, dir: 3)
2015/08/26 17:18:04 [5812] Number of created files: 5 (reg: 4, dir: 1)
2015/08/26 17:18:04 [5812] Number of deleted files: 4 (reg: 3, dir: 1)
2015/08/26 17:18:04 [5812] Number of regular files transferred: 6
...

Without dry-run, i.e.

rsync -a --delete-delay --progress --itemize-changes --stats --log-file="/tmp/rsync-wet.txt" /tmp/mySource/ /tmp/myDest/

the log-file looks like this (13 items):

2015/08/26 17:19:44 [5837] building file list
2015/08/26 17:19:44 [5837] .d..t...... ./
2015/08/26 17:19:44 [5837] >f.st...... Bbb.txt
2015/08/26 17:19:44 [5837] >f+++++++++ Ccc.txt
2015/08/26 17:19:44 [5837] .d..t...... sub1/
2015/08/26 17:19:44 [5837] >f.st...... sub1/Fff.txt
2015/08/26 17:19:44 [5837] >f+++++++++ sub1/Ggg.txt
2015/08/26 17:19:44 [5837] cd+++++++++ sub2/
2015/08/26 17:19:44 [5837] >f+++++++++ sub2/Iii.txt
2015/08/26 17:19:44 [5837] >f+++++++++ sub2/Jjj.txt
2015/08/26 17:19:44 [5837] *deleting   sub3/Kkk.txt
2015/08/26 17:19:44 [5837] *deleting   sub3/
2015/08/26 17:19:44 [5837] *deleting   Ddd.txt
2015/08/26 17:19:44 [5837] *deleting   sub1/Hhh.txt
2015/08/26 17:19:44 [5837] Number of files: 11 (reg: 8, dir: 3)
2015/08/26 17:19:44 [5837] Number of created files: 5 (reg: 4, dir: 1)
2015/08/26 17:19:44 [5837] Number of deleted files: 4 (reg: 3, dir: 1)
2015/08/26 17:19:44 [5837] Number of regular files transferred: 6
...

which accurately reflects what rsync is doing.

I am puzzled because I believed that the output of rsync with and without --dry-run should be the same. (Otherwise, what would dry-run be good for?) The problem refers to the log-file only. The terminal output is always complete, with or without --dry-run.

I tried different options, e.g. --rtgopl or -rtgo instead of -a, -v instead of -i. I tried rearrangig the flags. I tried adding options like -c or --inplace. Didn't help. It also does not matter whether the destination is another local path (as in the example), a USB-drive or a remote destination via ssh. What did I do wrong? Or is rsync supposed to work like this? (I am using Ubuntu 14.04, rsync version 3.1.0.)

Tammo J.
  • 131

1 Answers1

8

Finally, I found a hint that the behavior of rsync described above may be a feature, not a bug:

The current code logs the same way for a --log-file as it does for a daemon log, which means that it does not log transfers that aren't really transfers.

[https://bugzilla.samba.org/show_bug.cgi?id=5792#c2]

In order to get a log-file in dry-run-mode that really contains all updates, creations and deletions, as a workaround you could redirect the screen output to a file, e.g. like

rsync -a --delete-delay --progress --itemize-changes --stats --out-format='%t %p %i %n %M %l' --dry-run /tmp/mySource/ /tmp/myDest/  | tee /tmp/rsync-dry.txt

In the example, I used the option --out-format='%t %p %i %n %M %l' to format the output roughly the way it would have been formatted by the --log-file option.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Tammo J.
  • 131