1. Trang chủ
  2. » Giáo Dục - Đào Tạo

Backup And Recovery In SQL Server

68 329 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 68
Dung lượng 1,05 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Introduction to Backup OperationsBackup and Recovery in SQL Server 2000 Lesson 2A / Slide 6 of 34 ©NIIT Backup and Recovery in SQL Server 2000 Introduction to Backup Operations • You pe

Trang 1

In this lesson, you will learn about:

•Performing backup operations

•Performing recovery operations

In this lesson, you will learn about:

Performing backup operations

Performing recovery operations

Trang 2

Backup and Recovery in SQL Server 2000 Lesson 2A / Slide 2 of 34

©NIIT

Backup and Recovery in SQL Server 2000

Pre-Assessment Questions

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

Trang 3

Backup and Recovery in SQL Server 2000 Lesson 2A / Slide 3 of 34

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

Trang 4

Backup and Recovery in SQL Server 2000 Lesson 2A / Slide 4 of 34

Trang 5

Backup and Recovery in SQL Server 2000 Lesson 2A / Slide 5 of 34

©NIIT

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

I NSTRUCTOR N OTES

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:

Trang 6

Introduction to Backup Operations

Backup and Recovery in SQL Server 2000 Lesson 2A / Slide 6 of 34

©NIIT

Backup and Recovery in SQL Server 2000

Introduction to Backup Operations

• 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).

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)

Trang 7

Reasons for Taking Backups

Backup and Recovery in SQL Server 2000 Lesson 2A / Slide 7 of 34

©NIIT

Backup and Recovery in SQL Server 2000

Reasons for Taking Backups

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

• Hardware Failure

• Natural Disasters

• Intentional or Accidental Data Loss

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

Trang 8

Identifying Backup Devices

Backup and Recovery in SQL Server 2000 Lesson 2A / Slide 8 of 34

• SQL Server 2000 uses the following types of backup devices:

• Disk Devices

• Tape Devices

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

Trang 9

Creating a Permanent Backup Device Using the SQL Server Enterprise Manager

Backup and Recovery in SQL Server 2000 Lesson 2A / Slide 9 of 34

©NIIT

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.

Trang 10

Backup and Recovery in SQL Server 2000 Lesson 2A / Slide 10 of 34

©NIIT

Backup and Recovery in SQL Server 2000

Creating a Permanent Backup Device

using the SQL Server Enterprise

Manager (Contd.)

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

Trang 11

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

Trang 12

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

Trang 13

Creating a Permanent Backup Device Using

Transact-SQL

Backup and Recovery in SQL Server 2000 Lesson 2A / Slide 11 of 34

©NIIT

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’]

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

Trang 14

Backup devices are not associated with a specific database

Identifying the Types of Backups

Backup and Recovery in SQL Server 2000 Lesson 2A / Slide 12 of 34

Trang 15

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

Trang 16

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

Trang 17

precautions that should be undertaken while performing a backup operation.

Trang 18

PERFORMING DATABASE BACKUP USING THE

DATABASE BACKUP WIZARD

Backup and Recovery in SQL Server 2000 Lesson 2A / Slide 13 of 34

©NIIT

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.

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

Trang 19

• Start the Database Backup Wizard

• Select the type of backup to be performed

• Select the backup device to be used

• Verify the backup operation

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

Trang 20

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

Trang 21

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

Trang 22

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

Trang 23

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

Trang 24

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

„Differential 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

Trang 25

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

Trang 26

5 In the Scheduling section of the Backup Verification and Scheduling

screen, select the Schedule option This automatically sets the weekly schedule as Once every week at Sunday, at 12:00 AM, as shown

6 Click the Next button to display the Completing the Create Database

Backup Wizard screen, as shown

4: Verify the backup operation

Action:

Trang 27

operation The details pane lists the backup device Mac along with the other backup

devices It shows backup has been successfully created and will run on every Sunday

at 12:00 A.M

Trang 28

P ERFORMING B ACKUPS USING

ALTERNATE METHODS

Backup and Recovery in SQL Server 2000 Lesson 2A / Slide 15 of 34

©NIIT

Backup and Recovery in SQL Server 2000

Other Ways to perform Backup

• You can perform backup in other ways:

• Using Tools menu of SQL Server 2000 Enterprise Manager

• Transact-SQL

• SQL Server 2000 enables you to perform the following types of

backups using Transact-SQL:

• Full database backup

• Differential database backup

• Filegroup backup

Trang 29

Backup and Recovery in SQL Server 2000 Lesson 2A / Slide 16 of 34

©NIIT

Backup and Recovery in SQL Server 2000

Other Ways to perform Backup

(Contd.)

•You can perform a full database backup of the SQL Server 2000 database.

BACKUP DATABASE <database_name> TO <backup_ device_name> =

BACKUP LOG <database_name> TO <transactionlog_ backup_filename>

You can also perform backup by:

„Using Tools menu of SQL Server 2000 Enterprise Manager

1 Select StartÆ All ProgramsÆ Microsoft SQL ServerÆ Enterprise

Manager, to open the Enterprise Manager.

2 From the Tools menu, select the Backup Database option, to open the SQL Server Backup dialog box

The SQL Server Backup dialog box consists of the General and Options

tabs

Trang 30

You can also display the SQL Server Backup dialog box by clicking the Database option from the Console Root and selecting the All TasksÆ Backup database option from the pop-up menu

right-that is displayed

3 In the Database drop-down list of the General tab, enter the name of the

database that needs to be backed up, as shown Then, enter the name of the

backup in the Name text box and the type of backup to be performed in the

Description text box

4 In the Backup section of the General tab, select the required backup option

You can select other types of backup operations available, such as

File and filegroup backup, Transaction log backup, and

Database-differential backup, from the Backup section The rest

of the backup process using the Enterprise Manager remains the same for all other types of backups

For the first time you need to take a complete database backup Till the time you take a complete database backup the other options in the backup section of the SQL Server Backup dialog box appear

deselected The options for File and filegroup backup,

Trang 31

5 The Destination section of the General tab displays a text box that requires

you to enter the backup device for the backup To enter the backup device,

click the Add button The Select Backup Destination dialog box appears with the File name and Backup device options

6 Select the Backup device option and click the OK button The text box in the Destination section displays the backup device selected

7 In the Overwrite section of the SQL Server Backup dialog box, select the

Append to media option Then, select the Schedule option in the Schedule

section SQL Server 2000 automatically provides you with a weekly schedule for performing backups

8 Activate the Options tab, as shown

Trang 32

9 Select the Verify backup upon completion option and verify that the Check media set name and backup set expiration option is selected Enter the

media set name in the Media set name text box

10 Click the OK button to complete the backup operation On successful

completion of the backup operation, a dialog box is displayed containing the

The backup operation has been completed successfully message, as

shown

11 Click the OK button to close the message box

Trang 33

The backup of any database provides you with the information about the database activities, such as the most recent transactions, check points issued in the database, and oldest active transaction log record It also provides information about the original database, its location, and its schema and structure

Using Transact-SQL

SQL Server 2000 enables you to perform the following types of backups using Transact-SQL:

„Full database backup

„Differential database backup

„Filegroup backup

„Transactional log backup

Full Database Backup

You can perform a full database backup of the SQL Server 2000 database using the BACKUP DATABASE statement of Transact-SQL The following is the syntax of the BACKUP DATABASE statement:

BACKUP DATABASE <database_name> TO <backup_ device_name> = <path>

In the above syntax:

„The database_name variable refers to the database for which backup needs to

be performed

„The backup_device_name variable refers to the name of the backup device

„The path variable refers to the location of the specified backup device

For example, you can use the following statement to perform a full database backup of the Employee database and store it in the Full.bak file:

BACKUP DATABASE Employee TO Disk = ‘C:\MSSQL\Full.bak’

You can also verify the backup taken The following is the syntax of the Transact-SQL statements to verify a full database backup:

BACKUP DATABASE <database_name> TO <backup_filename>

RESTORE VERIFYONLY FROM <backup_filename>

In the above syntax:

Trang 34

„The backup_filename variable refers to the file that stores the database backup

„The VERIFYONLY keyword verifies the backup stored in the backup file

For example, you can use the following statement to perform a full database backup of the employee database and store it in the Mac file The backup data is verified after the completion of the backup operation:

BACKUP DATABASE Employee TO Mac

RESTORE VERIFYONLY FROM Mac

Differential Database Backup

You can use BACKUP DATABASE statement of Transact-SQL to perform a differential database backup The following is the syntax for performing a differential database backup using BACKUP DATABASE statement:

BACKUP DATABASE <database_name> TO <backup_filename> WITH DIFFERENTIAL

In the above syntax:

„The database_name variable refers to the database for which a differential backup has to be performed

„The backup_filename variable refers to the file that stores the full database backup

„The WITH DIFFERENTIAL keyword performs the differential backup of the database

For example, you can use the following statement to perform a differential backup of the Employee database and store the backup in the Mac backup file:

BACKUP DATABASE Employee TO Mac WITH DIFFERENTIAL

Ngày đăng: 16/10/2015, 21:33

TỪ KHÓA LIÊN QUAN