Big deployment tonight and restoring an 200GB backup if it goes wrong would blow the maintenance window. Snapshots keep coming up as the answer.
How do database snapshots actually work, what is the syntax and what are the catches?
Big deployment tonight and restoring an 200GB backup if it goes wrong would blow the maintenance window. Snapshots keep coming up as the answer.
How do database snapshots actually work, what is the syntax and what are the catches?
Snapshots are exactly the tool for the deployment guard job, and understanding the mechanism explains both the speed and the catches.
A snapshot is a read only view of the database frozen at creation, held in sparse files that start empty: when a page changes in the source after creation, the original page is copied into the snapshot first. Creation is therefore instant regardless of the 200GB, and the snapshot grows only with the changes made after it. A deployment touching a few GB of pages costs a few GB of snapshot, nothing like a second copy.
The syntax names every data file: CREATE DATABASE AppDB_Snap ON (NAME = AppDB_Data, FILENAME = 'D:\Snaps\AppDB_Data.ss') AS SNAPSHOT OF AppDB, one file clause per data file in the source, query sys.master_files for the logical names first. The revert, your bad deployment button: RESTORE DATABASE AppDB FROM DATABASE_SNAPSHOT = 'AppDB_Snap', which rewinds the source to the frozen moment in roughly the time proportional to the changed pages, minutes against your backup restore hours.
The catches to respect: reverting requires dropping every other snapshot of that database first and breaks the log backup chain, so take a full or differential backup after any revert. Everything since creation vanishes in a revert including data users entered mid deployment, which is why the pattern is snapshot, deploy, verify, drop snapshot on success. Editions: all editions since 2016 SP1, Enterprise only before that, worth checking your version tonight rather than at midnight. And a snapshot is not a backup, it lives on the same storage as the source and dies with it, tonight's real backup still runs first.
Snapshot created in under a second before the deployment, which went fine so it was dropped after verification. The everything since creation warning shaped the runbook, we blocked user access until the verify passed. Textbook night thanks to this.