Backup and Restore your SQL Server Database The most important part of the job!
Corruption User error Malicious activity Disaster recovery Why do we back up? Corruption User error Malicious activity Disaster recovery
How do we recover a database that is borked? Restore from the last known good backup. - Microsoft
How do we know if the last known backup is good? Test. Your. Backups. - Basically every data professional
The business makes the rules Recovery Point Objective (RPO) Recovery Time Objective (RTO) Service Level Agreement (SLA)
Recovery point objective (RPO) How much data are we prepared to lose?
Recovery time objective (RPO) How much time do we have to recover?
Defining a restore strategy, redux How much data can we lose? (RPO) How long will recovery take? (RTO) Can we actually do this? (SLA)
How do we back up our databases? Copy database files File snapshots Database snapshots Built-in BACKUP command SQL native backup
What is the one true backup method? SQL Server native backup (the built-in BACKUP command)
Corollary to the one true backup method A SQL Server native backup is only as good as its restore (the built-in RESTORE command)
What does a SQL Server data file look like? Lots of 8KB data pages All objects are stored in pages Each page has a header 8 contiguous pages = extent
What does a SQL Server transaction log look like? Virtual log files Log Sequence Numbers Active / inactive Circular Recovery model etutorials.org
So what is a recovery model then? Full recovery model Bulk-logged recovery model Simple recovery model
All transactions are fully logged The log file grows until cleared Full recovery model All transactions are fully logged The log file grows until cleared Transaction log backups needed Allows point-in-time recovery
Bulk-logged recovery model Bulk operations minimally logged The log file grows until cleared Transaction log backups needed Some point-in-time recovery
Log file cleared after every commit No transaction logging at all Simple recovery model Log file cleared after every commit No transaction logging at all No point-in-time recovery possible
What types of backups can I take? Full backup Differential backup Transaction log backup File / filegroup backup* Partial backup*
Full backup (BACKUP DATABASE) Copy of entire data file Active portion of the log Full, bulk-logged, simple
Full backup (BACKUP DATABASE WITH COPY_ONLY) Copy of entire data file Active portion of the log Does not affect differentials Full, bulk-logged, simple
Extents changed since last full Active portion of the log Differential backup Extents changed since last full Active portion of the log Each differential is bigger Not affected by COPY_ONLY Full, bulk-logged, simple
Transaction log backup Active portion of the log Full and bulk-logged only
Log backups are incremental Differential backups are not Backup chain Log backups are incremental Differential backups are not
Restore a full backup (can include a COPY_ONLY backup)
Restore to a point in time (basic method) Restore a full backup (may include a COPY_ONLY backup) Restore all transaction logs Use WITH NORECOVERY option
Restore to a point in time with differential backups Restore a full backup* Restore latest differential backup Restore all transaction logs Use WITH NORECOVERY option
Automation is the new black Automate your backups ola.hallengren.com / dbatools.io / minionware.net / ** SQL Agent ** Notify on failure, not success Automate your restore script Steve Stedman (bit.ly/automateScript)
Copy backups securely off-premises Test restores frequently Best practices Back up with CHECKSUM Copy backups securely off-premises Test restores frequently DBCC CHECKDB is your friend Automate all the things
SQL Server Maintenance Wizard Do use: Tips and tricks Don’t use: SQL Server Maintenance Wizard Do use: Ola Hallengren’s Maintenance Solution MinionWare Backup
Show Me The Money imgflip.com