I’ve spent a good part of this year on Unity Catalog backups at scale: thousands of Delta tables, nightly DEEP CLONE into a separate backup catalog, and a backup window that kept getting longer. The obvious fix was “only clone tables that actually changed.” It mostly works, but it took me a few iterations, and one benchmark result I didn’t like, to get it right. This is what I learned.
Why clones copy more than you’d expect
DEEP CLONE is incremental, but at the file level. If a MERGE touches three rows, every Parquet file holding those rows gets rewritten, and the next clone copies those files. OPTIMIZE and auto-compaction are worse for this: they rewrite files with zero logical change, and the clone happily copies all of it again.
So the idea is simple. Before cloning, look at the source table’s Delta history and skip the clone if nothing since the last backup was a real data change.
The gate
I keep the last cloned source version as a table property on the backup table itself (backup.sourceVersion), so there’s no control table to maintain. On the next run I read the commits after that version and ignore pure maintenance:
IGNORE_OPS = {"OPTIMIZE", "VACUUM START", "VACUUM END", "SET TBLPROPERTIES",
"UNSET TBLPROPERTIES", "COMPUTE STATISTICS", "ANALYZE TABLE", "FSCK", "REORG"}
I also ignore commits whose metrics prove nothing happened, for example a MERGE with zero rows inserted, updated and deleted, or an append that wrote zero rows. If a metric is missing, or the write mode was overwrite, I treat it as a change. Anything left over means clone.
The bug: DROP + CREATE
The first version compared versions only, and in testing I found a backup table sitting at 0 rows while the source had 6.
The source was loaded by an ETL job that drops and recreates the table. A recreated table starts its version counter over, and it landed on the same version number my marker had stored. The gate saw “same version, nothing to do” and skipped it, every night. Nothing failed, and nothing looked wrong in the job output. That’s the scary kind of backup bug.
The fix is to store the source table’s id (from DESCRIBE DETAIL) next to the version, in backup.sourceTableId, and clone whenever it changes. More generally, I made every uncertain case fall back to cloning: history vacuumed past the marker, a version that went backwards, a non-Delta source, any read error. A gate that skips one clone it should have run is worse than no gate at all.
Then the gate itself was the slow part
Once it was correct, I looked at a production run that took about two hours. The individual clones were taking 0.1 to 0.6 minutes. Most of the time was spent deciding whether to clone. Three things were wrong:
- I was calling
DESCRIBE HISTORY without a LIMIT. For tables loaded often or maintained by Predictive Optimization, that’s thousands of commits read per table, per run. Now I read LIMIT 1 to get the current version, then LIMIT n for only the commits after the marker.
- The marker only moved after a real clone, so for tables that kept getting skipped, the window I had to inspect grew every night. Now the marker advances when a clone is skipped for maintenance-only reasons.
- The checks shared the clone thread pool (8 threads). Checking is cheap metadata work, so I split it into two phases: check everything at 32 threads, then clone only what’s needed at 8.
On a test workspace with 48 synthetic tables (20 to 2,000 commits each), a full gating pass went from 85.6 s to 16.3 s. I wrote 15 correctness tests for the cases that scared me (a DELETE buried among 80 maintenance commits, a zero-row MERGE, DROP + CREATE landing on the same version), and all 15 pass.
The result I didn’t like
I expected gating to cut the bytes we copy. So I set up an A/B run on a 5-million-row, 200-file table, old approach against new, through a mix of maintenance and small writes.
Total bytes copied were 695.7 MB in both cases.
The gate correctly skips the clone right after an OPTIMIZE. But the next time someone inserts even one row, the clone has to copy every file OPTIMIZE rewrote. In my test that was about 198 MB to back up a one-row insert. Gating doesn’t remove the OPTIMIZE cost; it just moves it to the next real write.
That explained why there was little gain on the busiest tables, which get loaded between every backup. Where gating does pay off is tables that are maintained but rarely written: reference data, archives, slowly changing dimensions. For the busy tables, the real options are to run OPTIMIZE right after the backup instead of before it, to back them up less often if the recovery point allows, or to just budget for the copy.
If you’re building something similar
Store both the version and the table id on the backup table. Default to cloning whenever you can’t prove nothing changed. Never read the full history. Advance the marker on skips. Keep checking and cloning on separate thread pools. And measure bytes copied, not just how many tables were skipped. My skip rate looked great on a dashboard while the bytes didn’t move at all.