Sub topic 9
Limits of time travel and why it is not a backup
This chapter assumes you can run DESCRIBE HISTORY, query with VERSION AS OF, and use RESTORE. It also assumes you know that VACUUM removes old data files. Here you will see where time travel stops working and what to use instead for real recovery.
What decides how far back you can go
Two separate things must both still exist for a past version to be readable:
- The commit entries in the transaction log (the JSON files in
_delta_log). These are controlled bydelta.logRetentionDuration. - The data files that version points to. These are controlled by
delta.deletedFileRetentionDurationand by whether anyone ranVACUUM.
If either is gone, the version cannot be read. The log can still list a version while its data files are already deleted. That case produces the most confusing errors.
ALTER TABLE main.sales.orders SET TBLPROPERTIES (
'delta.logRetentionDuration' = 'interval 30 days',
'delta.deletedFileRetentionDuration' = 'interval 7 days'
);These values are the defaults. In practice the usable window is often closer to the 7-day file retention than to the 30-day log retention, because VACUUM deletes files once they pass the shorter period.
Limits you will run into
- VACUUM removes the files. After
VACUUM, any version that needed the deleted files fails to load, even thoughDESCRIBE HISTORYmay still show it. - Log cleanup removes the commit. Log entries are cleaned up in the background, usually when new checkpoints are written. Past the log retention period, the version number is gone.
- Shortening retention is a one-way door. If you set
deletedFileRetentionDurationto a low value and runVACUUM, the files are deleted. Raising the setting later does not bring them back. - Schema and metadata follow the version. You read old data with the schema of that version, which can differ from today's table.
- Time travel is per table. It does not roll back several tables to one consistent moment. You must restore each table yourself.
- Dropped tables are different. If you drop a managed table, its files are removed. History does not help you. Unity Catalog offers
UNDROP TABLEfor a limited period, but that is a separate feature.
A failed read after VACUUM looks like this:
SELECT * FROM main.sales.orders VERSION AS OF 5;Typical outcomes are an error that the version is older than the earliest available version, or a file-not-found error for a data file. Both mean the same thing: the data is no longer there.
Check before you rely on history
Use a dry run to see what VACUUM would delete before you run it for real:
VACUUM main.sales.orders RETAIN 168 HOURS DRY RUN;The output lists files that are about to become unreachable. If a version you care about depends on them, extend retention first.
You can also look at the oldest version that DESCRIBE HISTORY reports, then test that you can still read it:
history = spark.sql("DESCRIBE HISTORY main.sales.orders")
oldest = history.agg({"version": "min"}).collect()[0][0]
# This read can still fail if VACUUM already removed the files.
spark.read.option("versionAsOf", oldest).table("main.sales.orders").limit(1).count()A successful DESCRIBE HISTORY row is not proof the data is readable. Only a read proves it.
Why time travel is not a backup
A backup protects you from losing the system that holds the data. Time travel lives inside that system, so it fails in the same situations the table does.
| Risk | Does time travel help? |
|---|---|
| Bad `UPDATE` or `DELETE` last week | Yes, if within retention and not vacuumed |
| Bad change found after 40 days | Usually no |
| Table dropped (managed) | No, apart from `UNDROP` within its window |
| Corrupted or deleted files in cloud storage | No |
| Wrong region or account is lost | No |
| Regulatory requirement for long-term copies | No |
History and data share the same storage location. Someone with write access can delete both. Retention windows are short by design, and long retention raises storage cost because old files stay on disk.
For real recovery, add a separate layer:
- Use
DEEP CLONEto copy a table to a different location or account on a schedule. - Enable versioning and cross-region replication on the cloud storage bucket.
- Keep Unity Catalog permissions tight so few people can run
VACUUMor drop tables.
Use time travel for short-term mistakes and audits. Use clones and storage-level protection for disaster recovery.
Exercise
A table has default retention settings. On day 10 you run VACUUM with the default retention. On day 12 you try VERSION AS OF on a version committed on day 1, and DESCRIBE HISTORY still lists it. Why might the read fail, and what is the earliest point at which the listing itself disappears?
Show answer
The data files that version needed were removed from the table more than 7 days earlier, so VACUUM on day 10 could delete them, and the read fails with a missing-file or version-too-old error. The history entry stays because log retention is 30 days. It can disappear after about 30 days, once log cleanup runs.
Exercise
Name two things you would set up so that losing a table's storage does not also lose your only recovery copy.
Show answer
Any two of: a scheduled DEEP CLONE to a separate location or account, cloud storage versioning, and cross-region replication of the storage bucket.