用 robocopy /MIR 镜像文件夹做精确备份

robocopy 是 Windows 内置的健壮复制工具,/MIR 可以让目标目录与源目录保持完全一致的镜像,且支持断点续传。

Windows文件系统终端高风险
运行 `robocopy "C:\Data" "E:\Backup\Data" /MIR /R:2 /W:5` 将源目录镜像到目标——注意 /MIR 会删除目标端多余的文件。

01命令

命令
$ robocopy "C:\Data" "E:\Backup\Data" /MIR /R:2 /W:5 /DCOPY:DAT /COPY:DAT

02作用说明

/MIR 等价于 /E(复制所有子目录,含空目录)加 /PURGE(删除源目录中已不存在的目标文件),因此目标是源的精确副本。/R:2 /W:5 把重试次数限制为 2 次、间隔 5 秒,避免被占用的文件让任务挂上几天;/COPY:DAT /DCOPY:DAT 则保留文件和目录的时间戳与属性。加 /MT:8 可开启多线程,任务中断后重跑同一命令会自动续传。关注退出码:0 表示无文件需要复制,1 表示成功复制,8 及以上表示有失败项(可用 /LOG:路径 和 /TEE 记录日志)。

03风险

风险高风险
使用条件Destination must exist or be creatable; deleted files in the source will also be deleted in the destination.
!注意: /MIR 具有破坏性:一旦源和目标路径写反,目标数据会被清空——先用 /L(仅列出将要执行的操作)做演练。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • robocopy | Microsoft Learn
    Microsoft · vendor-doc · 2026-09-17
    依据: Microsoft documents robocopy /MIR as mirroring a directory tree, copying all subdirectories including empty ones and deleting destination files no longer present in the source.
  • Robocopy - Robust File Copy - Windows CMD
    SS64 · technical · 2026-09-17
    依据: SS64 documents /COPY:DAT as copying data, attributes and timestamps, and /R and /W as retry count and wait time between retries.

最后验证: 2026-09-17 · 分类: 文件与文件夹

06相关方案