SQL Server Backup and Recovery
SQL Server Backup and Recovery
Restoring Databases
Overview
Restoring Databases
Overview
Restoring Databases
Overview
Restoring Databases
Overview
• Dispelling myths
– You do not need to take a database offline to back
it up
– Backups will include open transactions
– All backups include the transaction log
– You cannot just backup a table by default
• “All or nothing”
• One exception: if that table is on a separate filegroup
What We’re Going to Cover
Restoring Databases
Overview
Restoring Databases
Overview
Restoring Databases
Overview
• Let me recap:
– Bulk Logged and Full recovery models are identical
provided no bulk operations have occurred since
the last backup
– Bulk Logged recovery model may prevent you
from backing up your log
Bulk Logged Recovery Model
Restoring Databases
Overview
Restoring Databases
Overview
Restoring Databases
Overview
Restoring Databases
Overview
• Basics of restores:
– The final backup you restore will, by default, take
the database through the RECOVERY process and
bring the database ONLINE
• You decide which is the final backup file in your
Transact-SQL code
– Any open transactions in the database will be
rolled back during the RECOVERY process
The Basics of Restoring
Databases
• Example restore:
– FULL backup: from Monday: 0800
– LOG backups: Monday: 0900, 1000, 1100
– DIFF backup: Monday 1200
– LOG backups: Monday: 1300, 1400, 1500
The Basics of Restoring
Databases
73
In this video…
Restoring Databases
Overview
• Factors to consider:
1. Size of database
2. Time it takes for each backup type to complete
3. How much “drag” backups place on the system
4. How much disk space our backups consume
5. Where to put the backups?
6. How much “loss” is acceptable
7. How much downtime is acceptable
Factors to consider
1. Size of database
– Large databases are problematic:
• Backup time can be hours and hours
– Therefore the restore time can be hours and hours
• Backup file sizes are huge
– In SQL Server 2008 Enterprise Edition, backup files can be
compressed (more on this later)
• Since the backups are so massive, they have an impact
on system performance
– Smaller and mid-size databases do not have as
much to worry about
Factors to consider
90
In this video…
Restoring Databases
Overview
Backup Strategy:
• Full backups on Saturdays at 2300
Database: LIFUtility
Recovery model: SIMPLE
Backup Strategy:
• Full backups on Saturdays at 2300
Database: LIFUtility
Recovery model: SIMPLE
Backup Strategy:
• Full backups on Saturdays at 2300
Database: LIFUtility
Recovery model: SIMPLE
Backup Strategy:
• Full backups on Saturdays at 2300
Database: LIFUtility
Recovery model: SIMPLE
Backup Strategy:
• Full backups on Saturdays at 2300
• Differential backup Wednesday at
2300
Database: LIFUtility
Recovery model: SIMPLE
Backup Strategy:
• Full backups on Saturdays at 2300
• Differential backup Wednesday at
2300
Database: LIFUtility
Recovery model: SIMPLE
103
In this video…
Restoring Databases
Overview
Backup Strategy:
• Full backups on Saturdays at 2300
• Differential backups each day at
2300
Database: LIFUtility
Recovery model: FULL
Backup Strategy:
• Full backups on Saturdays at 2300
• Differential backups each day at
2300
Database: LIFUtility
Recovery model: FULL
• Question #1:
– What would happen if we accidently
forgot to take the log backup in Step
1?
• We would lose all changes since the DIFF
Backup Strategy
• Question #2:
– What would happen if the disk(s)
holding the data file crashed during
the backup of the log?
• Remember that we can still backup the
log because changes are written to the
log first, and then to the data file
– This is a primary function of the transaction
log
Backup Strategy
• Question #3:
– What would happen if the disk(s)
holding the transaction log crashed
during the backup of the log?
• We would lose all changes since the DIFF
Be Careful!
118
In this video…
Restoring Databases
Overview
Backup Strategy:
• Full backups on Saturdays at 2300
• Differentials each day at 2300
• Log backups each hour
Database: LIFWeb
Recovery model: FULL
Backup Strategy:
• Full backups on Saturdays at 2300
• Differentials each day at 2300
• Log backups each hour
Database: LIFWeb
Recovery model: FULL
Backup Strategy:
• Full backups on Saturdays at 2300
• Differentials each day at 2300
• Log backups each hour
Database: LIFWeb
Recovery model: FULL
131
In this video…
Restoring Databases
Overview
Backup Strategy:
• Full backups on Saturdays at 2300
• Differentials each day at 2300
Database: LIFReporting
Recovery model: BULK LOGGED
Backup Strategy:
• Full backups on Saturdays at 2300
• Differentials each day at 2300
Database: LIFReporting
Recovery model: BULK LOGGED
Backup Strategy:
• Full backups on Saturdays at 2300
• Differentials each day at 2300
Database: LIFReporting
Recovery model: BULK LOGGED
Backup Strategy:
• Full backups on Saturdays at 2300
• Differentials each day at 2300
Database: LIFReporting
Recovery model: BULK LOGGED
Backup Strategy:
• Full backups on Saturdays at 2300
• Differentials each day at 2300
Database: LIFReporting
Recovery model: BULK LOGGED
Backup Strategy:
• Full backups on Saturdays at 2300
• Differentials each day at 2300
Database: LIFReporting
Recovery model: BULK LOGGED
Backup Strategy:
• Full backups on Saturdays at 2300
• Differentials each day at 2300
Database: LIFReporting
Recovery model: BULK LOGGED
Backup Strategy:
• Full backups on Saturdays at 2300
• Differentials each day at 2300
Database: LIFReporting
Recovery model: BULK LOGGED
Backup Strategy:
• Full backups on Saturdays at 2300
• Differentials each day at 2300
Database: LIFReporting
Recovery model: BULK LOGGED
Backup Strategy:
• Full backups on Saturdays at 2300
• Differentials each day at 2300
• Hourly log backups
Database: LIFReporting
Recovery model: BULK LOGGED
Backup Strategy:
• Full backups on Saturdays at 2300
• Differentials each day at 2300
• Hourly log backups
Database: LIFReporting
Recovery model: BULK LOGGED
147
In this video…
Restoring Databases
Overview
165
In this video…
Restoring Databases
Overview
• Visualization:
In the next video…
175
In this video…
Restoring Databases
Overview
185
In this video…
Restoring Databases
Overview
198
In this video…
Restoring Databases
Overview
• Basics of restores:
– The final backup you restore will, by default, take
the database through the RECOVERY process and
bring the database ONLINE
• You decide which is the final backup file in your
Transact-SQL code
– Any open transactions in the database will be
rolled back during the RECOVERY process
If you are lucky…
209
In this video…
Restoring Databases
Overview
220
In this video…
Restoring Databases
Overview
• Scenario:
– “Mike” calls you and explains that, sometime
around 11:30AM, a “bad” transaction was issued
by a developer
• Mission critical - must undo this transaction or restore
to point prior to the transaction
• Gotta do it now!
Point-in-time Restores are tricky
227
In this video…
Restoring Databases
Overview
• The Scenario:
– The disk system that held all of your data files
(.mdf) has just crashed and cannot be recovered
– The sysadmins have just completed installing new
drives and building the array
– Now it’s your turn to get that SQL Server back up
and running
Restoring Your Entire Server
setup.exe
/QUIET
/ACTION=REBUILDDATABASE
/INSTANCENAME=instance_name
/SQLSYSADMINACCOUNTS= accounts
[/SAPWD=password]
[/SQLCOLLATION=collation_name]
Restoring Your Entire Server
239
In this video…
Restoring Databases
Overview
• The Scenario:
– The disk system that held all of your data files
(.mdf) has just crashed and cannot be recovered
– The sysadmins have just completed installing new
drives and building the array
– Now it’s your turn to get that SQL Server back up
and running
Restoring Your Entire Server
• Reminders:
– No one can be in your database when you restore
– You are overwriting a database during the restore
• Conceptually think of it in three phases:
1. Delete original database files
2. Create new versions of database files
3. Restore the backup data into the new files
Restoring Your Entire Server
• A word of caution:
– Remember that, if you configure SSMS to open
both Object Explorer and a query window, that is
two connections
Restoring Your Entire Server