0% found this document useful (0 votes)
166 views

Backing Up SQL Server Databases

This document provides an overview of backing up SQL Server databases. It covers performing full, differential, transaction log, partial and filegroup backups. Additional topics include managing backup history, retention policies, backup verification, and advanced options like compression and encryption. Demonstrations show how to perform backups and verify backups are intact. The lab scenario tasks the reader with implementing a backup solution for AdventureWorks databases based on given requirements.

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)
166 views

Backing Up SQL Server Databases

This document provides an overview of backing up SQL Server databases. It covers performing full, differential, transaction log, partial and filegroup backups. Additional topics include managing backup history, retention policies, backup verification, and advanced options like compression and encryption. Demonstrations show how to perform backups and verify backups are intact. The lab scenario tasks the reader with implementing a backup solution for AdventureWorks databases based on given requirements.

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/ 27

Module 6

Backing Up SQL Server Databases


Module Overview

• Backing Up Databases and Transaction Logs


• Managing Database Backups
• Advanced Database Options
Lesson 1: Backing Up Databases and Transaction
Logs

• Introduction to SQL Server Backups


• Media Sets and Backup Sets
• Performing Database Backups
• Performing Transaction Log Backups
• Performing Partial and Filegroup Backups
• Demonstration: Performing Backups
Introduction to SQL Server Backups

• BACKUP Transact-SQL statement


BACK UP { DATABASE | LOG } <database_name>
TO <backup_device>, [, …n]
WITH <general_options>

• SSMS
• General
• Media Options
• Backup Options
Media Sets and Backup Sets

• Media sets consist of one or more disk backup


devices
• Data is striped across multiple devices
• A backup set represents one backup of any type
• Backup sets are written to media sets
• A media set can contain multiple backup sets

• Backup devices and media sets are created at first


use:
• Use FORMAT to overwrite an existing media set
• Use INIT to overwrite existing backup sets in a media set
• Use these options with caution
Performing Database Backups

• Full backup: • Differential backup:


• Entire database • Extents modified since
• Active portion of log the last full backup
• Active portion of log file

BACKUP DATABASE AdventureWorks BACKUP DATABASE AdventureWorks


TO DISK = 'D:\Backups\AW.bak' TO DISK = 'D:\Backups\AW.bak'
WITH INIT; WITH DIFFERENTIAL, NOINIT;

INIT - Controls whether the backup operation appends to or overwrites the


existing backup sets
*Default appends the backup (NOINIT)
Performing Transaction Log Backups

• Backs up only the transaction log


• Backs up the log from the last successfully
executed log backup to the current end of the log
• Truncates inactive log records unless options
specified
BACKUP LOG AdventureWorks Note: Database must be in full
TO DISK = 'D:\Backups\AW.bak' or bulk-logged recovery mode
WITH NOINIT; Why?

• Perform a log-tail backup before restoring


BACKUP LOG AdventureWorks
TO DISK = 'D:\Backups\AW.bak'
WITH [NORECOVERY | NO_TRUNCATE | CONTINUE ON ERROR];
Performing Partial and Filegroup Backups
Note: Filegroup and partial backups
• Partial backup: are normally only used when the
size of the database makes it
• Primary filegroup impossible to meet RTO using full,
• Read/Write filegroups diff, and TL backups

BACKUP DATABASE LargeDB


READ_WRITE_FILEGROUPS
TO DISK = 'D:\Backups\LrgRW.bak‘
WITH INIT;

• File or filegroup backup:


• Specific files or filegroups

BACKUP DATABASE LargeDB


FILEGROUP = 'FG2'
TO DISK = 'D:\Backups\LrgFG2.bak‘;
WITH options

• CREDENTIAL - more information in Ch09


• FILE_SNAPSHOT - Azure snapshot
• DIFFERENTIAL - Differential backup (Full is default)
• ENCRYPTION - Encrypt the backup
• NORECOVERY - Backs up the tail of the log and leaves the
database in restoring state
• STANDBY - Backs up the tail of the log and leaves the
database in read-only state
• (NO_)TRUNCATE - Potentially allows backup of the logs
even when the database is corrupted
More WITH options

• INIT - Controls whether the backup operation appends to


or overwrites the existing backup sets
• Default appends the backup (NOINIT)
• COPY_ONLY - Not part of your regularly scheduled
backups, and therefore doesn’t affect your normal backup
schedule
• (NO_)COMPRESSION - Compress the backup (or not)
• (NO_)CHECKSUM - Verify each page of the backup, and
generate a checksum value for the entire backup
Demonstration: Performing Backups

In this demonstration, you will see how to:


• Perform a full database backup
• Perform a differential database backup
• Perform a transaction log backup
Lesson 2: Managing Database Backups

• Determining a Retention and Testing Policy for


Backups
• Options for Ensuring Backup Integrity
• Viewing Backup History
• Retrieving Backup Metadata
• Demonstration: Verifying Backups
Determining a Retention and Testing Policy for
Backups

• Planning for backup retention must be part of


the strategy and form part of the test plan to
ensure accuracy
• Several considerations:
• Combination of backups needed for a database
recovery
• Archival requirements
• Synchronization with database checks
• Available secure storage location
• Hardware required for restoring backups
• Completeness of backups
Options for Ensuring Backup Integrity

• Mirrored media sets:


• Can mirror a backup set to up to four media sets
• Mirrors require the same number of backup devices
• Only in Enterprise Edition

• CHECKSUM backup option:


• Available for all backup types
• Generates a checksum over the backup stream
• Use to verify the backup

• Backup verification:
• Can use RESTORE VERIFYONLY for backup verification
• Useful when combined with CHECKSUM option
Viewing Backup History

• SQL Server tracks all backup activity in a set of


tables in the msdb database
SELECT bs.media_set_id, bs.backup_finish_date, bs.type,
bs.backup_size, bs.compressed_backup_size,
mf.physical_device_name
FROM dbo.backupset AS bs
INNER JOIN dbo.backupmediafamily AS mf
ON bs.media_set_id = mf.media_set_id
WHERE database_name = 'AdventureWorks'
ORDER BY backup_finish_date DESC;

• The Backup and Restore Events report in SSMS


displays detailed backup history information
Retrieving Backup Metadata

• RESTORE LABELONLY returns information about


the backup media on a specified backup device
• RESTORE HEADERONLY returns all the backup
header information for all backup sets on a
particular backup device
• RESTORE FILELISTONLY returns a list of data and
log files contained in a backup set
Demonstration: Verifying Backups

In this demonstration, you will see how to:


• View the Backup and Restore Events report
• Query backup history tables
• Verify backup media
Lesson 3: Advanced Database Options

• Copy-Only Backups
• Compressing Backups
• Demonstration: Using Backup Compression
• Encrypting Backups
• Demonstration: Using Backup Encryption
Copy-Only Backups

• Back up the database without changing the


restore order
• Copy-only transaction log back ups do not
truncate the log
• Copy-only full database backups do not affect
the differential base
BACKUP DATABASE AdventureWorks
TO DISK = 'D:\Backups\AWCopy.bak'
WITH COPY_ONLY, INIT;

*TRUNCATE - Potentially allows


backup of the logs even when the
database is corrupted
Compressing Backups

• Reduces size of backup on device


• Reduces I/O requirements, increases CPU usage
• Increases speed of backup and restore
• Some restrictions:
• Cannot share media with uncompressed backups
• Cannot share media with Windows backups
• Cannot be restored to pre-2008 SQL Server versions
Encrypting Backups

1. Create a database master key for master


2. Create a certificate or asymmetric key
3. Back up the database, specifying the algorithm
and key

BACKUP DATABASE AdventureWorks


TO DISK = 'D:\Backups\AW_Encrypt,bak'
WITH FORMAT, INIT,
ENCRYPTION( ALGORITHM=AES_128,
SERVER CERTIFICATE = [BackupCert])
Lab: Backing Up Databases

• Exercise 1: Backing Up Databases


• Exercise 2: Performing Database, Differential and
Transaction Log Backups
• Exercise 3: Performing a Partial Backup

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

Estimated Time: 90 minutes


Lab Scenario

As a database administrator for Adventure Works


Cycles, you are responsible for the
AdventureWorks regional, national, and data
archive databases. You must implement a backup
solution for these databases, based on the backup
requirements that have been provided.
Lab Review

• In this lab, you have seen how to set the recovery


model for a database based on its backup
strategy, and how to perform full, differential,
transaction log, filegroup, and partial backups.
Module Review and Takeaways

• Review Question(s)
• Best Practice

You might also like