1. Trang chủ
  2. » Công Nghệ Thông Tin

Brad’s Sure Guide to SQL Server Maintenance Plans- P30 doc

5 209 0
Tài liệu đã được kiểm tra trùng lặp

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

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 519,27 KB

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

Nội dung

Full TaskThe basic purpose of a backup of a SQL Server database is to make a copy of the data so that it can be used to restore a database in the event of a disaster, such as system fail

Trang 1

(Full) Task

The basic purpose of a backup of a SQL Server database is to make a copy of the data so that

it can be used to restore a database in the event of a disaster, such as system failure, damage

to the database, corruption of the data it contains, and so on

Of all the Maintenance Plan tasks that you need to perform, this is the most important It is critical that you make full backups of your production databases on a regular basis, preferably once a day A full backup can be performed on any database in SQL Server (expect for tempdb), no matter what recovery model it uses

While the Backup Database (Full) task is the focus of this chapter, it is not the only backup task available from the Maintenance Plan Wizard In the following two chapters,

we will examine the Backup Database (Differential) task and the Backup Database (Transaction Log) task In most cases, you will combine the Backup Database (Full) task with the Backup Database (Transaction Log) task in the same Maintenance Plan In fact, once you have mastered the Backup Database (Full) task, you will find that the other backup tasks are very similar, and learning them will be easy

Note, before we start, that the Maintenance Plan Wizard performs SQL Server native

backups If you want to perform a backup using a third-party tool then, in almost all cases, you will have to use the third-party's GUI tool, or T-SQL, to perform your backups This is because third-party tools don't usually integrate with the Maintenance Plan Wizard If you are using such a tool, you can still create a Maintenance Plan using the Maintenance Plan Wizard, but you will need to leave out the backup tasks that are included with it

Backup Strategy – a Brief Primer

As I stated in the introduction, there are three basic types of database backups:

• Full backup – backs up all the data in the database This is essentially making a copy of the MDF file(s) for a given database

• Differential backups – a backup of any data that has changed since the last full backup

In other words, a differential backup makes a copy of any data in the MDF file(s) that has

Trang 2

• Transaction log backups – a backup of the transaction log (LDF) file, which stores a history of the actions performed on the data since the last log backup (or database checkpoint if working in simple recovery mode) When a log backup is made, the live

transaction log generally gets truncated to remove the backed up entries

During both full and differential backups, enough of the transaction log is backed up to enable recovery of the backed up data, and reproduce any changes made while the backup was in progress However, neither full nor differential backups truncate the transaction log All backups occur within the context of the recovery model of the database The recovery

model essentially dictates how the transaction log for that database is managed The two main recovery models are described below (there is also a third model, bulk logged which, for

the purpose of this discussion, we'll ignore but which is often used for bulk data operations)

Simple Recovery – the transaction log is automatically truncated during periodic

checkpoints and, because of this, it cannot be backed up and used to recover data

Full Recovery – the transaction log is not automatically truncated during periodic

checkpoints and so can be backed up and used to recover data

The backup strategy for a database in simple recovery mode relies entirely on full and differential backups For example, you may take full backups of your simple recovery

database every day or, for larger databases, you may opt to perform weekly full backups, and daily differential backups An advantage of simple recovery mode is that you do not have to manage the transaction log and so the backup process is much simpler On the down side, you are exposed to potential data loss to the extent of your last backup In this example, that would be the potential loss of one day's data The simple recovery model tends to be used for databases that are not "mission critical."

Transaction log truncation

There is often some confusion surrounding the topic of when the transaction log gets

truncated, and a full discussion of the topic is outside the scope of this book However, note the following:

1 In simple recovery mode, the transaction log is automatically truncated whenever a checkpoint occurs.

2 In full (or bulk logged) recovery mode the transaction log is only truncated by a log backup Truncation will take place as soon as the log backup is complete, assuming

a checkpoint has occurred since the last log backup, and that there are not other

factors preventing log truncation, such as a long-running transaction.

Trang 3

3 Truncating the log removes the backed up entries from the log, freeing up space to

be reused It does not physically shrink the log file.

4 Neither full nor differential backups truncate the transaction log.

The backup strategy for a database in full recovery mode relies on both full (plus, if necessary, differential) backups and transaction log backups So, for example, for a database in full recovery mode, you might perform daily full backups, and then log backups every hour,

or perhaps even more frequently During recovery, the full backup is restored, followed by the subsequent chain of transaction log backups This process "rolls forward" all changes recorded in the transaction log backups and applies them to the full backup, thus making

it possible to restore data up to the point in time of the disaster (or close) In this way, your exposure to potential data loss is minimized (in this case to an hour or less), but the administrative overhead to maintain this process is much larger

Avoiding differential backups

For reasons that I'll explain as we progress, I tend to avoid differential backups if I can, as they make the backup process more complicated My backup strategy, wherever possible, relies on full and transaction log backups only, as appropriate.

As noted at the start of this chapter, the reason to back up a database is in order to be able to restore it and recover the data it contains, in the event of a disaster The type and frequency

of backups that are suitable for each of your databases will be driven by business decisions that are made regarding the organization's tolerance to the potential loss of data from each database in question

A full discussion of backup planning and strategy is outside the scope of this book, and will include consideration of type and frequency of backups as well as where they are stored, how they are tested, security, and so on In fact, it's the topic for a short book in its own A

good place to start is the Introduction to Backup and Restore Strategies in SQL Server paper on

MSDN, but there are many other resources available However, hopefully this primer has provided enough background to work through this and the two subsequent chapters Suffice it to say, before we move on, that just because you have obtained a full database backup, does not necessarily mean that you can restore it The only way to ensure that your backups are sound, and the data they contain recoverable, is to test them!

Trang 4

An Overview of the Backup Database (Full) task

The purpose of the Backup Database (Full) task is to perform a full backup of the selected database(s) When the Backup Database (Full) task runs using its default settings, it executes the following T-SQL code (in this example, we're performing a full backup of the AdventureWorks database):

BACKUP DATABASE [AdventureWorks] TO DISK = N'C:\Program

Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Backup\ AdventureWorks_backup_2009_08_19_145336_3160000.bak'

WITH NOFORMAT, NOINIT, NAME = N'AdventureWorks_back

up_2009_08_19_145336_3150000', SKIP, REWIND, NOUNLOAD, STATS = 10

This is the standard BACKUP DATABASE command where the backed up database is being written to disk in a specified folder Ideally, this disk will be on a locally attached drive, a SAN,

or a NAS device that has been designated specifically for storing backups

The backup file for a Full (and Differential) backup uses the BAK extension The name of the backup is the name of the database appended with a time stamp that uniquely identifies that backup This makes it easy for you to identify backups when you view them inside a folder When a Backup Database (Full) task runs, it produces a text report similar to this one:

Microsoft(R) Server Maintenance Utility (Unicode) Version

10.0.2531

Report was generated on "HAWAII."

Maintenance Plan: User Databases Maintenance Plan

Duration: 00:00:04

Status: Succeeded.

Details:

Back Up Database (Full) (HAWAII)

Backup Database on Local server connection

Databases: AdventureWorks

Type: Full

Append existing

Task start: 2009-08-19T15:02:10.

Task end: 2009-08-19T15:02:14.

Success

Command: BACKUP DATABASE [AdventureWorks] TO DISK = N''C:\

Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\ Backup\AdventureWorks_backup_2009_08_19_150210_7570000.

Trang 5

up_2009_08_19_150210_7560000'', SKIP, REWIND, NOUNLOAD, STATS = 10

GO

Since, in this example, I was only backing up the AdventureWorks database, this is the only database I see in this report If I backed up other databases, then you would see a separate BACKUP DATABASE command for every database backed up by this task

Append existing

You might notice the phrase "Append existing" in the previous report Ignore it, as it is only relevant if you back up to a backup device or stripped set, which is something I will discuss a little later, and which I recommend you generally avoid.

When and How Often to Perform Full Backups

Here's my backup philosophy My goal is to try and perform a full backup of all my databases

every night In most cases, taking a full backup incurs minimal overhead on your SQL

Server, although I still prefer to run full backups when servers are less busy (usually at night) One exception to this would be if your SQL Server already has an I/O bottleneck; in this case, performing a backup at most any time will increase disk contention and hurt server performance Of course, if you have this problem, then you should consider tweaking the performance of your queries, or getting a faster disk I/O subsystem

If your databases are very large, you may find that you do not have the available resources (such as storage space), or even enough time, to back them up every night One option that

is worth considering, if you find yourself in this situation, is purchasing a third-party backup tool Such tools provide high-speed, compressed, and encrypted backups that you can fit into less disk space and smaller maintenance windows As noted in the introduction to this chapter, this will almost certainly mean that you cannot use the Maintenance Plan Wizard to schedule your backups, and instead you should use scripting, or the facilities provided by the third-party tool, to perform the backups

Backup compression in SQL Server 2008 Enterprise Edition

SQL Server 2008 Enterprise Edition (not standard edition) offers built-in backup

Ngày đăng: 04/07/2014, 23:20

TỪ KHÓA LIÊN QUAN