From Scattered Copies to One Library: A Photo Backup and De-duplication Strategy
Everyone who has taken photos for more than a few years ends up with the same mess. There’s a folder from the old laptop, a “backup” external disk from 2019, another one from 2022 that is mostly the same, a phone export, and a NAS share that holds some of each. Every copy was made in good faith. Together they’re a pile of overlapping, half-trusted duplicates, and nobody can say with confidence which files exist only once.
I’ve been building photo-organizer, a command-line tool for this problem, and while using it on my own disks I wrote down the strategy I ended up with. This post is that strategy. The commands are photo-organizer’s, but the ideas apply to whatever tools you use.
The goal is three things, in order:
- one clean, de-duplicated library per media kind,
- a real, independent backup of each library,
- retiring the old scattered copies, but only after both of those exist and are verified.
Three roles
The most useful step was to give every folder exactly one role.
| Role | What it is | Who writes to it |
|---|---|---|
| Source | Existing scattered folders and old backups | nobody new; tools only read them |
| Library | One de-duplicated copy, laid out YYYY/YYYY-MM-DD/ | only organize |
| Backup | A copy of the library on a different disk or machine | only backup |
sources (messy, many) --organize--> library (one clean copy) --backup--> backup (other disk)
The non-obvious part: old backups are sources, not backups. That 2019 disk and the 2022 disk overlap heavily, and neither one is a copy of anything in particular. Treating them as backups is how you end up “protected” by three disks that each lack a different 10% of your photos. In this scheme they’re inputs. Merging them into the library collapses the duplicates, and the backup is something new that you make from the library.
Principles
Copy first, delete last
Nothing is ever changed in a source. The tool reads sources and writes to the library. A source gets deleted only after its contents are verified in the library and the library has been backed up. Deletion is always a manual step. No command deletes sources as a side effect.
A backup is an independent copy
It’s tempting to save space by hardlinking library files to the originals. Don’t. A hardlink is a second name for the same bytes, so one disk failure or one in-place edit hits both “copies,” and many backup tools handle hardlinks badly. Filesystem block cloning (reflinks, APFS clones) has the same problem from a durability point of view. If the backup can’t survive the loss of the original’s disk, it isn’t a backup.
Verify by content, not by name
File names and sizes lie. IMG_0001.JPG exists in every camera’s history. For speed, photo-organizer’s scan hash only samples the first and last 32 KB of each file, which is good enough to find likely duplicates but not to prove them. Until whole files are compared, a duplicate group is “unconfirmed.” So the real library build uses full verification:
photo-organizer organize <sources> --type photo --dest <photo-library> --verify full
Keep photos and videos apart
Photos and videos differ in size, value per gigabyte, and how carefully they’re worth verifying. A terabyte of video is a handful of files. A terabyte of photos is a quarter million. I keep them in separate libraries, both laid out by date:
photo-organizer organize <sources> --type photo --dest <photo-library> --verify full
photo-organizer organize <sources> --type video --dest <video-library> --verify auto
One subtlety: files that share a base name are classified as a group, and any photo in the group makes it a photo group. So a RAW+JPG pair stays together, and so does the .mov half of an iPhone Live Photo, which belongs next to its still rather than among your videos. The two runs never overlap, and together they’re equivalent to one run without --type.
Manifests must tell the truth
Every analysis (finding duplicates, checking backup coverage) runs on scan manifests. A manifest that still lists a file you deleted last month will happily count it as a second copy. That’s exactly the wrong answer, because it makes a single-copy file look safe. So scan prunes rows for deleted files by default. As a safety valve, pruning is skipped if the scan couldn’t read some folders (an unmounted share shouldn’t look like mass deletion) or if it would remove more than half the rows.
Removable disks need a stable identity
An external disk mounts at different paths on different machines and on different days. Scanning it with --media-id <name> writes a small machine-id file to the disk root once, so the disk is recognized wherever it shows up. If you want a disk left completely untouched, --no-write-media-id skips that.
The workflow
- Check free space on every disk involved. The library needs room, and a nearly full disk (especially a ZFS pool) slows down and leaves no space for the backup.
- Scan each top-level root, read-only:
Prefer one manifest per top folder. Scanning a parent and a child is harmless but wasteful. Re-scan existing roots rather than inventing new, bigger ones, so cached hashes are reused.photo-organizer scan <root> - Look at what you have:
photo-organizer dups ~/manifests/_Manifest/*.csv photo-organizer dup-folders --top 20 ~/manifests/_Manifest/*.csv - Preview the library build. A preview copies nothing and can save the exact plan:
Read the summary: copy size, duplicate counts, date ranges, warnings. Keep the plan file somewhere permanent. It’s the record of why every file is where it is.photo-organizer organize <sources> --type photo --dest <library> \ --verify full --save-plan plan.json - Apply exactly what you previewed:
photo-organizer organize --plan plan.json --apply - Verify. Run the preview again. It should report nothing left to copy. Then run
check-backup. - Back up the library:
photo-organizer backup <library> --dest <target>backupmirrors into a folder with the library’s name inside the target, so pass the parent folder, not the final one. - Retire a source, by manual delete or
archive, only after steps 6 and 7 pass.
Two practical notes:
- When space is tight, work in slices. Take one source subfolder at a time: copy, verify, back up, then free that slice. The peak extra space is then one slice instead of the whole library.
- Order matters.
organizekeeps the first copy of each piece of content it meets and visits sources in path order. If two trees share content and you prefer one as the origin, say the better-named or better-dated one, list it first.
Where the backup lives
- It must be on a different disk, ideally a different machine, with room for the whole library.
- A second dataset on the same disks or pool protects against accidental deletion, not against disk or pool failure.
- A single external disk is a good second copy, but not a safe only copy.
- NTFS and exFAT reject some filenames and are case-insensitive. Watch
backupoutput for errors on odd names. - If the target disk already holds old data, scan it and compare it with everything else first. You need to know whether that data is itself backed up before you write anything to the disk.
Before you hit apply
A preview is only useful if you read it. These are the things I check:
- Unset camera clocks. Hundreds of files dated January 1st of some year usually means a camera that lost its clock. They’ll all land in one folder.
- Dates from modified time only. If a file has no EXIF or container date, its date comes from the filesystem, and that isn’t trustworthy after a copy or restore.
- Duplicate counts are estimates until
--verify fullhas compared whole files. - Stale manifests. A manifest that’s months old can still list files that no longer exist. Re-scan before trusting it.
Multiple machines
The next step I’m working toward is a hub model. One machine holds the library and its own backup. Every other machine only pushes to it: scan locally, backup <root> --dest <hub>:<incoming>, then collect the manifests and check-backup from the hub. That needs SSH keys, the hub registered with collect --add, and photo-organizer installed on each remote. The incoming folders are just more sources, so the same three-role rules apply.
Takeaways
- Give every folder one role: source, library, or backup.
- Old backups are sources. The real backup is made fresh from the library.
- Copy first, verify by content, back up, and only then delete, by hand.
- Hardlinks and clones aren’t backups.
- Keep the plan file, and read the preview before you apply it.
None of this is complicated. What it takes is discipline about the order of operations. Photos are one of the few kinds of data that can’t be regenerated, so I’d rather follow a slow, boring process than find out later that a file existed only once.