Last week I put a plea for help up about my quest to find a way to mirror some directories between servers. That isn’t so difficult, but the desire to have it real-time – or almost real-time – made finding a cost-effective solution difficult.
I put a post up on serverfault.com and got some good responses. The answer I selected taught me some features of my old friend robocopy that I had never discovered: the /mon and /mot flags.
/mon: Monitors the source, and runs again when more than N changes are detected.
/mot: Monitors source, and runs again in M minutes if changes are detected.
Those flags are game changers! With them, robocopy runs the sync job as specified. When done, it stays alive and starts watching for changes. As the changes are detected the timer starts a countdown until the next run. Brilliant!
I created a ltitle batch file with the robocopy command and arguments I wanted. I set it as a scheduled task that starts every morning at 6 AM. I specified properties on the task to kill the job after 16 hours. Then the next day it starts up. Seems to be working very well. The only time it gets weird is when folks inadvertently lock files on the mirror’s destination side. That hoses things up a big until they release the lock. That’s mostly been an education issue though.
Here’s the command I’m using. Lots of flags!
robocopy "E:\source" \\server2\dest /mir /mon:1 /mot:1 /R:2 /W:15 /COPY:DT /log:c:\util\mirlog.txt /NJH /NJS /NDL /NP /Z
The logging is a bit funky and might be related to the logging options I’ve specified (/NJH /NFS /NDL /NP). Seems like I get lots of blank gaps in the log when there are locked files and the latest log entry isn’t necessarily at the bottom of the file.. But hey, we know that any changes made will be on the other server within a minute and that’s just what needed to happen.
Pseudo real-time mirroring for free!
Possibly Related posts:







That’s awesome. But are those options perhaps only in the Vista or 7 version of Windows?
I don’t have a Win 7 machine to test with at the moment, but the old standard Robocopy version that runs on WinXP doesn’t have those options.
Thanks
-Dave
Dave – I’m not sure about that and will have fire up an XP machine soon to check.
I’m using the old version of robocopy though — X10 is the only one that’ll run on Windows 2003 Server editions (I’ve tried copying over Win2008 / Win7 versions but they won’t run). I’m pretty sure that is the same version (X10) as what comes with XP. Or if not, should be available.