Set Up a Local Backup Drive with File Versioning Using Robocopy on Windows 10/11
Difficulty: Intermediate |
Time Required: 30-45 minutes
Backing up your files to a second (local) drive is one of the simplest ways to protect your data. Using
Robocopy, a powerful built-in Windows tool, you can create a backup that not only mirrors your data but also
keeps multiple older versions of changed or deleted files.
In this tutorial, you’ll set up:
- A local backup drive (internal or external)
- A folder structure for versioned backups
- A repeatable Robocopy command (with an optional batch file) to run your backups whenever you like
This works on
Windows 10 and Windows 11 (Home or Pro).
Prerequisites
Before you start, make sure you have:
- A secondary drive
- Can be an internal HDD/SSD (D:, E:, etc. or an external USB drive.
- Must have enough free space to store your backups plus previous versions of changed files.
- A source folder to back up
Common choices:
C:\Users\<YourName>\Documents
C:\Users\<YourName>\Pictures
- Or a custom data folder, e.g.
C:\Data
- Basic familiarity with Command Prompt
- You should be comfortable opening Command Prompt and typing/pasting commands.
- An administrator account (recommended)
- Not strictly required for all locations, but often needed for system-related folders.
Note: Robocopy is built into Windows 10 and 11. No additional software is required.
Step 1 – Decide on Your Backup Strategy
You’ll use a simple but effective setup:
- Source folder: Your main data folder (e.g.
C:\Users\Alice\Documents)
- Backup root folder on backup drive: e.g.
E:\Backups
- Versioned backup subfolders:
E:\Backups\Current – latest backup (mirror of your source)
E:\Backups\Archive – older versions of files moved here when they change or are deleted
Robocopy will:
- Keep
Current in sync with your source (mirror)
- Move changed or deleted files from
Current into Archive, keeping previous versions instead of overwriting or losing them.
Step 2 – Prepare the Backup Drive and Folders
- Plug in / locate your backup drive
- Open File Explorer
- Note the drive letter (e.g.
D:, E:, F:).
- For this guide, we’ll assume the backup drive is E:.
- Create the backup folder structure
- On the backup drive, create:
E:\Backups
E:\Backups\Current
E:\Backups\Archive
- Confirm your source folder path
- Browse to your source folder in File Explorer.
- Click the address bar to see the full path, e.g.
- Write it down or keep the window open; you’ll need the exact path for the command.
Tip: Use simple names and paths without special characters or very long folder names to avoid path-length issues.
Step 3 – Open Command Prompt (or Windows Terminal)
You can run Robocopy in either
Command Prompt or
Windows Terminal.
- Press Win + X
- Click Windows Terminal (Admin) or Command Prompt (Admin) (on older builds of Windows 10, you may see “Command Prompt” instead of Terminal).
- If prompted by User Account Control (UAC), click Yes.
Note (Windows 11): Windows Terminal is the default. You can still run cmd inside it by selecting the Command Prompt profile or just typing cmd if you’re in PowerShell.
Step 4 – Build the Robocopy Command (With Versioning)
4.1 Basic mirroring without versioning (for reference)
A standard Robocopy mirror command looks like this:
robocopy "C:\Users\Alice\Documents" "E:\Backups\Current" /MIR /R:3 /W:5
/MIR – Mirrors the source to the destination (includes deletions).
/R:3 – Retry failed copies up to 3 times.
/W:5 – Wait 5 seconds between retries.
However,
/MIR alone
does not preserve older versions when files change or are removed.
4.2 Adding versioning using a backup (archive) directory
Robocopy has a
/B switch (for backup mode) and an
/MOV or /MOVE option? Those don’t directly do versioning. The key for versioning here is:
- Use
/XO – Exclude older files (so newer source doesn’t overwrite newer backup).
- Use
/MAXAGE or date-based directories, or…
- Better approach: Use
/XF and /XD carefully plus separate archive step.
A practical strategy:
- First move changed/deleted files from Current to Archive
- Then run a mirror from source to Current
That way:
- Any files that are about to be overwritten or deleted in
Current are first moved into Archive.
We’ll use two Robocopy commands:
- Archive step – Move “orphaned” files from
Current to Archive
- Mirror step – Mirror source to
Current
Step 5 – Create a Simple Versioning Script
You’ll store your Robocopy commands in a
batch file so you can run backups easily.
5.1 Create a batch file
- Open Notepad.
- Paste the following script, then we’ll customize it:
Code:
[USER=35331]@echo[/USER] off
setlocal rem === CONFIGURE THESE PATHS ===
set "SRC=C:\Users\Alice\Documents"
set "DEST=E:\Backups\Current"
set "ARCHIVE=E:\Backups\Archive" echo Starting backup at %DATE% %TIME%
echo Source: %SRC%
echo Destination: %DEST%
echo Archive: %ARCHIVE%
echo. rem === STEP 1: MOVE CHANGED/DELETED FILES FROM CURRENT TO ARCHIVE ===
echo Archiving changed/deleted files from CURRENT to ARCHIVE...
robocopy "%DEST%" "%ARCHIVE%" /MOVE /E /R:1 /W:2 /XJ /FFT
echo. rem === STEP 2: MIRROR SOURCE TO CURRENT ===
echo Mirroring source to CURRENT...
robocopy "%SRC%" "%DEST%" /MIR /R:3 /W:5 /XJ /FFT /COPY:DAT /DCOPY:T /V /NP /LOG+:"%ARCHIVE%\backup_log.txt" echo.
echo Backup completed at %DATE% %TIME%
endlocal
pause
- Edit the three paths near the top to match your system:
Code:
set "SRC=C:\Users\YourName\Documents"
set "DEST=E:\Backups\Current"
set "ARCHIVE=E:\Backups\Archive"
- In Notepad, click File > Save As…
- Set Save as type:
All Files (*.*)
- Name it something like:
DocumentsBackup.bat
- Save it somewhere convenient (e.g. Desktop or
C:\Scripts).
5.2 What this script does
- Step 1
robocopy "%DEST%" "%ARCHIVE%" /MOVE /E /R:1 /W:2 /XJ /FFT
- Treats
Current as the source and Archive as the destination.
/MOVE – Moves files (copy then delete from source).
/E – Includes subfolders, even empty ones.
- Effectively, any files still in
Current (from previous backups) are moved to Archive first.
- Step 2
robocopy "%SRC%" "%DEST%" /MIR ...
- Mirrors your live data into
Current, recreating the up-to-date view.
- Newly changed/removed files from prior runs are now preserved in
Archive.
Important Warning:
- The first run will move everything from
Current to Archive, then mirror the entire source into Current. That’s expected.
- After that, only changed/deleted files from previous backups are moved to
Archive.
Step 6 – Run Your Backup
- Double-click your
DocumentsBackup.bat file, or:
- Open Command Prompt
- Navigate to the folder containing the batch file, e.g.:
cd /d C:\Scripts
- Run it:
DocumentsBackup.bat
- Watch the output:
- You’ll see two Robocopy runs – archiving, then mirroring.
- At the end, the script pauses so you can see any messages.
- After completion:
- Open
E:\Backups\Current – it should match your source folder.
- Open
E:\Backups\Archive – it should contain previous versions and older copies.
Tip: Keep the batch file and backup drive names consistent. If the drive letter for your external disk changes, you must update the DEST and ARCHIVE paths in the script.
Step 7 – Optional: Add Date-Based Subfolders (More Granular Versions)
If you want to separate archive versions by date, you can slightly modify the script to use dated folders inside
Archive, like:
E:\Backups\Archive\2025-12-06\...
Add this after
setlocal in the script:
Code:
for /f "tokens=1-3 delims=./-" %%a in ("%DATE%") do ( set "YYYY=%%c" set "MM=%%a" set "DD=%%b")
set "TODAY=%YYYY%-%MM%-%DD%"
set "ARCHIVE=E:\Backups\Archive\%TODAY%"
And ensure that folder is created automatically by adding:
if not exist "%ARCHIVE%" mkdir "%ARCHIVE%"
before the first Robocopy command.
This way, each time you run the backup, old files are moved into a new date-stamped archive folder, making it easier to roll back to a specific day.
Step 8 – (Optional) Schedule Automatic Backups
On Windows 10/11, you can use
Task Scheduler to run the batch file automatically.
- Press Win + R, type
taskschd.msc, and press Enter.
- In the right pane, click Create Basic Task…
- Name it, e.g. Documents Robocopy Backup.
- Choose a Trigger:
- Daily, Weekly, or When I log on.
- Choose Start a program.
- Browse to your
DocumentsBackup.bat file.
- Finish the wizard.
Tip:
- On laptops, you may want to check the option “Run task as soon as possible after a scheduled start is missed” and configure it to run only if the backup drive is connected (this requires using conditions and possibly a more advanced setup).
Tips and Troubleshooting
1. Long Paths or Special Characters
- If you see errors like “ERROR 123” or path too long:
- Keep folder names shorter.
- Avoid very deep nested folders.
- You can consider enabling long path support in Windows 10/11 (Group Policy or registry), but that’s outside this tutorial’s scope.
2. Permissions / Access Denied
- Run your batch file as Administrator (right-click > Run as administrator).
- Avoid backing up system-protected folders (e.g.,
C:\Windows) with this simple script.
3. Excluding Certain Folders or Files
Add these switches to the
mirror command in the script if needed:
- Exclude folders:
/XD "Temp" "Cache"
- Exclude files by pattern:
/XF *.tmp *.bak *.iso
Example:
robocopy "%SRC%" "%DEST%" /MIR /R:3 /W:5 /XJ /FFT /COPY:DAT /DCOPY:T /XD "Temp" /XF *.tmp
4. Checking Logs
The script uses:
/LOG+:"%ARCHIVE%\backup_log.txt"
- This appends logs to
backup_log.txt in your archive folder.
- Open it in Notepad to review:
- How many files were copied/moved
- Any errors that occurred
5. Verifying Backup Integrity
- Periodically open files directly from
E:\Backups\Current and E:\Backups\Archive:
- Make sure documents open correctly.
- Confirm that you can restore an older copy from
Archive if needed.
Conclusion
Using Robocopy with a simple script, you’ve created a
local backup system with file versioning:
- Your Current folder mirrors your latest data.
- Your Archive folder stores older versions of files and previously deleted items.
- With optional scheduling, your backups can run automatically in the background.
This setup is lightweight, uses only built-in Windows tools, and gives you a safety net against accidental changes, corruption, or deletion.
Key Takeaways:
- Robocopy on Windows 10/11 can create powerful, scriptable backups without extra software.
- A two-step process (archive then mirror) lets you preserve older versions of changed or deleted files.
- Storing backups on a separate local drive greatly reduces the risk of data loss from drive failure or mistakes.
- Batch scripts and Task Scheduler make running and automating backups straightforward.
- Regularly verifying your backups and logs ensures your data is actually protected when you need it.
This tutorial was generated to help WindowsForum.com users get the most out of their Windows experience.