Tải bản đầy đủ (.pdf) (68 trang)

Backup And Recovery In SQL Server

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.05 MB, 68 trang )

LESSON: 2A
BACKUP AND RECOVERY IN
SQL SERVER 2000
Objectives
Backup and Recovery in SQL Server 2000

Objectives
In this lesson, you will learn about:




©NIIT

Performing backup operations
Performing recovery operations

Backup and Recovery in SQL
Server 2000

Lesson 2A / Slide 1 of 34

In this lesson, you will learn about:

 Performing backup operations
 Performing recovery operations

2A.1

Administering and Troubleshooting SQL Server 2000



Backup and Recovery in SQL Server 2000

Pre-Assessment Questions

©NIIT

1.

Which of the following server roles includes the members of Windows
built-in Administrators group by default?
a)
serveradmin
b)
securityadmin
c)
sysadmin
d)
processadmin

2.

Which of the following fixed database roles can add, delete, and modify
objects in a database using the Transact-SQL statements?
a)
db_owner
b)
db_ddladmin
c)
db_securityadmin

d)
db_accessadmin

Backup and Recovery in SQL
Server 2000

Lesson 2A / Slide 2 of 34

Administering and Troubleshooting SQL Server 2000

2A.2


Backup and Recovery in SQL Server 2000

Pre-Assessment Questions

©NIIT

2A.3

3.

Which of the following Transact-SQL Statements associated with the
members of the sysadmin and dbcreator server roles?
a)
CREATE TABLE
b)
BACKUP DATABASE
c)

CREATE DATABASE
d)
CREATE TRIGGER

4.

When a new user-defined database role is created, the entry is made in
which one of the following system tables?
a)
sysusers
b)
syspermissions
c)
sysdatabases
d)
sysmembers

Backup and Recovery in SQL
Server 2000

Lesson 2A / Slide 3 of 34

Administering and Troubleshooting SQL Server 2000


Backup and Recovery in SQL Server 2000

Pre-Assessment Questions
5.


©NIIT

Which table stores the details about the stored procedures, triggers,
and views?
a)
syscomments
b)
sysusers
c)
syspermissions
d)
sysdatabases

Backup and Recovery in SQL
Server 2000

Lesson 2A / Slide 4 of 34

Administering and Troubleshooting SQL Server 2000

2A.4


Backup and Recovery in SQL Server 2000

Solutions to Pre-assessment Questions:
Ans 1. c. sysadmin
Ans 2. b. db_ddladmin
Ans 3. c. CREATE DATABASE
Ans 4. a. Sysusers

Ans 5. a. Syscomments

©NIIT

Backup and Recovery in SQL
Server 2000

Lesson 2A / Slide 5 of 34

INSTRUCTOR NOTES
Start the session by introducing the concept of backups to the students. Tell the
students about the importance of the backup operations. Next, discuss the different
types of backup devices that can be used to back up databases in SQL Server 2000.
Then, elaborate on how to create a backup device using the SQL Server 2000
Enterprise Manager in detail. You can create a backup device, Mac using the SQL
Server 2000 Enterprise Manager. Also tell the students that a backup device can be
created using the sp_adddumpdevice system stored procedure of Transact-SQL and
explain the syntax of the sp_adddumpdevice system stored procedure. Next, discuss
about the types of backup available. Explain each type in detail and tell the students
about the situations where each type of backup is used and when each backup is
performed.
Ensure that the following datafiles are installed on the student nodes:

„Employee.mdb

2A.5

Administering and Troubleshooting SQL Server 2000



Introduction to Backup Operations
Backup and Recovery in SQL Server 2000

Introduction to Backup Operations

©NIIT



You perform backup operations as a precautionary measure to prevent
data loss.



A backup is a copy of the data that you store at a location other than
the hard disk of your computer.



You can back up data on a magnetic tape, magnetic disk, or the hard
disk of another computer system in the Local Area Network (LAN).

Backup and Recovery in SQL
Server 2000

Lesson 2A / Slide 6 of 34

You perform backup operations as a precautionary measure to prevent data loss. A
backup is a copy of the data that you store at a location other than the hard disk of
your computer. You can back up data on a magnetic tape, magnetic disk, or the hard

disk of another computer system in the Local Area Network (LAN).

Administering and Troubleshooting SQL Server 2000

2A.6


Reasons for Taking Backups

Backup and Recovery in SQL Server 2000

Reasons for Taking Backups


The following are the reasons for taking backup of your data:





©NIIT

Hardware Failure
Natural Disasters
Intentional or Accidental Data Loss

Backup and Recovery in SQL
Server 2000

Lesson 2A / Slide 7 of 34


The following are the reasons for taking backup of your data:

„Hardware Failures: This refers to data loss due to failure of hardware devices,

such as hard disk, processor, or input/output devices. The hardware devices are
expected to work without failure for a specific time period that is termed as
Mean Time Between Failure (MTBF). The MTBF is measured in hours and
indicates the average time a computer system can work without failure. This
average time is calculated by dividing the total number of functional hours
observed by the total number of failures. You can calculate the average life cycle
of your computer and perform backups periodically.

„Natural Disasters: This refers to data loss due to unpredictable situations, such
as flood, fire, and earthquakes. Since these situations are unpredictable, you
need to take backups on a regular basis.

„Intentional or Accidental Data Loss: This refers to data loss due to intentional or
accidental negligence of the user, such as accidental use of the DELETE
statement or the DROP DATABASE statement.

2A.7

Administering and Troubleshooting SQL Server 2000


Identifying Backup Devices
Backup and Recovery in SQL Server 2000

Backup Device





©NIIT

A backup device is a medium that stores the backup data. A backup
device can be a temporary device or a permanent device.
You use a temporary backup device only once, whereas you use a
permanent backup device to repeatedly store backups from the
available backup devices.
SQL Server 2000 uses the following types of backup devices:
• Disk Devices
• Tape Devices

Backup and Recovery in SQL
Server 2000

Lesson 2A / Slide 8 of 34

A backup device is a medium that stores the backup data. A backup device can be a
temporary device or a permanent device. You use a temporary backup device only
once, whereas you use a permanent backup device to repeatedly store backups from
the available backup devices. SQL Server 2000 uses the following types of backup
devices:

„Disk Devices: A disk device is the local disk of your computer system or another
computer system that is connected through LAN. A disk device should be
different from the disk storing the SQL Server 2000 data. They are usually used
to back up large databases of size 20 GB or more.


„Tape Devices: Tape devices are magnetic tapes that are physically connected to

the computer, running SQL Server 2000. They are usually used to backup small
size databases, for example databases of size less than 10 GB.
Both, tape and disk devices can be used as temporary or permanent
backup devices.

Administering and Troubleshooting SQL Server 2000

2A.8


Creating a Permanent Backup Device Using the
SQL Server Enterprise Manager
Backup and Recovery in SQL Server 2000

Creating a Permanent Backup Device
using the SQL Server Enterprise
Manager
• In SQL Server, you can create a permanent backup device using the SQL
Server Enterprise Manager.

©NIIT

2A.9

Backup and Recovery in SQL
Server 2000


Lesson 2A / Slide 9 of 34

Administering and Troubleshooting SQL Server 2000


Backup and Recovery in SQL Server 2000

Creating a Permanent Backup Device
using the SQL Server Enterprise
Manager (Contd.)

©NIIT

Backup and Recovery in SQL
Server 2000

Lesson 2A / Slide 10 of 34

In SQL Server, you can create a permanent backup device to store the backup files
using the SQL Server Enterprise Manager. The following steps enable to create a
permanent backup device using the SQL Server Enterprise Manager:
1. Select StartÆ All ProgramsÆ Microsoft SQL ServerÆ Enterprise
Manager, to open the Enterprise Manager.
2. From the Console Root, expand the Microsoft SQL Servers option and then
expand the SQL Server Group option.
3. Expand the SQL Server default instance option and expand the Management
option.
4. Right-click the Backup option, to display the pop-up menu, as shown.

Administering and Troubleshooting SQL Server 2000


2A.10


5. From the pop-up menu, select the New Backup Device option, to open the
Backup Device Properties-New Device dialog box.
6. In the Name text box of the Backup Device Properties dialog box, enter
Mac as the name of the backup device that you want to create. The backup
file name is automatically displayed in the File name text box (C:\Program
Files\Microsoft SQL Server\MSSQL\backup), as shown.

2A.11

Administering and Troubleshooting SQL Server 2000


7. Click the OK button to close the Backup Device Properties-New Device
dialog box.
8. Verify that the details pane of the SQL Server Enterprise Manager displays
the newly created backup device.

Administering and Troubleshooting SQL Server 2000

2A.12


Creating a Permanent Backup Device Using
Transact-SQL
Backup and Recovery in SQL Server 2000


Creating a Permanent Backup Device
using Transact-SQL


You can also create a permanent backup device using the
sp_adddumpdevice system stored procedure of the Transact-SQL. The
following is the syntax of the sp_adddumpdevice stored procedure:
sp_addumpdevice [@devtype =] ‘device_type’, [@logicalname =]
‘logical_name’, [@physicalname =] ‘physical_name’]

©NIIT

Backup and Recovery in SQL
Server 2000

Lesson 2A / Slide 11 of 34

You can also create a permanent backup device using the sp_addumpdevice system
stored procedure of the Transact-SQL. The following is the syntax of the
sp_addumpdevice stored procedure:
sp_addumpdevice [@devtype =] ‘device_type’, [@logicalname =]
‘logical_name’, [@physicalname =] ‘physical_name’]
In the above syntax:

„The device_type variable refers to the type of backup device that you want to

use. The value of this variable can be disk, tape or pipe. The device type has to
be specified within single quotes.

„The logical_name variable refers to the name of the backup device, and is used

by the operating system.

„The physical_name refers to the physical name of the backup device and is used
by the database administrator or the user.

2A.13

Administering and Troubleshooting SQL Server 2000


Backup devices are not associated with a specific database.

Identifying the Types of Backups
Backup and Recovery in SQL Server 2000

Types of Backups







Full
Differential
Filegroup
Differential filegroup
Transaction log
Parallel striped


©NIIT

Backup and Recovery in SQL
Server 2000

Lesson 2A / Slide 12 of 34

SQL Server 2000 provides various methods to back up databases, filegroups, and
transaction log files. The different backup methods of SQL Server are:

„Full
„Differential
„Filegroup
„Differential filegroup
„Transaction log
„Parallel striped

Administering and Troubleshooting SQL Server 2000

2A.14


Full Backup
Full backup refers to the backup of the entire SQL Server 2000 database. A full backup
operation takes the backup of the database, data files, and the transaction log files. It
also takes the backup of the database objects, system and user-defined tables, and
indexes. A full backup is predominantly used to backup data of read-only databases.
The full backup operation is necessary for a database because it provides a baseline
for recovery of data, in the event of a system failure. As a result, all other methods of
backup are performed only after performing a full database backup. It is also a

prerequisite for performing the transaction log and differential backups. A full backup
is required to rebuild databases in the case of system failure. It is also required when
you need to store new data without deleting the old data. For example, you can
perform a full database backup at the end of a financial year and use the same
database for storing data of the next financial year. You can either use Transact-SQL
or SQL Server Enterprise Manager to perform a full backup.

Differential Backup
Differential backup records and stores all the changes made to a database and
database objects, since the last full backup of the database. You can take a differential
backup only after performing a full backup. This backup operation is faster and
requires less memory space than the full backup operation because it records the last
backup. You can perform a differential backup to store the changes to the database,
database objects, filegroups, or the transaction log files since the last full database
backup. You can also use the differential backup of user databases to restore them to
a specific state at a given point-of-time. You can perform a differential backup for a
database, filegroups, and transaction log files using either the Transact-SQL or the
SQL Server Enterprise Manager.

Filegroup Backup
Filegroup backup makes copies of specific data files or the data files contained in a
single filegroup. You perform a filegroup backup for Very Large Databases (VLDBs)
when there is a time and memory space constraint and full database backup cannot be
performed. You need to carefully plan a filegroup backup so that the related data and
indexes are backed up together. Filegroup backup is performed when you want to
backup selected data files of a specific database or when the database is of the Very
Large-Scale Database (VLDB) category. Similar to differential backup, you can either
use the Transact-SQL or the SQL Server Enterprise Manager to perform a filegroup
backup.


2A.15

Administering and Troubleshooting SQL Server 2000


Differential Filegroup Backup
Differential filegroup backup refers to the backup of all the changes made to a
filegroup since the last filegroup backup. Differential filegroup backup is faster and
requires less memory space as compared to a filegroup backup because it records only
the most recent changes made to the filegroup. Differential filegroup backup is
performed when you want to backup the most recent changes made to selected data
files of specified database. You can perform this backup using either the Transact-SQL
or the SQL Server 2000 Enterprise Manager.

Transaction Log Backup
Transaction log backup is a sequential record of the information stored in a transaction
log file. A transaction log backup depends on the size of the transaction log file, the
rate at which the transactions occurs, and the fault tolerance of the system.
Transactional log backup is performed to rebuild the system and user databases.
Transaction log backup is also used to monitor and optimize the performance of
databases. You can use either the Transact-SQL or the SQL Server 2000 Enterprise
Manager to perform this backup.

Parallel Striped Backup
Parallel striped backup is used to speed up the backup operation. In this type of
backup, you use multiple backup devices to backup multiple data files, filegroups, and
transaction log files. You can use both permanent as well as temporary backup devices
to perform the backup operation. However, the backup devices should be of the same
type, either a disk or tape device. Parallel striped backup is generally used for the full
backup of Very Large Databases (VLDBs).


The members of the sysadmin and dbcreator server roles have the
permission to perform backup operations. In addition to the
members of the server roles, members of db_owner and
db_backupoperator have the permission to perform the backup
operation.
The system databases should be backed up in situations like virus
attacks and security concerns because unauthorized access of data
can corrupt the information stored in SQL. This is because system
databases stores information about all user databases and the
functionality of SQL Server. The backup of user database on the
other hand is done on a periodical basis to avoid any accidental loss
of data.

Administering and Troubleshooting SQL Server 2000

2A.16


INSTRUCTOR NOTES
You can now discuss how to perform a full database backup operation using the SQL
Server 2000 Database Backup wizard. To help the students get a better understanding
of the full database backup operation, present the students with an imaginary
business problem that requires performing of a full database backup operation.
Discuss the solution of the problem in detail by breaking the solution into small tasks.
Now, you can tell the students how to perform different types of backup operations
using the SQL Server Enterprise Manager or Transact-SQL. While explaining the
Transact-SQL method to perform backup operations, explain the syntax of the
Transact-SQL statements with examples. After discussing the various methods of
performing different types of backup operations, tell the students about the

precautions that should be undertaken while performing a backup operation.

2A.17

Administering and Troubleshooting SQL Server 2000


PERFORMING DATABASE
BACKUP USING THE
DATABASE BACKUP WIZARD
Backup and Recovery in SQL Server 2000

Performing Database Backup Using the
Database Backup Wizard
According to the security policy of Mac Aluminium, Inc., the administration department
has been asked to design a backup plan. The backup plan will use the Database Wizard
of SQL Server 2000 Enterprise Manager for taking a full backup of the Master database
and name the media set, disk device, and backup as Mac. The new full backup should be
appended to the existing backup in the disk, Mac, and should be verified after the
backup operation is complete. The backup plan includes a schedule for performing the
backup on every Sunday at 12:00 AM.

©NIIT

Backup and Recovery in SQL
Server 2000

Lesson 2A / Slide 13 of 34

Problem Statement

According to the security policy of Mac Aluminium, Inc., the administration department
has been asked to design a backup plan. The backup plan will use the Database
Wizard of SQL Server 2000 Enterprise Manager for taking a full backup of the Master
database and name the media set, disk device, and backup as Mac. The new full
backup should be appended to the existing backup in the disk, Mac, and should be
verified after the backup operation is complete. The backup plan includes a schedule
for performing the backup on every Sunday at 12:00 AM.

Administering and Troubleshooting SQL Server 2000

2A.18


Solution
Backup and Recovery in SQL Server 2000

Task List





©NIIT

Start the Database Backup Wizard
Select the type of backup to be performed
Select the backup device to be used
Verify the backup operation

Backup and Recovery in SQL

Server 2000

Lesson 2A / Slide 14 of 34

To solve the preceding problem, perform the following tasks:
1. Start the Database Backup Wizard.
2. Select the type of backup.
3. Select the backup device.
4. Verify the backup operation.

2A.19

Administering and Troubleshooting SQL Server 2000


1: Start the Database Backup Wizard
Create a backup device named Mac before you perform the steps. To
create the backup device refer to the section “Creating a Permanent
Backup Device using the SQL Server Enterprise Manager

Action:
1. Select StartÆ All ProgramsÆ Microsoft SQL ServerÆ Enterprise
Manager, to open the Enterprise Manager.
2. From the Tools menu, select the Wizards option to display the Select
Wizard dialog box, as shown.

Administering and Troubleshooting SQL Server 2000

2A.20



3. Expand the Management option and select Backup Wizard, as shown.

4. Click the OK button to display the Welcome to the Create Database
Backup Wizard screen, as shown.

5. Click the Next button to display the Select Database to Backup screen.

2A.21

Administering and Troubleshooting SQL Server 2000


2: Select the type of backup
Action:
1. In the Database drop-down list of the Select Database to Backup screen,
select the default master as the name of the database, as shown.

If you want to backup any other database, you can select the particular database from
the Database drop-down list.
2. Click the Next button to display the Type Name and Description for
Backup screen, as shown.

Administering and Troubleshooting SQL Server 2000

2A.22


The Type Name and Description for Backup screen displays the following
two textboxes:


„Name: This text box automatically displays the name of the database that
needs to be backed up.

„Description: This text box allows you to enter the description of type of
backup required.

3. Verify that master backup appears in Name text box. Enter Full database
backup in the Description text box.
4. Click the Next button to display Select Type of Backup screen, as shown.

2A.23

Administering and Troubleshooting SQL Server 2000


The Select Type of Backup screen displays the following two options:

„Differential backup
„Transaction log backup
The Differential database and Transaction log backup options are disabled
in the case of master databases. These two options would also be disabled if
you are performing the backup for the first time. Till you perform a full
database backup, you cannot perform either a differential backup or a
transactional log backup, for a user created database.
5. Select the Database backup-backup the entire database option. Click the
Next button to display the Select Backup Destination and Action screen.

3: Select the backup device
The Select Backup Destination and Action screen allows you to select the backup

device that you want to use for the backup operation. In the Select backup device
section, you can either select a Tape, File, or Backup device option. The screen
displays the default location for a file. You can also select the Append to the backup
media option to append the current backup set to any existing backup sets on the
backup media. Similarly, the Overwrite the backup media option allows you to
overwrite the current backup set on any existing backup sets on the backup media. In
addition, the Read and verify the integrity of the backup after backup option
verifies the backup files that have been written and are readable.

Action:
1. In the Select backup device section of the Select Backup Destination and
Action screen, select the Backup device option and select the name Mac
from the listbox, as shown.

Administering and Troubleshooting SQL Server 2000

2A.24


2. In the Properties section, verify that the Append to the backup media
option is selected. Select the Read and verify the integrity of the backup
after backup option.
3. Click the Next button to display the Backup Verification and Scheduling
screen.
4. In the Backup Verification and Scheduling screen, verify that the Check
media set name and backup set expiry date option is selected. Enter the
name, Mac in the Media set name text box.

2A.25


Administering and Troubleshooting SQL Server 2000


×