rsync kopiert immer wieder alle Dateien neu auf USB-Stick

01. März 2025 · Anwendungen · andreas · Kein Kommentar

Gerade wenn es darum geht, daß nur ein Delta kopiert werden soll, ist rsync (gegenüber z.B. cp) mein Werkzeug der Wahl. Umso erstaunter war ich daß rsync bei einem

# rsync -av /meine-quelle /mnt/stick/

immer wieder alle Dateien neu auf den USB-Stick kopierte, auch wenn zwischenzeitlich an der Quelle keine Änderungen vorgenommen wurden.

Einen ersten Hinweis auf die Ursache liefert der Beitrag “rsync to USB flash drive always transferring all data” bei Stack Exchange, denn der Stick war tatsächlich mit exFAT formatiert.

Eine Suche nach Hintergrundinformationen führte zum Microsoft Dev Blog-Beitrag “Why does the timestamp of a file increase by up to 2 seconds when I copy it to a USB thumb drive?

This means that copying a file to a FAT-formatted device (typically a floppy drive or a USB thumb drive) can increase the timestamp by up two seconds.

in dem die Erklärung, warum immer aufgerundet wird, gleich mitgeliefert wird:

To avoid this infinite loop, the convention is always to round up, so that the copy of a file is never older than the original.

Zumindest der referenzierte Knowledge Base-Artikel “KB127830 - Time Stamps Change When Copying From NTFS to FAT” ist über die WaybackMachine des Internet Archive noch zu finden und erklärt den Mechanismus:

File time stamps on FAT drives are rounded to the nearest twoseconds (even number) when the file is written to the drive. The file timestamps on NTFS drives are rounded to the nearest 100 nanoseconds when thefile is written to the drive. Consequently, file time stamps on FAT drivesalways end with an even number of seconds, while file time stamps on NTFSdrives can end with either even or odd number of seconds.

When files are copied from NTFS drives to FAT drives, somefile time stamp rounding has to occur; the file time stamp is rounded up to the next even second.

Auch wenn sich das Beispiel auf NTFS vs. FAT bezieht, gilt das gleiche auch im Hinblick auf ext4 und FAT. Abhilfe schafft der Parameter “–modify-window” auf den auch die rsync-FAQ hinweist:

Another common cause involves sending files to an Microsoft filesystem: if the file’s modified time is an odd value but the receiving filesystem can only store even values, then rsync will re-transfer too many files. You can avoid this by specifying the –modify-window=1 option.

Mit dem Aufruf

# rsync -av --modify-window=1 /meine-quelle /mnt/stick/

lässt sich rsync von der Rundung nicht mehr aus der Ruhe bringen und verhält sich wie erwartet.