rsync on macOS copies "phantom data" when drive disconnects

Super User Asked by zyklus on December 2, 2020

I’m trying to copy files off of a drive that is failing. It hasn’t failed yet 🙂

Basically it keeps disconnecting every 30 seconds. macOS then automatically remounts it, but Finder is having issues copying files.

So I’m trying to use rsync -a --progress, but every time the drive disconnects rsync just "keeps going", and fills the rest of the file with… I dunno, something. I’d assume it’d write zeros, but it’s writing actual data according to hexdump. In any case, it’s not accurate data.

I’ve been able to reproduce the behavior by rsync’ing from a random SD card. If I pull the card while copying a 4gb file rsync just zips through and writes a full 4GB file, even though that’s nonsense.

How do I get rsync to stop copying phantom data when a drive is disconnected??

The problem is that in 2020, macOS ships with a version of rsync from 2006.

One Answer

Rsync should exit if the destination drive gets disconnected. You may need to specify a shorter timeout (in seconds) for this behavior to work properly if the drive is reconnecting quickly.

Something like rsync -a --progress --timeout 2

Relevant man info:

       This  option  allows you to set a maximum I/O timeout in seconds. If no data is transferred for the specified time then rsync will exit. The default is 0, which means no timeout.

Correct answer by tbenz9 on December 2, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP