Preventing Corrupted File Copies Overwriting OK Versions: Mac & NAS
In today's interconnected world, backing up files has become an essential task for many individuals and organizations. This article will focus on a common scenario where a user wants to prevent corrupted file copies from overwriting OK versions when backing up files from a Mac to a Network Attached Storage (NAS) device.
The Scenario
Let's consider a specific scenario: Today is November 11, 2024, and everything seems to be fine with your Mac's SSD. You decide to make a backup of your files to your NAS device. Time goes by, and on June 1, 2025, you decide to restore a file from the backup. Unfortunately, you discover that a corrupted version of the file was backed up and has now overwritten the OK version on your Mac.
The Solution: Rsync and Hard Links
One solution to this problem is to use the rsync command, which includes a feature called hard links. Hard links allow rsync to create a link to the file on the source instead of copying the file to the destination when the file already exists on the destination with the same contents and permissions.
Rsync Command
Here's an example rsync command:
rsync -avh --progress --delete --update --inplace --links /path/to/source /path/to/destination
-a: archive mode, which preserves timestamps, permissions, and other attributes-v: verbose mode, which displays transfer progress and other information-h: human-readable mode, which displays file sizes in a human-readable format--progress: displays progress during the transfer--delete: deletes files on the destination that don't exist on the source--update: skips files that already exist on the destination with the same size and timestamps--inplace: updates files in-place, instead of creating temporary files--links: preserves hard links
In this example, /path/to/source is the source directory on your Mac, and /path/to/destination is the destination directory on your NAS device.
References
- O'Reilly. Using Rsync to Manage and Backup Data (2015).
- Brian Moses. Strategy for backing up Mac laptops to a NAS over wireless (2009).
- man rsync: https://linux.die.net/man/1/rsync