How to Preserve File Timestamps During Backup With xcopy on Windows 11
🔍 WiseChecker

How to Preserve File Timestamps During Backup With xcopy on Windows 11

Quick fix: Use xcopy with /k flag (keep attributes). Better: use robocopy instead, which preserves timestamps by default. Example: robocopy C:\Source D:\Backup /e /copy:DAT /dcopy:T. This copies all files including subdirectories, preserves Data, Attributes, Timestamps for files, and copies directory timestamps. Modern recommendation: robocopy over xcopy.

Standard copy command and File Explorer drag-drop reset file dates to “now.” This breaks backup sorting, version checks, sync tools. xcopy and robocopy can preserve original timestamps. robocopy is more powerful and is Microsoft’s recommendation.

Symptom: Want to preserve file Created/Modified timestamps during backup with xcopy or robocopy on Windows 11.
Affects: Windows 11 (and Windows 10).
Fix time: ~5 minutes (plus copy time).

ADVERTISEMENT

What causes this need

Many workflows rely on file dates:

  • Backup verification: sort by date to find recent changes.
  • Version control: timestamps confirm which is newest.
  • Sync tools (rsync, Resilio): use timestamps to detect changes.
  • Forensics / compliance: timestamps are evidence.
  • Photo / media organization: shoot dates.

Default copy sets Created = now, breaking these workflows.

Method 1: xcopy with /k flag

The legacy route.

  1. xcopy is the older Windows copy utility. To preserve timestamps:
    xcopy "C:\Source" "D:\Backup" /e /i /h /k
    • /e: include all subdirectories.
    • /i: treat destination as directory.
    • /h: copy hidden files.
    • /k: preserve file attributes (includes read-only state).
  2. xcopy preserves Modified timestamp by default. Created timestamp is reset.
  3. For preserving more: limited via xcopy. Better to use robocopy (Method 2).
  4. For overwrite handling: add /y (no prompt to overwrite).
  5. For continue on error: /c.
  6. For verbose output: /v.
  7. Example with full options:
    xcopy "C:\Source" "D:\Backup" /e /i /h /k /y /c

This is the xcopy approach.

ADVERTISEMENT

Method 2: robocopy for full timestamp preservation

The modern recommendation.

  1. robocopy is Microsoft’s replacement for xcopy. Built into Windows.
  2. Basic mirror with timestamps:
    robocopy "C:\Source" "D:\Backup" /e /copy:DAT /dcopy:T
    • /e: copy all subdirectories (including empty).
    • /copy:DAT: copy Data, Attributes, Timestamps for files. Default is DAT.
    • /dcopy:T: copy directory timestamps too. Default doesn’t copy these.
  3. This preserves: file Modified timestamp, Attributes (read-only, hidden, etc.), directory Modified timestamp.
  4. For Created timestamps: not preserved by default. Add: /copy:DATSO for Data, Attributes, Timestamps, Security, Owner. Still not Created. Need specific flag.
  5. For Created + Modified + Accessed:
    robocopy "C:\Source" "D:\Backup" /e /copy:DATSO /dcopy:DAT

    DATSO for files; DAT for directories.

  6. For mirror mode (delete files in dest that aren’t in source): add /mir. Caution: deletes.
  7. For resume / sync: /z (restartable mode).
  8. For logging: /log:C:\backup-log.txt.

This is the robocopy way.

Method 3: PowerShell for granular timestamp control

For specific requirements.

  1. PowerShell can copy with full timestamp preservation:
    Get-ChildItem "C:\Source" -Recurse | ForEach-Object {
        $dest = $_.FullName.Replace("C:\Source", "D:\Backup")
        if ($_.PSIsContainer) {
            New-Item -ItemType Directory -Path $dest -Force | Out-Null
        } else {
            Copy-Item -Path $_.FullName -Destination $dest -Force
            $destFile = Get-Item $dest
            $destFile.CreationTime = $_.CreationTime
            $destFile.LastWriteTime = $_.LastWriteTime
            $destFile.LastAccessTime = $_.LastAccessTime
        }
    }
  2. This copies each file and explicitly sets all three timestamps.
  3. Slower than xcopy/robocopy due to per-file Copy-Item overhead.
  4. For very large file counts: stick with robocopy.
  5. For mass-renaming with timestamp preservation: extract date from file content (EXIF for photos), set Created/Modified to match.
  6. For backup verify: after copy, compare hashes:
    Get-FileHash "C:\Source\file.txt" -Algorithm MD5
    Get-FileHash "D:\Backup\file.txt" -Algorithm MD5

    Match means data integrity preserved.

This is the granular approach.

How to verify the fix worked

  • Compare source and dest: right-click file in source → Properties → note Created, Modified, Accessed dates.
  • Same for dest. Dates should match (within microsecond precision, depending on filesystem).
  • For batch verify: dir /tw /tc in cmd. /tw = sort by write time, /tc = sort by create time.
  • robocopy log: search for “Mismatch” entries. Should be none.

If none of these work

If timestamps don’t preserve: Filesystem limitation: FAT32 has 2-second granularity. exFAT has 10ms. NTFS has 100ns. ReFS has nanoseconds. Filesystem-to-filesystem mismatch: timestamps round. For OneDrive / network shares: server may set Modified to server time. Local files preserved. For permission issues: can’t set timestamps on files where user lacks ownership. Run as Admin or take ownership. For files in use: in-use files may not preserve timestamps. Close apps first or use /B in robocopy (backup mode, requires Admin). For VSS-based backups: Volume Shadow Copy preserves timestamps inherently. Tools like Macrium Reflect use VSS. For Linux / macOS source: ext4 / APFS timestamps may have nanosecond precision; rounding occurs to NTFS. For specific date forensics: tools like ExifTool can read/write timestamps in alternate locations (file metadata).

Bottom line: Use robocopy "C:\Source" "D:\Backup" /e /copy:DAT /dcopy:T for standard timestamp preservation. Add /copy:DATSO /dcopy:DAT for fuller preservation. xcopy /k for legacy compatibility.

ADVERTISEMENT