Automatically Mirror Files in Windows to a Network Drive with Robocopy



Centralizing your photos and videos on a network drive makes them accessible to all machines on your network. Robocopy, a Windows Command Line Utility, will keep files in sync with your main library.
My home has many computers and many screens, but just one central library of photos, music, and videos. My main computer stores all my multimedia (and the backups). But rather than keeping my main computer on at all times (it’s a power-hungry mid-tower), I mirror my photos and videos to a network drive that’s plugged into my router.
Originally, I was using SyncToy to keep my main multimedia library in sync with the network drive library. But for inexplicable reasons, SyncToy has been running monstrously slow ever since I upgraded to Windows 7 and Windows 8. Since Microsoft stopped supporting SyncToy about four years ago, it’s unlikely that it’ll be fixed. So, I’ve started using Robocopy instead. And so far, it works great.
I can sync a folder pair consisting of my main photo library and a folder on my network drive. And like with SyncToy, Robocopy will also delete files on the network drive that no longer exists in my collection. Best of all, Robocopy is free (it comes built-in to Windows).
Use Robocopy Command Line Tool
Robocopy is a command line tool. To mirror a folder to another folder (in my case, the folder on my network drive), use the following switches:
robocopy source_directory target_directory /MIR
Replace source_directory and target_directory with the appropriate folder paths. Note that you’ll have to wrap it in quotes if there are spaces in the folder path.
That’s the basic command you’ll need. It only has one switch: /MIR. /MIR is a combination of the /e and /purge switches, which, collectively, copy all subdirectories (including empty subdirectories) and delete files and directories that no longer exist in the source directory. /MIR also overwrites the directory security settings (unlike /e) if the directory already exists.
Simply type the above command into cmd.exe to make it happen.
The progress of the file copy will be shown in the command window. Afterward, you’ll get a summary of the files transferred. Here, you’ll see that 2 files were copied and 1 was deleted because it didn’t exist in the source directory. Only 1 directory was copied because the other directory was the root, which already existed.
To save yourself the trouble of typing that in each time you import photos to your library, you can copy and paste the command into Notepad and save it with the .bat extension.
Then, all you have to do is double-click it to run it.
With a batch file, you can also automate it to run once a week, daily, etc. similar to my earlier tip on how to automatically wake and sleep your computer using Windows Task Scheduler. Just sub out the wake.bat and sleep.bat for mirror.bat.
Other Switches and Tweaks
There are two other switches I use with my Robocopy mirror batch file. The first is the /z switch. This enables Restart mode, which lets you resume a large transfer if it’s been interrupted. With large movie files, this may come in handy. But with network drives, it does slow things down a bit.
The other one I use is /LOG. This writes the status of the transfer to a log file, rather than displaying it in the command prompt. This is handy when the transfer runs automatically when I’m away, so I can go back and view it. I save the log in my Dropbox folder, so I can view it from my phone or another computer to see if the transfer occurred.
My entire batch file looks like this:
robocopy "E:\Storage\Photos and Videos" "Z:\photos and videos" /MIR /Z /LOG:mirror.log
Conclusion
Overall, Robocopy has been working well for me. It keeps my files in sync so they are available to all the devices on my network. And it seems to be considerably faster than SyncToy. Usually, I sync right away whenever I do an import, but if I forget, it runs once a day at 5 AM (which is about 15 minutes before I sit down at my computer first thing in the morning).
Also, this will work much better for you if you use one directory for your photos and videos. If you have multiple directories, things can get a little more complex. But it could be as simple as running multiple Robocopy commands (one for each folder pair to keep in sync).
What do you use to mirror files to your network drive? Let us know in the comments!
28 Comments
Leave a Reply
Leave a Reply

Harv
Doesn’t work as expected. I put the command to test a small directory in a batch file. After the first run I ran the same batch file multiple times without changing anything. It still copies the files and reports them as Older or Newer. I expected the files to be bypassed after the first run.
Jack Busch
Hi, Harv – Not sure why you are experiencing that. I run it every morning and I get lots of skipped files. See my last report:
Total Copied Skipped Mismatch FAILED Extras
Dirs : 793 2 791 0 0 0
Files : 16711 46 16665 0 0 0
Bytes : 118.058 g 279.28 m 117.785 g 0 0 0
Times : 0:09:49 0:06:24 0:00:00 0:03:24
Are you using all the switches?
robocopy “E:\Storage\Photos and Videos” “Z:\photos and videos” /MIR /Z /LOG:mirror.log
Harv
Here’s what I get after repeat runs of the batch file with no changes. The “Newer” is sometimes reported as “Older”.
————————-
F:\Marcs Documents\PC Stuff\macros>robocopy “f:\marcs pictures\2013 pictures\Gracienne” “t:\2013 pictures\Gracienne” /MIR
——————————————————————————-
ROBOCOPY :: Robust File Copy for Windows
——————————————————————————-
Started : Tuesday, April 16, 2013 6:49:11 AM
Source : f:\marcs pictures\2013 pictures\Gracienne\
Dest : t:\2013 pictures\Gracienne\
Files : *.*
Options : *.* /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /R:1000000 /W:30
——————————————————————————
5 f:\marcs pictures\2013 pictures\Gracienne\
100% Newer 17.3 m Moviea.wmv
99% Newer 138242 photo.JPG
Modified 117789 photoa.JPG
99% Newer 87243 photob.JPG
99% Newer 430604 tthotoa.JPG
——————————————————————————
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 0 0 0 0
Files : 5 5 0 0 0 0
Bytes : 18.08 m 18.08 m 0 0 0 0
Times : 0:00:09 0:00:09 0:00:00 0:00:00
Speed : 2106881 Bytes/sec.
Speed : 120.556 MegaBytes/min.
Ended : Tuesday, April 16, 2013 6:49:20 AM
F:\Marcs Documents\PC Stuff\macros>pause
Press any key to continue . . .
CapinDFW
@Harv – You’re not running Windows 8, are you?
http://answers.microsoft.com/en-us/windows/forum/windows_8-files/robocopy-appears-to-be-broken-in-windows-8/9a7634c4-3a9d-4f2d-97ae-093002a638a9.
Also, what is T: mapped to? Could it be a cloud drive? Not sure if Robocopy could play well with the cloud…
Garry
Try KrojamSoft SyncFile for synchronising. Its a simple and best software for synchronising.
CapInDFW
Very slick. I had no idea robocopy existed, let alone how powerful it is. I was messing around with xcopy and various applications of questionable worth (FYI – free of charge doesn’t necessarily make it worth it). Robocopy is just what I’ve been looking for to sync my media!
Thanks for the tip! G+ and FB like
OFS
FreeFileSync DOES WORK, and works very well. Just be careful during install so that you don’t install the crapware.
Sean
I ended up googling my way here after downloading FreeFileSync (FFS – ha!) and seeing the crapware included with it (luckily I spotted it before installing). It is not possible to install it without also installing the junk – the three options are…
1. Install FFS and Linkey, and set homepage, and a load of other stuff to it
2. Install FFS and Linkey, but don’t set homepage and other stuff to use it (BUT STILL INSTALL IT!)
3. Install nothing – neither FFS or Linkey
The installer is clearly designed to fool the skim-reader into thinking that option 2 (custom) is to install FFS but not Linkey – it is not. Always read every word of the installer for free software!
But robocopy looks absolutely perfect – thank you very much for the guide.
Steve Krause
You bet Sean. Yeah, Robocopy just gets it done. There is so much Junkware out there now it’s annoying. I installed IMGBURN on a PC I built on Saturday and only by clicking “Advanced Install” did I see they were also adding in a bunch of JUNK along with the App I wanted to install…..
So good FYI on the FFS junk. Good reminder for everyone to READ THE FINE PRINT!
Thnx for reading my blog.
-S
Sean
FreeFileSync definitely *CAN* be installed without crapware, and very easily, at least as of June of 2015. Only one clearly-identified box to un-check.
Andy Bussieres
I’ve set it up and tested it on a single network directory – with a .bat file much the same as yours. Works like a charm. Always was a fan of its predecessor – xcopy. Follows the KISS rule. I have two 6TB My Cloud drives – one for data – one for backup. Considered the WD Mirror drive – but prefer fully independent units. Hope it doesn’t take too long to go through the directory structure after the initial copy. Thanks for the post.
Tony S.
so, I would like a robust backup of some files that get edited on multiple machines, will this work? I don’t know if you know the electric sheep screensaver, but figured it would be a good set of test files where is is continually downloading and making new ‘sheep’ it will also delete old sheep based upon a file size. Which simulates my house where files do accidentally get deleted. would be nice to add something like the Apple Time Machine Backup into the works.
–file name
RoboCopy.bat
–content
robocopy “C:\ProgramData\ElectricSheep\content” “\\WDMYCLOUD\SmartWare\Electric Sheep” /MIR /Z /LOG:mirror.log
robocopy “\\WDMYCLOUD\SmartWare\Electric Sheep” “\\FRED-505\ElectricSheepContent” /MIR /Z /LOG:mirror.log
robocopy “\\FRED-505\ElectricSheepContent” C:\ProgramData\ElectricSheep\content” /MIR /Z /LOG:mirror.log
Bill
I’m stumped how to get RoboCopy to work under Win7. I’ve devolved down to the simplest case I can think of and it doesn’t work. First I execute:
Copy c:\SharedData\Test.txt c:\Junk\Test.txt
This works fine. Then I simply add Robo to the front and try to execute again:
RoboCopy c:\SharedData\Test.txt c:\Junk\Test.txt
Win7 complains “ERROR 123 Accessing source directory. Filename, directory name or volume label syntax is incorrect.”
Any idea what I’m doing wrong? It seems too simple to be wrong, but…
isaiah
are you appending the line with “/MIR” ?
robocopy “E:\Storage\Photos and Videos” “Z:\photos and videos” /MIR
^^^^
TravisRiggs
I am trying to use this for a networked drive, however I want to copy all of the sub-directories as well. Where “N” is my network and “L” is my local machine. My N drive has directories that go through multiple levels (e.g. N\Cases\Case Number\Emails\) robocopy doesn’t seem to create directories or subfolders.
TravisRiggs
Actually I wasn’t being patient enough – it is working great now and I am working on scheduling automatic updates. A question on the batch file: could it be setup to run every hour? In the event I am disconnected from my network (I’m using a laptop and I often travel for work) is there a way to pause the scheduled task without deleting it?
Nicole
my batch file doesn´t work! I don´t know what I´m doing wrong… :(
Andrew
Here’s mine. If you post your batch file, we can try to figure out why it is not working.
robocopy “\\WDMYCLOUD-6TB1\Public\Shared Videos\Z” “\\WDMYCLOUD-6TB2\Public\Shared Videos\Z” /copy:dt /mir /z /log:C:\Users\Andrew\Desktop\mirror.log /tee /np
Paul
@Bill: robocopy is a tool meant for syncing folders, but you are trying to use it to copy individual files. If you remove both occurrences of “Test.txt” in your example then you should find that it works :)
Bill
Thanks for that. I went back to look at the system help for RoboCopy and it’s ambiguous just mentioning “source” and “destination”, but not file or directory.
But it does seem to just work for directories.
Juan
Hi, mine is not working either…I created two small folders to try it out .
Here it is, as one of the folder path does not have spaces I did not wrap it in quotes.
robocopy C:\Users\s176026\Documents\Screenshot-Confirmations “C:\Users\s176026\Desktop\test\test once more” /MIR /Z /LOG:mirror.log
Is this correct?
Thank you in advance
Kingshuk
This was very useful. Nice wholesome way to sync up my files to my NAS and being able to access them at any time. Thanks for this article !
Luis
It works!!!
Sergio Soares
Can you please tell me how you schedule it to run every day at 5am ? This is what I need.
Goanna
Robocopy doesn’t run automatically, you need to run your script manually every day 5 am, so I suggest using alternatives like Carbonite or Gs Richcopy360
NancyBlack
Gs Richcopy 360 works very well with me so I can’t back to use Robocopy again.
The program supports long path names,
Supports copying from open files
Supports encryption and compression before the transfer
The program is multithreaded and can send Email after the job is finished
Florizi Welback
Hi Nancy , Am I the only one who sees that ?, Gs Richcopy 360 works well but has too many features. Not sure if I need that many.
Dave
what about a pass word protected share ?