logo
search
Data Backup Problems

How to Back Up Local Folders to OneDrive Using Robocopy

Maira MehtabMaira Mehtab Sep 27, 2026 870 views

Question details

The user wants to automate the process of copying local directories, such as Desktop and Documents, to a OneDrive backup folder using Robocopy.

Product
Microsoft OneDrive
Device & OS
Windows
Scenario
Creating a reliable and automated script to continuously back up important local files to cloud storage via the OneDrive sync client.
Observed behavior
Files need to be successfully copied to the OneDrive sync directory without requiring complex symbolic links, while accurately handling subfolders and file deletions.
Before you start

Ensure that the Microsoft OneDrive desktop application is installed, actively running, and you know the exact local path of your OneDrive synchronization folder.

Solution 1Recommended

Create and Schedule a Robocopy Backup Script

Use the Windows built-in Robocopy tool to directly copy your local directories into your OneDrive folder, and automate it using Windows Task Scheduler.

Robocopy (Robust File Copy) is a powerful command-line tool built into Windows. You can use it to copy local folders directly into your local OneDrive synchronization directory. Once copied locally, the OneDrive application will automatically upload these files to the cloud. You do not need to use 'mklink' or symbolic links for this method.

1
Identify source and destination paths

Determine the exact file paths for the folder you want to back up (for example, %USERPROFILE%\Documents) and your OneDrive destination folder (for example, %USERPROFILE%\OneDrive\Backups).

2
Write the Robocopy command

Open Notepad and type your Robocopy script. For a standard copy that includes all subfolders and excludes specific build folders, use: robocopy "%USERPROFILE%\source" "%USERPROFILE%\OneDrive\Backups\source" /E /XD bin obj

3
Choose between /E and /MIR

Use the /E flag to copy subfolders without deleting files from your OneDrive destination if they are removed from the local source. Alternatively, use /MIR to perfectly mirror the folder. Use /MIR with caution, as deleting a local file will also delete the backup in OneDrive.

4
Save as a batch file

Save the text document with a .bat file extension (e.g., OneDriveBackup.bat). Ensure 'Save as type' is set to 'All Files' in Notepad.

5
Automate with Windows Task Scheduler

Open Windows Task Scheduler and click 'Create Basic Task'. Set the trigger to run 'Daily' or 'At log on'. In the 'Action' step, select 'Start a program' and point it to your newly created .bat file.

Important Warning About the /MIR Switch: The /MIR switch forces a strict mirror of the source directory. If a file is accidentally deleted from your local source folder, Robocopy will permanently delete it from the OneDrive backup folder during its next run.
Free Microsoft Office alternative

A Simpler Way to Back Up and Sync Your Documents

While configuring Robocopy scripts is powerful, managing command-line automated tasks can be tedious and prone to error. If you are primarily looking to back up Office documents, WPS Office provides an all-in-one productivity suite with built-in Cloud sync. As a highly compatible, free Microsoft Office alternative, it seamlessly saves and backs up your files across all your devices without requiring a single line of code.

  1. 1. Download WPS Office: Visit the official WPS website and download the free installer for your operating system.
  2. 2. Install the Suite: Run the setup file and follow the quick on-screen instructions. The installation is lightweight and fast.
  3. 3. Enable Cloud Sync: Sign in to your free WPS account and turn on WPS Cloud to automatically save and back up your documents as you work.
Fully compatible with Microsoft Word, Excel, and PowerPoint formats (.docx, .xlsx, .pptx).Built-in WPS Cloud storage to automatically sync and securely back up your documents.Lightweight application that runs smoothly on Windows, Mac, Linux, and mobile devices.Free to download and use with a highly familiar, tabbed user interface.
microsoft office alternative - wps office

Frequently Asked Questions

Do I need to use mklink to sync local folders to OneDrive?

No, you do not need to use mklink (symbolic links). You can use a Robocopy script to directly copy the files from your local folders into the standard OneDrive synchronization directory. OneDrive will detect the newly copied files and sync them automatically.

What is the difference between /E and /MIR in a Robocopy script?

The /E parameter copies all subdirectories, including empty ones, but leaves files in the destination intact even if they are removed from the source. The /MIR parameter acts as a mirror; it will copy new files but also delete files from the destination folder if they have been removed from the source.

How do I exclude specific folders from my Robocopy backup?

You can use the /XD flag followed by the names of the directories you wish to exclude. For example, adding '/XD bin obj' to your command will prevent those specific folders from being copied to your OneDrive backup directory.

How can I run my backup script automatically without manually clicking it?

You can fully automate your .bat script using the Windows Task Scheduler. Simply create a new basic task, choose a recurring schedule (such as daily or upon logging in), and set the action to run your saved Robocopy batch file.