0% found this document useful (0 votes)
127 views21 pages

Restoring SQL Server Databases

This document provides an overview of restoring SQL Server databases. It discusses the restore process, types of restores, and advanced restore scenarios like point-in-time recovery. The key phases of restore are copying data files, applying redo operations, and undoing uncommitted transactions. Differential and log restores are demonstrated. File/filegroup and encrypted backups can also be restored. System databases have special restore requirements. Point-in-time recovery uses the STOPAT option to recovery up to a specific date or marked transaction. Hands-on labs provide restore experience.

Uploaded by

Phil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views21 pages

Restoring SQL Server Databases

This document provides an overview of restoring SQL Server databases. It discusses the restore process, types of restores, and advanced restore scenarios like point-in-time recovery. The key phases of restore are copying data files, applying redo operations, and undoing uncommitted transactions. Differential and log restores are demonstrated. File/filegroup and encrypted backups can also be restored. System databases have special restore requirements. Point-in-time recovery uses the STOPAT option to recovery up to a specific date or marked transaction. Hands-on labs provide restore experience.

Uploaded by

Phil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Module 7

Restoring SQL Server Databases


Module Overview

• Understanding the Restore Process


• Restoring Databases
• Advanced Restore Scenarios
• Point-in-time Recovery
Lesson 1: Understanding the Restore Process

• Phases of the Restore Process


• Types of Restores
• Preparations for Restoring Backups
• Discussion: Determining the Required Backups to
Restore
Phases of the Restore Process

• The restore process of a SQL Server database


consists of three phases:
Phase Description
Data copy Creates files and copies data to the files
Redo Applies committed transactions from
restored log entries
Undo Rolls back transactions that were
uncommitted at the recovery point

• Redo and undo are also known as recovery


Types of Restores

• Complete database restores:


• Simple recovery model
• Full recovery model

• System database restore

• Advanced restores:
• File or filegroup restore
• Piecemeal restore
• Encrypted backup restore
• Page restore
Preparations for Restoring Backups

• Perform a tail-log backup if using full or bulk-


logged recovery model

• Identify the backups to restore:


• Last full, file, or filegroup backup
• Last differential backup, if it exists
• Log backups, if using full or bulk-logged
recovery model
Lesson 2: Restoring Databases

• Restoring a Full Database Backup


• Restoring a Differential Backup
• Restoring Transaction Log Backups
• Demonstration: Restoring Databases
Restoring a Full Database Backup

• Use SQL Server Management Studio


• Use the RESTORE DATABASE statement:
• Use WITH REPLACE to overwrite an existing database
• Use WITH MOVE to relocate the database files

RESTORE DATABASE AdventureWorks


FROM DISK = 'D:\Backups\AW.bak';
Restoring a Differential Backup

1. Restore the latest full database backup WITH


NORECOVERY
RESTORE DATABASE AdventureWorks
I’m not done
FROM DISK = 'D:\Backups\AW.bak' restoring yet!
WITH FILE = 1, NORECOVERY;

2. Restore the latest differential backup WITH


RECOVERY
RESTORE DATABASE AdventureWorks
Okay, I’m
FROM DISK = 'D:\Backups\AW.bak' done restoring.
WITH FILE = 3, RECOVERY;
Restoring Transaction Log Backups

• Restore transaction logs by using the RESTORE


LOG statement
• Restore the log chain chronologically:
• Use NORECOVERY for all but the last backup
• Use RECOVERY for the last backup (often the tail-log
backup)
-- Restore last full and differential database backups . . .
-- Restore planned log backups
RESTORE LOG AdventureWorks FROM DISK =
'D:\Backups\AW.bak' WITH FILE = 5, NORECOVERY;

-- Restore tail-log backup


RESTORE LOG AdventureWorks FROM DISK = 'D:\Backups\AW-
TailLog.bak' WITH RECOVERY;
Demonstration: Restoring Databases

In this demonstration, you will see how to:


• Create a tail-log backup
• Restore a database
Lesson 3: Advanced Restore Scenarios

• Restoring File or Filegroup Backups


• Restoring an Encrypted Backup
• Demonstration: Restoring an Encrypted Backup
• Restoring Data Pages
• Recovering System Databases
Restoring File or Filegroup Backups

Restoring an individual file or filegroup:


1. Create a tail-log backup (if possible)
2. Restore each damaged file or filegroup
3. Restore any differential file backups
4. Restore transaction log backups in sequence
5. Recover the database
Performing a piecemeal restore:
1. Restore read/write filegroups with PARTIAL
2. Restore any differential or log backups and
recover the database
3. Restore read-only filegroups
Restoring an Encrypted Backup

• If the encryption key exists on the server


instance:
• Restore the database as normal

• Otherwise:
1. Create or restore a database master key for the
master database
2. Create the encryption certificate or key from a
backup
3. Restore the database
Recovering System Databases

System database Description


master Backup required: yes
Recovery model: simple
Restore using single user mode
model Backup required: yes
Recovery model: user configurable
Restore using –T3608 trace flag
msdb Backup required: yes
Recovery model: simple (default)
Restore like any user database
tempdb/resource No backups can be performed
tempdb is created during instance startup
Restore resource using file restore or setup

Prevents SQL Server from automatically starting


and recovering any database except the master database.
Lesson 4: Point-in-time Recovery

• Overview of Point-in-time Recovery


• STOPAT Option
• STOPATMARK Option
• Performing a Point-in-time Recovery by Using SQL
Server Management Studio
• Demonstration: Performing a Point-in-time
Recovery
Overview of Point-in-time Recovery

• Enables recovery of a database up to any


arbitrary point in time that is contained in the
transaction log backups

• Point in time can be defined by:


•A datetime value
• A named transaction

• Database must be in FULL recovery model


STOPAT Option

• Provide the STOPAT and WITH RECOVERY options as part


of all RESTORE statements in the sequence:
• No need to know in which transaction log backup the
requested point in time resides
• If the point in time is after the time included in the
backup, a warning will be issued and the database will
not be recovered after the restore completes
• If the point in time is before the time included in the
backup, the RESTORE statement fails
• If the point in time provided is within the time frame of
the backup, the database is recovered up to that point
STOPATMARK Option

• Transactions marked using:


• BEGIN TRAN <name> WITH MARK <description>

• Restore has two related options:


• STOPATMARK rolls forward to the mark and includes
the marked transaction in the roll forward
• STOPBEFOREMARK rolls forward to the mark and
excludes the marked transaction from the roll forward

• If the mark is not present in the transaction log backup,


the backup is restored, but the database is not recovered
Performing a Point-in-time Recovery by Using
SQL Server Management Studio
Lab: Restoring SQL Server Databases

• Exercise 1: Restoring a Database Backup


• Exercise 2: Restoring Database, Differential, and
Transaction Log Backups
• Exercise 3: Performing a Piecemeal Restore

Logon Information
Virtual machine: 20764C-MIA-SQL
User name: ADVENTUREWORKS\Student
Password: Pa55w.rd

Estimated Time: 60 minutes

You might also like