backup and recovery in sql server. back-up and restore planning goals and objectives implementation...

32
Backup and Recovery in Backup and Recovery in SQL Server SQL Server

Upload: bethany-holt

Post on 22-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Backup and Recovery in Backup and Recovery in SQL ServerSQL Server

Back-up and Restore

Back-up and Restore

Planning Planning ImplementationImplementation ExecutionExecution

Goals and ObjectivesGoals and Objectives

Training and Testing

Training and Testing

BACKING UP AND RESTORING

BACKING UP AND RESTORING

High Level ViewHigh Level View

PlanningPlanning

Needs assessmentNeeds assessment Management expectationsManagement expectations Network architectureNetwork architecture PersonnelPersonnel

ImplementationImplementation

TrainingTraining Who’s involved in the process?Who’s involved in the process?

TestingTesting Failsafe your processFailsafe your process Remember what the purpose of backups are!Remember what the purpose of backups are!

The Role of Back-upsThe Role of Back-ups

Data RecoveryData Recovery Data MigrationData Migration

Backing up your dataBacking up your data

Backup Basics Backup Basics

Data FilesData Files .MDF.MDF .LDF.LDF

Backup DevicesBackup Devices CreateCreate DeleteDelete

Recovery ModelsRecovery Models

SimpleSimple Most restrictive model.Most restrictive model. Can’t complete transaction log backups.Can’t complete transaction log backups. Good if you only want to recover to your last full backup.Good if you only want to recover to your last full backup.

Bulked LogBulked Log Ability to recover to the end of a full backup or the end of Ability to recover to the end of a full backup or the end of

a transaction log.a transaction log. Lose the ability to restore to a specific point in time.Lose the ability to restore to a specific point in time.

FullFull Allows full, differential, transaction log and filegroup Allows full, differential, transaction log and filegroup

recoveries.recoveries. Provides the highest level of data protection.Provides the highest level of data protection. Point in time restores.Point in time restores.

Types of BackupsTypes of Backups

Full DatabaseFull Database Differential DatabaseDifferential Database Transaction LogTransaction Log FilegroupFilegroup

FullFull

Completes a full backup up the database right up to the Completes a full backup up the database right up to the point where the database finishes.point where the database finishes.

Backs up all tables, indexes, system tables and the Backs up all tables, indexes, system tables and the database object in those tablesdatabase object in those tables

Striping exampleStriping example

The Backup Database The Backup Database StatementStatement

BACKUP DATABASE { BACKUP DATABASE { database_namedatabase_name | | @@database_name_var database_name_var } } TO < backup_device > [ TO < backup_device > [ ,,......nn ] ] [ WITH [ WITH     [ BLOCKSIZE     [ BLOCKSIZE = = { { blocksizeblocksize | | @@blocksize_variable blocksize_variable } ] } ]     [ [     [ [ , , ] DESCRIPTION ] DESCRIPTION = = { { ''texttext'' | | @@text_variable text_variable } ] } ]     [ [     [ [ , , ] DIFFERENTIAL ] ] DIFFERENTIAL ]     [ [     [ [ , , ] EXPIREDATE ] EXPIREDATE == { { date date | | @@date_var date_var } }         | RETAINDAYS         | RETAINDAYS == { { daysdays | | @@days_var days_var } ] } ]     [ [     [ [ , , ] PASSWORD ] PASSWORD = = { { password password | | @@password_variable password_variable } ] } ]     [ [     [ [ , , ] FORMAT | NOFORMAT ] ] FORMAT | NOFORMAT ]     [ [     [ [ , , ] { INIT | NOINIT } ] ] { INIT | NOINIT } ]     [ [     [ [ , , ] MEDIADESCRIPTION ] MEDIADESCRIPTION = = { { ''texttext'' | | @@text_variable text_variable } ] } ]     [ [     [ [ , , ] MEDIANAME ] MEDIANAME = = { { media_name media_name | | @@media_name_variable media_name_variable } ] } ]     [ [     [ [ , , ] MEDIAPASSWORD ] MEDIAPASSWORD = = { { mediapassword mediapassword | | @@mediapassword_variable mediapassword_variable } ] } ]     [ [     [ [ , , ] NAME ] NAME == { { backup_set_namebackup_set_name | | @@backup_set_name_var backup_set_name_var } ] } ]     [ [     [ [ , , ] { NOSKIP | SKIP } ] ] { NOSKIP | SKIP } ]     [ [     [ [ , , ] { NOREWIND | REWIND } ] ] { NOREWIND | REWIND } ]     [ [     [ [ , , ] { NOUNLOAD | UNLOAD } ] ] { NOUNLOAD | UNLOAD } ]     [ [     [ [ , , ] RESTART ] ] RESTART ]     [ [     [ [ , , ] STATS [ ] STATS [ == percentage percentage ] ] ] ]

Differential BackupDifferential Backup

Creates a backup of the changes made to the database Creates a backup of the changes made to the database since the last full backupsince the last full backup

Does not keep track of individual transactions so it does Does not keep track of individual transactions so it does not provide the ability to restore to a point in timenot provide the ability to restore to a point in time

The Transaction LogThe Transaction Log The transaction log keeps a log of each transaction The transaction log keeps a log of each transaction

giving a DBA the ability roll forward or roll back to a giving a DBA the ability roll forward or roll back to a specific point.specific point.

When the transaction log is backed up the log is When the transaction log is backed up the log is truncated.truncated.

Transaction log backups are scheduled in intervals Transaction log backups are scheduled in intervals typically 5 to 30 minutes.typically 5 to 30 minutes.

Backs up the transactions since the last Full Backup, Backs up the transactions since the last Full Backup, Differential Backup or Transaction Log Backup.Differential Backup or Transaction Log Backup.

Backup Log StatementBackup Log StatementBACKUP LOG { BACKUP LOG { database_namedatabase_name | | @@database_name_var database_name_var } }

{ {     TO < backup_device > [     TO < backup_device > [ ,,......n n ] ]     [ WITH     [ WITH         [ BLOCKSIZE         [ BLOCKSIZE = = { { blocksizeblocksize | | @@blocksize_variable blocksize_variable } ] } ]         [ [         [ [ , , ] DESCRIPTION ] DESCRIPTION = = { { ''texttext'' | | @@text_variable text_variable } ] } ]         [ [         [ [ ,,] EXPIREDATE ] EXPIREDATE == { { date date | | @@date_var date_var } }             | RETAINDAYS             | RETAINDAYS == { { daysdays | | @@days_var days_var } ] } ]         [ [         [ [ , , ] PASSWORD ] PASSWORD = = { { password password | | @@password_variable password_variable } ] } ]         [ [         [ [ , , ] FORMAT | NOFORMAT ] ] FORMAT | NOFORMAT ]         [ [         [ [ , , ] { INIT | NOINIT } ] ] { INIT | NOINIT } ]         [ [         [ [ , , ] MEDIADESCRIPTION ] MEDIADESCRIPTION = = { { ''texttext'' | | @@text_variable text_variable } ] } ]         [ [         [ [ , , ] MEDIANAME ] MEDIANAME = = { { media_name media_name | | @@media_name_variable media_name_variable } ] } ]         [ [         [ [ , , ] MEDIAPASSWORD ] MEDIAPASSWORD = = { { mediapassword mediapassword | | @@mediapassword_variable mediapassword_variable } ] } ]         [ [         [ [ , , ] NAME ] NAME == { { backup_set_namebackup_set_name | | @@backup_set_name_var backup_set_name_var } ] } ]         [ [         [ [ , , ] NO_TRUNCATE ] ] NO_TRUNCATE ]         [ [         [ [ ,, ] { NORECOVERY | STANDBY ] { NORECOVERY | STANDBY = = undo_file_name undo_file_name } ] } ]         [ [         [ [ , , ] { NOREWIND | REWIND } ]] { NOREWIND | REWIND } ]        [ [         [ [ , , ] { NOSKIP | SKIP } ] ] { NOSKIP | SKIP } ]         [ [         [ [ , , ] { NOUNLOAD | UNLOAD } ] ] { NOUNLOAD | UNLOAD } ]         [ [         [ [ , , ] RESTART ] ] RESTART ]         [ [         [ [ , , ] STATS [ ] STATS [ == percentage percentage ] ] ] ]     ]     ]

FilegroupsFilegroups

Allow a user to place tables, indexes and other database Allow a user to place tables, indexes and other database objects into specific database files.objects into specific database files.

Can be backed up and restored individually or in groups.Can be backed up and restored individually or in groups. Useful when time restraints prevent full backups.Useful when time restraints prevent full backups.

Verifying the BackupVerifying the Backup

Does not check the consistency of the database (i.e. Does not check the consistency of the database (i.e. DBCC CHECKDATABASE).DBCC CHECKDATABASE).

Verifies the integrity of the database backup and checks Verifies the integrity of the database backup and checks for corruption.for corruption.

Makes sure all the data in the backup set is readable.Makes sure all the data in the backup set is readable.

Restore Verify OnlyRestore Verify OnlyRESTORE VERIFYONLY RESTORE VERIFYONLY

FROM < backup_device > [ FROM < backup_device > [ ,,......n n ] ] [ WITH [ WITH     [ FILE     [ FILE == file_number file_number ] ]     [ [     [ [ , , ] { NOUNLOAD | UNLOAD } ] ] { NOUNLOAD | UNLOAD } ]     [ [     [ [ , , ] LOADHISTORY ] ] LOADHISTORY ]     [ [     [ [ ,, ] PASSWORD ] PASSWORD == { { passwordpassword | | @@password_variablepassword_variable } ] } ]     [ [     [ [ ,, ] MEDIAPASSWORD ] MEDIAPASSWORD == { { mediapasswordmediapassword | | @@mediapassword_variable mediapassword_variable } ] } ]     [ [     [ [ , , ] { NOREWIND | REWIND } ] ] { NOREWIND | REWIND } ]

Job SchedulingJob Scheduling

The most widely used way complete day to day and The most widely used way complete day to day and week to week scheduled backup operations.week to week scheduled backup operations.

Creation of jobs though Enterprise Manager.Creation of jobs though Enterprise Manager. SQL Server Agent must be started.SQL Server Agent must be started.

Database Maintenance PlansDatabase Maintenance Plans

Expanded job scheduling abilities.Expanded job scheduling abilities. Creates jobs managed by the SQL Server Agent.Creates jobs managed by the SQL Server Agent. Can schedule integrity checks, reorganize indexes and Can schedule integrity checks, reorganize indexes and

delete unwanted database backups. delete unwanted database backups.

StorageStorage

Using a consistent method of keeping track of your Using a consistent method of keeping track of your backups.backups.

Using the system backup tables in the msdb database.Using the system backup tables in the msdb database. Archiving backups to tape and different considerations Archiving backups to tape and different considerations

for different industriesfor different industries

Recovering your dataRecovering your data

Restore scenariosRestore scenarios

Data MigrationData Migration DevelopmentDevelopment TestingTesting

Disaster RecoveryDisaster Recovery Recovering BackupsRecovering Backups Standby ServersStandby Servers

Restore BasicsRestore Basics Make sure you are using the correct backup set.Make sure you are using the correct backup set. RESTORE LABELONLY: summarizes information about RESTORE LABELONLY: summarizes information about

the backup set.the backup set. RESTORE HEADERONLY: returns information about RESTORE HEADERONLY: returns information about

each item in the backup set including the order in which each item in the backup set including the order in which the backups were made.the backups were made.

RESTORE FILELISTONLY: returns the associated data RESTORE FILELISTONLY: returns the associated data files in relation to a specific backup device.files in relation to a specific backup device.

Restoring a Full Backup and a Restoring a Full Backup and a Differential BackupDifferential Backup

Restore a full backup.Restore a full backup. Restoring a differential.Restoring a differential. The WITH RECOVERY/NORECOVERY clause.The WITH RECOVERY/NORECOVERY clause. Files must be restored in order.Files must be restored in order.

The Restore StatementThe Restore StatementRESTORE DATABASE { RESTORE DATABASE { database_namedatabase_name | | @@database_name_var database_name_var } }

[ FROM < backup_device > [ [ FROM < backup_device > [ ,,......n n ] ] ] ] [ WITH [ WITH     [ RESTRICTED_USER ]     [ RESTRICTED_USER ]     [ [     [ [ , , ] FILE ] FILE == { { file_numberfile_number | | @@file_number file_number } ] } ]     [ [     [ [ , , ] PASSWORD] PASSWORD = = { { password password | | @@password_variable password_variable } ] } ]     [ [     [ [ , , ] MEDIANAME] MEDIANAME = = { { media_name media_name | | @@media_name_variable media_name_variable } ] } ]     [ [     [ [ , , ] MEDIAPASSWORD] MEDIAPASSWORD = = { { mediapassword mediapassword | | @@mediapassword_variable mediapassword_variable } ] } ]     [ [     [ [ , , ] MOVE ] MOVE ''logical_file_namelogical_file_name'' TO TO ''operating_system_file_nameoperating_system_file_name' ' ] ]             [             [ ,,......n n ] ]     [ [     [ [ , , ] KEEP_REPLICATION ] ] KEEP_REPLICATION ]     [ [     [ [ , , ] { NORECOVERY | RECOVERY | STANDBY ] { NORECOVERY | RECOVERY | STANDBY = = undo_file_name undo_file_name } ] } ]     [ [     [ [ , , ] { NOREWIND | REWIND } ] ] { NOREWIND | REWIND } ]     [ [     [ [ , , ] { NOUNLOAD | UNLOAD } ] ] { NOUNLOAD | UNLOAD } ]     [ [     [ [ , , ] REPLACE ] ] REPLACE ]     [ [     [ [ , , ] RESTART ] ] RESTART ]     [ [     [ [ , , ] STATS [ ] STATS [ == percentage percentage ] ]

Restoring a Full Backup and Restoring a Full Backup and TlogsTlogs

Must restore files in orderMust restore files in order Provides the ability to restore to a point in timeProvides the ability to restore to a point in time Provides the ability to restore to a marked transactionProvides the ability to restore to a marked transaction

Restore Log StatementRestore Log StatementRESTORE LOG { RESTORE LOG { database_namedatabase_name | | @@database_name_var database_name_var } }

[ FROM < backup_device > [ [ FROM < backup_device > [ ,,......n n ] ] ] ] [ WITH [ WITH     [ RESTRICTED_USER ]     [ RESTRICTED_USER ]     [ [     [ [ , , ] FILE ] FILE == { { file_numberfile_number | | @@file_number file_number } ] } ]     [ [     [ [ , , ] PASSWORD] PASSWORD = = { { password password | | @@password_variable password_variable } ] } ]     [ [     [ [ , , ] MOVE ] MOVE ''logical_file_namelogical_file_name'' TO TO ''operating_system_file_nameoperating_system_file_name' ' ] ]             [             [ ,,......n n ] ]     [ [     [ [ , , ] MEDIANAME] MEDIANAME = = { { media_name media_name | | @@media_name_variable media_name_variable } ] } ]     [ [     [ [ , , ] MEDIAPASSWORD] MEDIAPASSWORD = = { { mediapassword mediapassword | | @@mediapassword_variable mediapassword_variable } ] } ]     [ [     [ [ , , ] KEEP_REPLICATION ] ] KEEP_REPLICATION ]     [ [     [ [ ,, ] { NORECOVERY | RECOVERY | STANDBY ] { NORECOVERY | RECOVERY | STANDBY = = undo_file_name undo_file_name } ] } ]     [ [     [ [ , , ] { NOREWIND | REWIND } ] ] { NOREWIND | REWIND } ]     [ [     [ [ ,, ] { NOUNLOAD | UNLOAD } ] ] { NOUNLOAD | UNLOAD } ]     [ [     [ [ ,, ] RESTART ] ] RESTART ]     [ [     [ [ ,, ] STATS [ ] STATS [== percentage percentage ] ] ] ]     [ [     [ [ ,, ] STOPAT ] STOPAT == { { date_time date_time | | @@date_time_var date_time_var } }         | [         | [ ,, ] STOPATMARK ] STOPATMARK == ''mark_namemark_name'' [ AFTER [ AFTER datetime datetime ] ]         | [         | [ ,, ] STOPBEFOREMARK ] STOPBEFOREMARK == ''mark_namemark_name'' [ AFTER [ AFTER datetime datetime ] ]

Point in Time RestorePoint in Time Restore

Allows user to restore to a point before a failure or Allows user to restore to a point before a failure or corrupt datacorrupt data

Allows user to restore without unwanted dataAllows user to restore without unwanted data

Restore to MarkRestore to Mark

STOPATMARK: Transactions can be ‘marked’ so that a STOPATMARK: Transactions can be ‘marked’ so that a restore can take you up to that marked transaction.restore can take you up to that marked transaction.

STOPBEFOREMARK: Restores can also restore up to STOPBEFOREMARK: Restores can also restore up to but not including that mark.but not including that mark.

Using a Backup to Create a Using a Backup to Create a New DatabaseNew Database

A new database can be created by using the backup A new database can be created by using the backup from an existing database.from an existing database.

This is made possible by using the ‘with move’ statement This is made possible by using the ‘with move’ statement which copies the data files and applies them to the new which copies the data files and applies them to the new database.database.

Consistency in Backing Up the Consistency in Backing Up the System DatabasesSystem Databases

It is important to consistently backup up the master It is important to consistently backup up the master database and the msdb databases.database and the msdb databases.

In a restore scenario the master database should be In a restore scenario the master database should be restored first and the msdb database should be restore restored first and the msdb database should be restore next followed by the model.next followed by the model.

The user databases should be restored last.The user databases should be restored last.

DiscussionDiscussion

Disaster Recovery scenarios.Disaster Recovery scenarios. Added input from user experience.Added input from user experience. Discussion/CommentsDiscussion/Comments