码迷,mamicode.com
首页 > 其他好文 > 详细

backup2:backup devices

时间:2016-07-12 23:21:02      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

Backup Devices 是存储SQL Server 数据和Trasaction Log备份的文件,分为两种:Physical backup device 和 logical backup device。physical backup device 是指Windows OS的file,其 physical name 类似:"D:\FolderPaths\FileName.bak",也可以是远程共享网络上一个file,其physical name 类似:"\\ServerName\SharePaths\FileName.bak"。logical backup device 是使用系统 sp 创建的physical file的一个引用。

EXEC sp_addumpdevice disk, mydiskdump, c:\dump\dump1.bak ;

一,分布式存储backup

During a backup operation on a SQL Server database, the backed up data (the backup) is written to one or more physical backup devices. These physical backup devices are initialized when the first backup in a media set is written to it.

一次成功的Backup operation产生一个backup set,如果backup特别大,可以将 backup 分布式存储在N个不同的Backup devices上,这N个backup content组成一个backup set。每一个backup device 也称作 media family。Media set 是backup devices的有序集合,用于存储一个或多个backup set。

The backups on a set of one or more backup media compose a single media set. A media set is an ordered collection of backup media, tapes or disk files, to which one or more backup operations have written using a fixed type and number of backup devices. A given media set uses either tape drives or disk drives, but not both. For example, the backup devices associated with a media set might be three tape drives named \\.\TAPE0, \\.\TAPE1, and \\.\TAPE2. That media set contains only tapes, starting with a minimum of three tapes (one per drive). The type and number of backup devices are established when a media set is created, and they cannot be changed. However, if necessary, between backup and restore operations a given device can be replaced with a device of the same type.

A media set is created on the backup media during a backup operation by formatting the backup media. After formatting, each file or tape contains a media header for the media set and is ready to receive backup content. With the header in place, the backup operation proceeds to back up the specified data to the backup media on all of the backup devices specified for the operation.

 

Media Families

Backups created on a single nonmirrored device or a set of mirrored devices in a media set constitute a media family. The number of backup devices used for the media set determines the number of media families in a media set. For example, if a media set uses two nonmirrored backup devices, the media set contains two media families.

media set              

An ordered collection of backup media, tapes or disk files, that uses a fixed type and number of backup devices.

physical backup device              

Either a tape drive or a disk file that is provided by the operating system. A backup can be written to from 1 to 64 backup devices. If a backup requires multiple backup devices, the devices all must correspond to a single type of device (disk or tape).

backup set              

The backup content that is added to a media set by a successful backup operation.

二,Specifying a backup device by using Its Physical Name

The basic BACKUP syntax for specifying a backup file by using its physical device name is:

BACKUP DATABASE database_name 
   TO DISK = { physical_backup_device_name | @physical_backup_device_name_var }

For example:

--Localhost Disk File
BACKUP DATABASE AdventureWorks2012 
   TO DISK = Z:\SQLServerBackups\AdventureWorks2012.bak;
GO

--Remote server file
BACKUP DATABASE AdventureWorks2012 
   TO DISK = \\RemoteServerName\ShareFolderPath\\AdventureWorks2012.bak;
GO

三,Specifying a backup device by using Its Logical Name    

A logical backup device is an optional, user-defined name that points to a specific physical backup device (a disk file or tape drive). A logical backup device lets you use indirection when referencing the corresponding physical backup device.

Defining a logical backup device involves assigning a logical name to a physical device. For example, a logical device, AdventureWorksBackups, could be defined to point to the Z:\SQLServerBackups\AdventureWorks2012.bak file . Backup and restore commands can then specify AdventureWorksBackups as the backup device, instead of DISK = ‘Z:\SQLServerBackups\AdventureWorks2012.bak‘.

The logical device name must be unique among all the logical backup devices on the server instance. To view the existing logical device names, query the sys.backup_devices catalog view. This view displays the name of each logical backup device and describes the type and physical file name or path of the corresponding physical backup device.

After a logical backup device is defined, in a BACKUP or RESTORE command, you can specify the logical backup device instead of the physical name of the device. For example, the following statement backs up the AdventureWorks2012 database to the AdventureWorksBackups logical backup device.

BACKUP DATABASE AdventureWorks2012 
   TO AdventureWorksBackups;
GO

In a given BACKUP or RESTORE statement, the logical backup device name and the corresponding physical backup device name are interchangeable.

One advantage of using a logical backup device is that it is simpler to use than a long path. Using a logical backup device can help if you plan to write a series of backups to the same path or to a tape device. Logical backup devices are especially useful for identifying tape backup devices.

A backup script can be written to use a particular logical backup device. This lets you switch to a new physical backup devices without updating the script. Switching involves the following process:

  1. Dropping the original logical backup device.

  2. Defining a new logical backup device that uses the original logical device name but maps to a different physical backup device. Logical backup devices are especially useful for identifying tape backup devices.

四,Logical backup devices

1,创建 logical backup devices

sp_addumpdevice [ @devtype = ] {‘disk‘ | ‘tape‘ }
    , [ @logicalname = ] logical_name 
    , [ @physicalname = ] physical_name

sp_addumpdevice adds a backup device to the sys.backup_devices catalog view. The device can then be referred to logically in BACKUP and RESTORE statements. sp_addumpdevice does not perform any access to the physical device. Access to the specified device only occurs when a BACKUP or RESTORE statement is performed. Creating a logical backup device can simplify BACKUP and RESTORE statements, where specifying the device name is an alternative using a "TAPE =" or "DISK =" clause to specify the device path.

2,添加Logical backup devices

--Adding a disk dump device
EXEC sp_addumpdevice disk, mydiskdump, c:\dump\dump1.bak;

--Adding a network disk backup device
EXEC sp_addumpdevice disk, networkdevice, \\<servername>\<sharename>\<path>\<filename>.bak;

3,查看logical backup devices

select name,
    type_desc,
    physical_name
from sys.backup_devices

五, Media Header

Every volume of backup media (disk file or tape) contains a media header that is created when by the first backup operation that uses the tape (or disk). That header remains intact until the media is reformatted.

The media header contains all of the information required to identify the media (disk file or tape) and its place within the media family to which it belongs. This information includes:

 

六,Backup set

A successful backup operation adds a single backup set to the media set. The backup set is described in terms of the media set to which the backup belongs. If the backup media consists of only one media family, that family contains the entire backup set. If the backup media consists of multiple media families, the backup set is distributed among them. On each medium, the backup set contains a header that describes the backup set.

The following example shows a Transact-SQL statement that creates a media set called MyAdvWorks_MediaSet_1 for the     AdventureWorks2012   database using three tape drives as backup devices:

BACKUP DATABASE AdventureWorks2012
TO TAPE = \\.\tape0, TAPE = \\.\tape1, TAPE = \\.\tape2
WITH 
   FORMAT,
   MEDIANAME = MyAdvWorks_MediaSet_1

If successful, this backup operation results in a new media set containing a new media header and one backup set spread across three tapes. The following figure illustrates these results:

 技术分享

 

Typically, after a media set is created, subsequent backup operations, one after another, append their backup sets to the media set. All of the media used by a backup set make up the media set, regardless of the number of media or backup devices involved. Backup sets are sequentially numbered by their position in the media set, allowing you to specify which backup set to restore.

Every backup operation to a media set must write to the same number and type of backup devices. With multiple devices, as with the first backup set, the content of every subsequent backup set is distributed among the backup media on all of the devices. To continue the above example, a second backup operation (a differential backup) appends information to the same media set:

BACKUP DATABASE AdventureWorks2012
TO TAPE = \\.\tape0, TAPE = \\.\tape1, TAPE = \\.\tape2
WITH 
   NOINIT,
   MEDIANAME = AdventureWorksMediaSet1,
   DIFFERENTIAL

If the second backup operation succeeds, it writes a second backup set to the media set, with the following distribution of backup content:

技术分享

When you are restoring backups, you can use you the FILE option to specify which backups you want to use. The following example shows the use of FILE = backup_set_file_number clauses when restoring a full database backup of the     AdventureWorks2012   database followed by a differential database backup on the same media set. The media set uses three backup tapes, which are on tape drives \\.\tape0, tape1, and tape2.

RESTORE DATABASE AdventureWorks2012 
FROM TAPE = \\.\tape0, TAPE = \\.\tape1, TAPE = \\.\tape2
   WITH 
   MEDIANAME = AdventureWorksMediaSet1,
   FILE=1, 
   NORECOVERY;
RESTORE DATABASE AdventureWorks2012 
FROM TAPE = \\.\tape0, TAPE = \\.\tape1, TAPE = \\.\tape2 
   WITH 
   MEDIANAME = AdventureWorksMediaSet1,
   FILE=2, 
   RECOVERY;
GO

 

参考文档:

Backup Devices (SQL Server)

Media Sets, Media Families, and Backup Sets (SQL Server)

sys.backup_devices (Transact-SQL)

sp_addumpdevice (Transact-SQL)

backup2:backup devices

标签:

原文地址:http://www.cnblogs.com/ljhdo/p/5658675.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!