Mirroring a folder in Windows

Summary:

Here’s how to use Windows RoboCopy and Windows Task Scheduler to mirror a folder’s contents to another folder. In my case, it’s keeping exact duplicates of my folder that contains all my creative projects and my notetaking app files on both OneDrive and Google Drive.

What you’ll need:

Quick background

I retired last year to write novels, make music, and be creative. The source files for all of those projects are in a folder named “Projects.” I already do an encrypted backup to an external drive daily. I was using OneDrive to sync it between my desktop and my laptop and got the benefit of a second backup.

Since I have plenty of spare Google Drive space, I figured it would be good to mirror the folder in my Google Drive too as a second off-site backup.

The three-step process

Steps 1 and 2 set up local copies of the folder that are synced to their respective cloud storage services. Step 3 mirrors one to the other. So if you aren’t using cloud storage, you can skip those steps.

Step 1: Make OneDrive store copies of the files locally

This assumes you’ve set up OneDrive as part of your Windows setup and your OneDrive folders are visible in File Explorer. Here’s a Microsoft tutorial on OneDrive if you don’t.

Once OneDrive is set up and the folder you want to mirror is in OneDrive, you need to make sure full copies of each file/folder are stored on your local drive. Right-click on the folder you want to mirror and select Always keep on this device.

That might take some time to complete, depending on your connection speed and how much there is in the folder. Once it’s done, you’ll have a green circle with a check in it next to it in the status column of File Explorer.

Step 2: Install and configure your Google Drive client

Follow Google’s instructions to install and configure Google Drive for Desktop.

I like to set it up with a drive letter. For that, from the installed client, I find I have to select the preferences option which opens another window in which I have to select the preferences option again. But then I get this window and scroll down for the drive letter preference.

Once it’s got a drive letter, go into that drive in Windows, go into your files & folders (“My Drive”), and create a folder to hold your mirrored files. Then right-click on it, select Offline access, and in its submenu, select Available offline.

Step 3: Set up mirroring

Step 3.1: Get your folder paths

First you’ll need the full path of each folder. Navigate into the folder, and click in the location bar at the top of the File Explorer to get the full path.

Unclicked location bar:

Clicked location bar:

The clicked location bar will give you the paths which you’ll need to construct the request.

Step 3.2: Open the task scheduler

The easiest way is to hit the Windows key to bring up the start menu and start typing “task scheduler.” When it offers it to you, hit enter or click on it.

When it opens, it’ll be somewhat blank until it connects the user interface to the service, then it will fill itself in and look somewhat like this.

Step 3.2: Create the task

Select Task Scheduler Library from the left column and then “Create Task” from the right column. You’ll get a dialogue window like this.

I’ve pixelated my machine and username, but if your computer was named Desktop2 and your name was Charles Smith, it might look like “Desktop2\csmith” or something similar. It’s going to be pre-populated for you. I added text for the name and description.

Security options: It will use your currently logged in account as the user to run the task as. No need to change that for this purpose. But there’s an important difference between Run only when user is logged on and Run whether user is logged on or not. The first option will open a terminal window and run the command in it every time you log on. If you close the terminal window, you stop the monitoring process for the mirroring. The second option will run everything in the background without needing any windows open. It’s up to you which you choose, but I choose Run whether user is logged on or not.

Next, select the Triggers tab and select New to add a trigger.

This tells it when to start running the task. I prefer it to start at logon. This is because you have to have the Google Drive client running to address it by its path. The default is to set it up when anyone logs on. If you choose Specific user instead, it will only launch when you (or another user you specify) logs on. I choose me just for extra safety so only me logging on will start it.

Optional: You can also go into the Advanced settings and set Delay task for with a couple of minutes wait. If your computer is slow to load all the apps and drivers after you logon, you might want to choose this just so your cloud clients like Google Drive and OneDrive have a chance to start before things get moving.

Since this will constantly monitor the root folder for changes and copy them to the mirrored folder, leave everything else as is and select OK.

Next, select the Actions tab. This is where you’re going to tell it what to do. Select New to create a new action.

The default action is Start a program, which is what you want.

For the Program/script either manually enter C:\Windows\System32\Robocopy.exe or use the Browse button to open a file picker window and select it from the Windows\System32 directory.

In the Add arguments field, add the following, substituting the paths you collected in step 3.1 for the two paths below.

“C:\Path\to\source\folder” “C:\Path\to\mirrored\folder” /MIR /MON:1 /MOT:5 /MT:16

Explaining the remaining arguments…

  • /MIR tells it to run this as a mirroring operation, which will copy everything from the source folder to the mirrored folder, including empty subdirectories. It also deletes files in the mirrored folder that were deleted from the source folder.
  • /MON:1 tells it to monitor the source folder and how many changes must occur for it to consider the source folder changed enough to run an update. It’s set to 1 here, so even one change will be enough.
  • /MOT:5 The update interval. In this example, it waits 5 minutes and checks the monitoring. If the number of changes monitored since the last update is greater than the number specified in the MON argument, it will run the update. It’s good to set this around five because if it’s running immediately, every time there’s a change, it could become more resource intensive.
  • /MT: This specifies how many threads to use when copying. If you’re regularly mirroring a lot of changes, setting it to 16 can be helpful in speeding up the opetation. If you leave off the :16 but keep /MT, it will default to eight threads. If you drop it all together, it will run single-threaded.

Last, select OK to finish defining the Action, then OK again to complete defining the task. If it asks you for a password, use your password from the Microsoft Account with which you’re logged in.

Now close the Task Scheduler and restart your computer to start it running. Wait about ten minutes and you’ll see your mirror folder populated with the contents of the source folder (or at least in mid-population) and you’re good to go.

Hope you found this helpful.

Add a Comment

Your email address will not be published. Required fields are marked *