tl;dr and an example
I'm looking for a way to compare two folders recursively and output the relative paths all files (and folders) that are different (by size or by timestamp, à la rsync).
For example, say I have
C:\source\foo\a.txt
C:\source\foo\bar\b.txt
C:\source\foo\bar\c.txt
and
C:\target\foo\a.txt
C:\target\foo\bar\b.txt
C:\target\foo\bar\d.txt
C:\target\foo\baz\
and suppose b.txt
has been changed under C:\source
, and is thus newer.
Then given a magical script or command, say, magic C:\source C:\target
, I'd like the output to be
foo\bar\b.txt
Or, a full path on either the source or the target folder would be acceptable too:
C:\source\foo\bar\b.txt
As the example shows, I don't care about files and folders that have been deleted or created! Which should make this task much simpler than otherwise.
What I know already...
I'm a UNIX dev myself, and wouldn't be asking if this were a UNIX system we're dealing with, but alas. Also, this is for a custom nightly backup solution, where reliability and data integrity is a priority, so given that a few weeks ago I couldn't even figure out a for-loop in a batch script, I'm pretty sure I lack the experience to do this right, or even determine the best way to do this.
Reading http://www.howtoforge.com/backing-up-with-rsync-and-managing-previous-versions-history, I learned that rsync can do something like what I'm after, using options like
--dry-run # don't actually rsync (touch) any files
--itemize-changes # list changes rsync _would_ have made
--out-format="%i|%n|" # define an output format for the list of changes
However, I'd hate to rely on Cygwin (cwRsync) to use rsync, as I'm already prone to running quick-and-dirty experiments on my Cygwin installation, often breaking the environment and needing to reinstall Cygwin every few weeks. That kind of opposes the "reliable" part of a nightly backup.
I haven't found any "canonical" tool like rsync in Windows, at least not any that support options like the above. Also, I'm not looking for software in general unless it's a simple and compact tool for specifically this purpose—I prefer a transparent, programmatic solution. For something as important as backing up files, relying on software or code I can't see or understand is scary!
Recap
I can't wrap my head around batch scripting syntax. Next I'll try PowerShell. But what would you do, given this task?—Is there some obvious route that I'm missing?