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.
/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: