backup2:backup devices

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)

时间: 2024-10-27 07:46:14

backup2:backup devices的相关文章

backup3:backup devices 的查询和验证

Backup database 命令执行成功之后,SQL Server 会创建相应的Backup set,media set 和 backup media family,在msdb中,存在相应的table来查询metadata. BACKUP DATABASE [TestSite] TO disk = 'D:\TestDBBackupFolder\Site1_db_bak1.bak', disk = 'D:\TestDBBackupFolder\Site1_db_bak2.bak' MIRROR

backup1:backup database

一,使用 BACKUP Database 命令创建数据库的完整备份和差异备份.1,syntax --Backing Up a Whole Database BACKUP DATABASE database_name TO <backup_device> [ ,...n ] [ WITH { DIFFERENTIAL | <general_WITH_options> [ ,...n ] } ] [;] <backup_device>::= { logical_device

backup4:backup operation

在backup operation 中,必须控制好 Init,NoSkip 和 Format 三个选项. 1,在做Full backup时,使用 Format Option 创建新的Media Set Format选项和NoSkip选项,NoInit选项是冲突的,在使用Format选项时,必须和 Skip, Init选项搭配. Option 'format' conflicts with option(s) 'noskip'. Option 'format' conflicts with opt

python实例:backup 备份

本文来源于<python简明教程>中的实例 1. 提出问题: 我想要一个可以为我的所有重要文件创建备份的程序.2. 分析明确问题:我们如何确定该备份哪些文件?备份保存在哪里?我们怎么样存储备份?3. 设计程序列表: 1). 需要备份的文件和目录由一个列表指定. 2). 备份应该保存在主备份目录中. 3). 文件备份成一个zip文件. 4). zip存档的名称是当前的日期和时间. 4. 编写代码: # Filename: backup_ver1.py import os import time

backup2:数据库还原

数据库还原的操作,分两步进行:第一步,验证(verify)备份文件:第二步,根据备份策略还原数据库: 参考<backup1:开始数据库备份>,备份策略是: 一周一次完整备份,一天一次差异备份,一小时一次事务日志备份 数据/日志的每次备份都使用一个单独的备份文件,数据备份的扩展名是 .bak,日志备份的扩展名是.trn 一,验证(Verifiy)备份文件 1,查看备份文件的文件列表(Data File 和 Log File) 由于,数据或日志的每次备份,都使用一个单独的备份文件,因此,在备份文件

backup4:数据库自动备份,自动删除备份文件

一:手写TSQL 脚本 1,自动备份 每周进行一次Database 的 Full Backup,设置 Schedule Interval 为Weekly use master go declare @FileName nvarchar(256) set @FileName = N'D:\SQLBackupFolder\TestDB_FullBackup_'+CONVERT(nvarchar(max),getdate(),112)+N'.bak' BACKUP DATABASE [TESTDB]

Setting Up and Configuring Backup and Recovery1

3.Setting Up and Configuring Backup and Recovery 这个单元讲述如何启动.与rman client如何互动,准备rman环境,实现备份和恢复策略 注意:尽管闪回数据库和安全还原点不是真的数据库备份,但是它们是数据保护策略一个重要部分.这些特性需要一些初始化设置,这些设置依赖于在备份策略中你怎么混合它们.Chapter 5-Data Protection with Restore Points andFlashback Database 提供了关于怎么

How to setup backup by using EMC NW + EMC NMM for sqlserver failover cluster (not always on)

As we said, sqlsever fail over cluster is perviously version of always on. The HA was guarenteed by OS not database. Therefor, we can not use windows cluster name as client name, because there is no windows cluster name in system. How and what to do

backup1:开始数据库备份

数据库备份分为数据文件备份和日志文件备份,数据文件的备份分为:完整备份和差异备份.在SQL Server 2012中,能够将数据分布式备份到不同的存储设备上,一般情况,只将数据备份到一个备份文件(.bak)中,只有在备份超大的数据库时,才需要分布式备份. 数据库备份的策略一般是:一周一次完整备份,一天一次差异备份,一小时一次事务日志备份,根据数据容灾的要求,适当增减备份的时间间隔. 为了便于管理数据备份文件,推荐的做法是: 数据/日志的每次备份都使用一个单独的备份文件,数据备份的扩展名是 .ba