标签:
一,使用 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_name | DISK = ‘physical_device_name‘ } <general_WITH_options> [ ,...n ]::= --Backup Set Options COPY_ONLY | { COMPRESSION | NO_COMPRESSION } | DESCRIPTION = { ‘text‘ | @text_variable } | NAME = { backup_set_name | @backup_set_name_var } | { EXPIREDATE = { ‘date‘ | @date_var } | RETAINDAYS = { days | @days_var } } --Media Set Options { NOINIT | INIT } | { NOSKIP | SKIP } | { NOFORMAT | FORMAT } | MEDIADESCRIPTION = { ‘text‘ | @text_variable } | MEDIANAME = { media_name | @media_name_variable } | BLOCKSIZE = { blocksize | @blocksize_variable } --Data Transfer Options BUFFERCOUNT = { buffercount | @buffercount_variable } | MAXTRANSFERSIZE = { maxtransfersize | @maxtransfersize_variable } --Error Management Options { NO_CHECKSUM | CHECKSUM } | { STOP_ON_ERROR | CONTINUE_AFTER_ERROR }
--Monitoring Options STATS [ = percentage ]
During a full or differential database backup, SQL Server backs up enough of the transaction log to produce a consistent database when the backup is restored. Only a full database backup can be performed on the master database.
2,差异备份
指定DIFFERENTIAL 关键字,SQL Server 将上一次完整备份之后所做的更新数据进行备份。
DIFFERENTIAL
Used only with BACKUP DATABASE, specifies that the database or file backup should consist only of the portions of the database or file changed since the last full backup. A differential backup usually takes up less space than a full backup. Use this option so that all individual log backups performed since the last full backup do not have to be applied.
3,Backup Set 和 Media Set 的区别
Backup Set 是将database backup的set,每一个backup operation 都会创建一个backup。 Media Set 是指存储backup的Disk device,多个Disk device的集合就是media set。
二,Backup Set Options
1,指定Backup Set有效期
{ EXPIREDATE = ‘date‘| RETAINDAYS = days }
Specifies when the backup set for this backup can be overwritten. If these options are both used, RETAINDAYS takes precedence over EXPIREDATE.
EXPIREDATE = { ‘date‘| @date_var }
Specifies when the backup set expires and can be overwritten.
RETAINDAYS = { days| @days_var }
Specifies the number of days that must elapse before this backup media set can be overwritten.
2,只复制
COPY_ONLY
Specifies that the backup is a copy-only backup, which does not affect the normal sequence of backups. A copy-only backup is created independently of your regularly scheduled, conventional backups. A copy-only backup does not affect your overall backup and restore procedures for the database.
3,压缩 Backup set
{ COMPRESSION | NO_COMPRESSION }
In SQL Server 2008 Enterprise and later versions only, specifies whether backup compression is performed on this backup, overriding the server-level default. At installation, the default behavior is no backup compression. But this default can be changed by setting the backup compression default server configuration option.
三, Media Set Options
1,初始化存储媒介
{ NOINIT | INIT }
Controls whether the backup operation appends to or overwrites the existing backup sets on the backup media. The default is to append to the most recent backup set on the media (NOINIT).
NOINIT
Indicates that the backup set is appended to the specified media set, preserving existing backup sets. If a media password is defined for the media set, the password must be supplied. NOINIT is the default.
INIT
Specifies that all backup sets should be overwritten, but preserves the media header. If INIT is specified, any existing backup set on that device is overwritten, if conditions permit. By default, BACKUP checks for the following conditions and does not overwrite the backup media if either condition exists:
Any backup set has not yet expired. For more information, see the EXPIREDATE and RETAINDAYS options.
The backup set name given in the BACKUP statement, if provided, does not match the name on the backup media. For more information, see the NAME option, earlier in this section.
2,检查backup set的有效期
{ NOSKIP | SKIP }
Controls whether a backup operation checks the expiration date and time of the backup sets on the media before overwriting them.
NOSKIP
Instructs the BACKUP statement to check the expiration date of all backup sets on the media before allowing them to be overwritten. This is the default behavior.
SKIP
Disables the checking of backup set expiration and name that is usually performed by the BACKUP statement to prevent overwrites of backup sets.
3,格式化存储媒介
{ NOFORMAT | FORMAT }
Specifies whether the media header should be written on the volumes used for this backup operation, overwriting any existing media header and backup sets.
4,块大小
BLOCKSIZE = { blocksize | @blocksize_variable }
Specifies the physical block size, in bytes. The supported sizes are 512, 1024, 2048, 4096, 8192, 16384, 32768, and 65536 (64 KB) bytes. The default is 65536 for tape devices and 512 otherwise. Typically, this option is unnecessary because BACKUP automatically selects a block size that is appropriate to the device. Explicitly stating a block size overrides the automatic selection of block size.
四,Data Transfer Options
BUFFERCOUNT = { buffercount | @buffercount_variable }
Specifies the total number of I/O buffers to be used for the backup operation. You can specify any positive integer; however, large numbers of buffers might cause "out of memory" errors because of inadequate virtual address space in the Sqlservr.exe process.
The total space used by the buffers is determined by: buffercount * maxtransfersize.
MAXTRANSFERSIZE = { maxtransfersize | @maxtransfersize_variable }
Specifies the largest unit of transfer in bytes to be used between SQL Server and the backup media. The possible values are multiples of 65536 bytes (64 KB) ranging up to 4194304 bytes (4 MB).
五,Error Management Options
These options allow you to determine whether backup checksums are enabled for the backup operation and whether the operation will stop on encountering an error.
1,对backup开启校验
2,backup 出错后是否继续
{ STOP_ON_ERROR | CONTINUE_AFTER_ERROR }
Controls whether a backup operation stops or continues after encountering a page checksum error.
六,Monitoring Options
Topic1, 对Backup Set 进行压缩,好处是能够减少disk Sapce和Disk IO消耗,对系统不利的影响是压缩和解压缩都需要消耗CPU资源。
Benefit
Because a compressed backup is smaller than an uncompressed backup of the same data, compressing a backup typically requires less device I/O and therefore usually increases backup speed significantly.
Performance Impact of Compressing Backups
By default, compression significantly increases CPU usage, and the additional CPU consumed by the compression process might adversely impact concurrent operations.
Allocation of Space for the Backup File
For compressed backups, the size of the final backup file depends on how compressible the data is, and this is unknown before the backup operation finishes. Therefore, by default, when backing up a database using compression, the Database Engine uses a pre-allocation algorithm for the backup file. This algorithm pre-allocates a predefined percentage of the size of the database for the backup file. If more space is needed during the backup operation, the Database Engine grows the file. If the final size is less than the allocated space, at the end of the backup operation, the Database Engine shrinks the file to the actual final size of the backup.
To allow the backup file to grow only as needed to reach its final size, use trace flag 3042. Trace flag 3042 causes the backup operation to bypass the default backup compression pre-allocation algorithm. This trace flag is useful if you need to save on space by allocating only the actual size required for the compressed backup. However, using this trace flag might cause a slight performance penalty (a possible increase in the duration of the backup operation).
Topic2,只复制Backup set,不会影响当前的数据库备份的序列。差异备份的基准是上一次的完整备份,即差异是指从上一次full backup之后,对数据文件执行的更新操作。如果做了一个 Copy-only full backup,不会影响差异备份的base(基准),该base是上一次full backup,而非本次 Copy-only full backup。A copy-only backup cannot serve as a differential base or differential backup and does not affect the differential base.
A copy-only backup is a SQL Server backup that is independent of the sequence of conventional SQL Server backups. Usually, taking a backup changes the database and affects how later backups are restored. However, occasionally, it is useful to take a backup for a special purpose without affecting the overall backup and restore procedures for the database. Copy-only backups serve this purpose.
参考doc:
Media Sets, Media Families, and Backup Sets (SQL Server)
标签:
原文地址:http://www.cnblogs.com/ljhdo/p/5658476.html