How to back up folders with robocopy

Overview

robocopy is Windows' robust folder-copy utility. It handles subfolders, retries, metadata, exclusions, logs, and restartable jobs.

Warning: /MIR can delete destination files that are absent from the source. Learn with additive copies and /L previews first.

  • ROBOCOPY syntax starts with a source folder and destination folder, followed by optional file filters and switches.
  • Run the same job again to copy only additions and changes.
  • Open the log and inspect summary counts, skipped files, and failures.

Commands to try

Type each command at the prompt, then press Enter. Replace sample names and paths with ones that exist on your computer.

Commands are generally not case-sensitive, but preserving the spelling shown here makes scripts easier to read.

robocopy "%USERPROFILE%\Documents\CmdPractice" "D:\Backups\CmdPractice" /e /r:2 /w:2
robocopy Source Destination /e /l
robocopy Source Destination /e /xj /log:backup.log
robocopy Source Destination /e /xf *.tmp /xd Cache

Useful options and details

Options change how a command behaves. Add spaces exactly as shown, and use the command's built-in help when an option is unfamiliar.

A path containing spaces must be enclosed in double quotes, such as "C:\My Files".

  • /e includes all subfolders, including empty ones; /s excludes empty ones.
  • /l lists what would happen without copying; /r:n and /w:n limit retries and wait time.
  • /xj excludes junctions, reducing loop risk; /log:file writes a log.

Tips and common mistakes

Check the current folder and read the command output before assuming an operation succeeded.

Practice with disposable files first. Commands that delete, overwrite, or stop a process may not offer an Undo button.

  • ROBOCOPY success uses exit codes 0 through 7 for various nonfatal outcomes; codes 8 and above indicate failures.
  • Do not treat sync or mirroring as the only backup: accidental deletion or ransomware can propagate.
  • Verify free space, destination identity, copied counts, and a sample restore before trusting a backup.

Safe practice

Create a temporary practice folder under your user profile so the examples cannot affect Windows system files.

After each command, inspect the result with dir or another read-only command before continuing.

  • Create separate disposable Source and Destination folders.
  • Preview an /e copy with /l, then run it.
  • Change one source file, rerun, inspect the log, and restore a sample.