brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: run robocopy /MIR with /L first, because it deletes

Backup
~/tips/tip-windows-robocopy-mir-list-only

robocopy C:\Data D:\Backup /MIR /L

Shows what a robocopy mirror would copy and delete before it touches any file.

Robocopy is still the best built-in way to copy a big folder on Windows, and /MIR keeps a backup folder identical to the source. Microsoft describes it as /e plus /purge, and that second half deletes files in the destination that aren’t in the source anymore. Mix up source and destination once and your backup copies an empty folder over your data.

So I always do a dry run first. /L only lists what would happen:

robocopy C:\Data D:\Backup /MIR /L

Read the list with care, above all the files it would remove from the destination. If the list looks right, run the same command without /L.

Two more switches I’d add for a real run:

robocopy C:\Data D:\Backup /MIR /R:2 /W:5 /LOG:C:\Logs\backup.log

The default is one million retries with 30 seconds between them, so one locked file can stall a copy for a very long time. /R:2 /W:5 keeps that short. /LOG writes the output to a file and overwrites it each time; use /LOG+ to append.

Caveat for scripts: robocopy’s exit codes aren’t the usual 0-is-good. Per the docs, 0 to 7 mean no failure (1 is files copied) and 8 or higher means at least one failure. A script that treats anything but 0 as an error will cry wolf every time.

Further reading: Microsoft Learn: robocopy

More Backup tips restic snapshots --group-by host,paths mysqldump --routines --events mydb > mydb.sql rsync -a --files-from=list.txt /home/me/ backup:/backup/ restic find "*.txt" restic stats All Backup tips (45) All topics

Link