zoukankan      html  css  js  c++  java
  • SQLSERVER数据库备份操作和还原操作做了什么

    SQLSERVER数据库备份操作和还原操作做了什么

    看了这篇文章:还原/备份时做了些什么

    自己也测试了一下,下面说的错误日志指的是SQLSERVER ERRORLOG

    一般在C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLLOG路径下,如果SQLSERVER安装在C盘的话

    要打开跟踪标志:3004, 3605

    完整备份

    先清空错误日志

    1 EXEC [sys].[sp_cycle_errorlog]

    执行数据库完整备份

    1  DBCC traceon(3004, 3605, -1)
    2  --完整备份
    3  BACKUP DATABASE [pratice]
    4  TO DISK='D:pratice_fullbackup_201207160152.bak'


    读取错误日志

    1 EXEC [sys].[xp_readerrorlog]

    备份时候,查询窗口的输出

    1 已为数据库 'pratice',文件 'pratice' (位于文件 2 上)处理了 28152 页。
    2 已为数据库 'pratice',文件 'pratice_log' (位于文件 2 上)处理了 2 页。
    3 BACKUP DATABASE 成功处理了 28154 页,花费 1.639 秒(134.195 MB/秒)。

    错误日志输出

     1 1 2013-12-01 19:17:50.300 spid56       DBCC TRACEON 3004, server process ID (SPID) 56. This is an informational message only; no user action is required.
     2  2 2013-12-01 19:17:50.300 spid56       DBCC TRACEON 3605, server process ID (SPID) 56. This is an informational message only; no user action is required.
     3  3 2013-12-01 19:17:50.300 spid56       BackupDatabase: Database pratice
     4  4 2013-12-01 19:17:50.320 spid56       Backup: Media open
     5  5 2013-12-01 19:17:50.320 spid56       Backup: Media ready to backup
     6  6 2013-12-01 19:17:50.320 spid56       Backup: Clearing differential bitmaps   ---正在清除DCM页面的位信息,因为是完整备份,差异变更(Differential Changed Map,DCM)页面  http://tech.it168.com/a2010/0921/1106/000001106857.shtml
     7  7 2013-12-01 19:17:50.330 spid56       Backup: Bitmaps cleared
     8  8 2013-12-01 19:17:50.330 spid56       BackupDatabase: Checkpoint done   --做checkpoint,将所有修改的数据都被写入磁盘
     9  9 2013-12-01 19:17:50.330 spid56       Backup: Scanning allocation bitmaps  --扫描数据库第3页:GAM页 和数据库第4页:SGAM页
    10 10 2013-12-01 19:17:50.340 spid56       Backup: Done with allocation bitmaps
    11 11 2013-12-01 19:17:50.340 spid56       BackupDatabase: Work estimates done  --估计备份操作所需要的时间
    12 12 2013-12-01 19:17:50.340 spid56       Backup: Leading metadata section done
    13 13 2013-12-01 19:17:50.340 spid56       Backup:Copying data   --正在拷贝数据
    14 14 2013-12-01 19:17:50.340 spid56       Backup: DBReaderCount = 1   --备份数据库读线程只有一个
    15 15 2013-12-01 19:17:50.340 spid56       Started file D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice.mdf
    16 16 2013-12-01 19:17:51.970 spid56       Completed file D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice.mdf
    17 17 2013-12-01 19:17:51.970 spid56       Padding MSDA with 65536 bytes
    18 18 2013-12-01 19:17:51.970 spid56       BackupDatabase: Database files done
    19 19 2013-12-01 19:17:51.980 spid56       慂正灵慄慴慢敳退慂正灵潌g邐%s : Log files done
    20 20  : Log files done
    21 21 2013-12-01 19:17:51.980 spid56       Backup: Trailing config done  --后续配置完成
    22 22 2013-12-01 19:17:51.980 spid56       Backup: MBC done
    23 23 2013-12-01 19:17:51.990 spid56       BackupDatabase: Writing history records  --写入备份历史记录到错误日志
    24 24 2013-12-01 19:17:51.990 备份           Database backed up. Database: pratice, creation date(time): 2013/11/19(19:35:23), pages dumped: 28171, first LSN: 3087:10132:37, last LSN: 3087:10149:1, number of dump devices: 1, device information: (FILE=1, TYPE=DISK: {D:pratice_fullbackup_201207160152   --pages dumped: 28171  BACKUP DATABASE 成功处理了 28154 页,花费 1.639 秒(134.195 MB/秒)
    25 25 2013-12-01 19:17:51.990 spid56       Writing backup history records  --写入备份历史记录到msdb的相关备份表
    26 26 2013-12-01 19:17:52.010 spid56       BackupDatabase: Finished

    关键的语句我都做了一些解释


    2013-12-01 19:17:50.320 spid56       Backup: Clearing differential bitmaps   ---正在清除DCM页面的位信息,

    因为是完整备份,差异变更(Differential Changed Map,DCM)页面  http://tech.it168.com/a2010/0921/1106/000001106857.shtml

    差异备份

    1 --差异备份
    2 Backup Database [pratice]
    3 To disk='d:pratice_Diff_20070908.bak'
    4 With Differential

    备份时候,查询窗口的输出

    1 已为数据库 'pratice',文件 'pratice' (位于文件 1 上)处理了 40 页。
    2 已为数据库 'pratice',文件 'pratice_log' (位于文件 1 上)处理了 1 页。
    3 BACKUP DATABASE WITH DIFFERENTIAL 成功处理了 41 页,花费 0.016 秒(20.019 MB/秒)。

    错误日志输出

     1 2013-12-01 19:42:29.790 spid56       BackupDatabase: Database pratice
     2 2013-12-01 19:42:29.820 spid56       Backup: Media open
     3 2013-12-01 19:42:29.820 spid56       Backup: Media ready to backup
     4 2013-12-01 19:42:29.820 spid56       BackupDatabase: Checkpoint done
     5 2013-12-01 19:42:29.820 spid56       Backup: Scanning allocation bitmaps
     6 2013-12-01 19:42:29.830 spid56       Backup: Done with allocation bitmaps
     7 2013-12-01 19:42:29.830 spid56       BackupDatabase: Work estimates done
     8 2013-12-01 19:42:29.830 spid56       Backup: Leading metadata section done
     9 2013-12-01 19:42:29.830 spid56       Backup:Copying data
    10 2013-12-01 19:42:29.830 spid56       Backup: DBReaderCount = 1
    11 2013-12-01 19:42:29.830 spid56       Started file D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice.mdf
    12 2013-12-01 19:42:29.830 spid56       Completed file D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice.mdf
    13 2013-12-01 19:42:29.830 spid56       Padding MSDA with 720896 bytes
    14 2013-12-01 19:42:29.840 spid56       BackupDatabase: Database files done
    15 2013-12-01 19:42:29.840 spid56       慂正灵慄慴慢敳退慂正灵潌g邐%s : Log files done
    16  : Log files done
    17 2013-12-01 19:42:29.840 spid56       Backup: Trailing config done
    18 2013-12-01 19:42:29.840 spid56       Backup: MBC done
    19 2013-12-01 19:42:29.840 spid56       BackupDatabase: Writing history records
    20 2013-12-01 19:42:29.840 备份           Database differential changes were backed up. Database: pratice, creation date(time): 2013/11/19(19:35:23), pages dumped: 139, first LSN: 3087:10184:34, last LSN: 3087:10200:1, full backup LSN: 3087:10159:37, number of dump devices: 1, device information: 
    21 2013-12-01 19:42:29.850 spid56       Writing backup history records
    22 2013-12-01 19:42:29.860 spid56       BackupDatabase: Finished

    跟完整备份的错误日志差不多

    日志备份

    1 --日志备份,默认截断日志
    2 Backup Log [pratice]
    3 To disk='d:pratice_Log_20070908.bak'

    备份时候,查询窗口的输出

    1 已为数据库 'pratice',文件 'pratice_log' (位于文件 1 上)处理了 29 页。
    2 BACKUP LOG 成功处理了 29 页,花费 0.008 秒(27.954 MB/秒)。

    错误日志输出

     1 2013-12-01 19:48:02.080 spid56       BackupLog: database pratice
     2 2013-12-01 19:48:02.100 spid56       BackupLog: SafeCheckpoint done
     3 2013-12-01 19:48:02.110 spid56       Backup: Media open
     4 2013-12-01 19:48:02.110 spid56       Backup: Media ready to backup
     5 2013-12-01 19:48:02.110 spid56       BackupLog: Work estimate done
     6 2013-12-01 19:48:02.110 spid56       Backup: Leading metadata section done
     7 2013-12-01 19:48:02.110 spid56       慂正灵潌g邐%s : Log files done
     8  : Log files done
     9 2013-12-01 19:48:02.110 spid56       Backup: Trailing config done
    10 2013-12-01 19:48:02.110 spid56       Backup: MBC done
    11 2013-12-01 19:48:02.120 spid56       BackupLog: Writing history records
    12 2013-12-01 19:48:02.120 备份           Log was backed up. Database: pratice, creation date(time): 2013/11/19(19:35:23), first LSN: 3087:9742:1, last LSN: 3087:10200:1, number of dump devices: 1, device information: (FILE=1, TYPE=DISK: {'d:pratice_Log_20070908.bak'}). This is an informational m
    13 2013-12-01 19:48:02.120 spid56       Writing backup history records
    14 2013-12-01 19:48:02.140 spid56       BackupLog: Finished

    日志备份里只有这句话跟差异备份和完整备份不一样

    1 2013-12-01 19:48:02.100 spid56       BackupLog: SafeCheckpoint done

    文件备份

    1 --文件备份
    2 Exec Sp_Helpdb pratice --查看数据文件
    3 Backup Database pratice
    4 File='pratice'   --数据文件的逻辑名
    5 To disk='d:pratice_File_20070908.bak'

    备份时候,查询窗口的输出

    1 已为数据库 'pratice',文件 'pratice' (位于文件 1 上)处理了 28152 页。
    2 已为数据库 'pratice',文件 'pratice_log' (位于文件 1 上)处理了 2 页。
    3 BACKUP DATABASE...FILE=<name> 成功处理了 28154 页,花费 1.663 秒(132.258 MB/秒)。

    错误日志输出

     1 2013-12-01 20:53:13.480 spid56       BackupDatabase: Database pratice
     2 2013-12-01 20:53:13.500 spid56       Backup: Media open
     3 2013-12-01 20:53:13.500 spid56       Backup: Media ready to backup
     4 2013-12-01 20:53:13.500 spid56       Backup: Clearing differential bitmaps
     5 2013-12-01 20:53:13.500 spid56       Backup: Bitmaps cleared
     6 2013-12-01 20:53:13.510 spid56       BackupDatabase: Checkpoint done
     7 2013-12-01 20:53:13.510 spid56       Backup: Scanning allocation bitmaps
     8 2013-12-01 20:53:13.510 spid56       Backup: Done with allocation bitmaps
     9 2013-12-01 20:53:13.510 spid56       BackupDatabase: Work estimates done
    10 2013-12-01 20:53:13.510 spid56       Backup: Leading metadata section done
    11 2013-12-01 20:53:13.510 spid56       Backup:Copying data
    12 2013-12-01 20:53:13.520 spid56       Backup: DBReaderCount = 1
    13 2013-12-01 20:53:13.520 spid56       Started file D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice.mdf
    14 2013-12-01 20:53:15.200 spid56       Completed file D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice.mdf
    15 2013-12-01 20:53:15.200 spid56       Padding MSDA with 65536 bytes
    16 2013-12-01 20:53:15.200 spid56       BackupDatabase: Database files done
    17 2013-12-01 20:53:15.210 spid56       慂正灵慄慴慢敳退慂正灵潌g邐%s : Log files done
    18  : Log files done
    19 2013-12-01 20:53:15.210 spid56       Backup: Trailing config done
    20 2013-12-01 20:53:15.210 spid56       Backup: MBC done
    21 2013-12-01 20:53:15.220 spid56       BackupDatabase: Writing history records
    22 2013-12-01 20:53:15.220 备份           Database file was backed up. Database: pratice, creation date(time): 2013/11/19(19:35:23), file list: (pratice(D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice.mdf)), pages dumped: 28171, number of dump devices: 1, device informatio
    23 2013-12-01 20:53:15.230 spid56       Writing backup history records
    24 2013-12-01 20:53:15.240 spid56       BackupDatabase: Finished

    文件组备份

    1 --文件组备份
    2 Exec Sp_Helpdb pratice --查看数据文件
    3 Backup Database pratice
    4 FileGroup='Primary'   --数据文件的逻辑名
    5 To disk='d:pratice_FileGroup_20070908.bak'
    6 With init

    备份时候,查询窗口的输出

    1 已为数据库 'pratice',文件 'pratice' (位于文件 1 上)处理了 28152 页。
    2 已为数据库 'pratice',文件 'pratice_log' (位于文件 1 上)处理了 2 页。
    3 BACKUP DATABASE...FILE=<name> 成功处理了 28154 页,花费 1.679 秒(130.998 MB/秒)。

    错误日志输出

     1 2013-12-01 20:58:49.790 spid56       BackupDatabase: Database pratice
     2 2013-12-01 20:58:49.800 spid56       Backup: Media open
     3 2013-12-01 20:58:49.800 spid56       Backup: Media ready to backup
     4 2013-12-01 20:58:49.800 spid56       Backup: Clearing differential bitmaps
     5 2013-12-01 20:58:49.810 spid56       Backup: Bitmaps cleared
     6 2013-12-01 20:58:49.810 spid56       BackupDatabase: Checkpoint done
     7 2013-12-01 20:58:49.810 spid56       Backup: Scanning allocation bitmaps
     8 2013-12-01 20:58:49.820 spid56       Backup: Done with allocation bitmaps
     9 2013-12-01 20:58:49.820 spid56       BackupDatabase: Work estimates done
    10 2013-12-01 20:58:49.820 spid56       Backup: Leading metadata section done
    11 2013-12-01 20:58:49.820 spid56       Backup:Copying data
    12 2013-12-01 20:58:49.820 spid56       Backup: DBReaderCount = 1
    13 2013-12-01 20:58:49.820 spid56       Started file D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice.mdf
    14 2013-12-01 20:58:51.480 spid56       Completed file D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice.mdf
    15 2013-12-01 20:58:51.480 spid56       Padding MSDA with 65536 bytes
    16 2013-12-01 20:58:51.480 spid56       BackupDatabase: Database files done
    17 2013-12-01 20:58:51.480 spid56       慂正灵慄慴慢敳退慂正灵潌g邐%s : Log files done
    18  : Log files done
    19 2013-12-01 20:58:51.480 spid56       Backup: Trailing config done
    20 2013-12-01 20:58:51.480 spid56       Backup: MBC done
    21 2013-12-01 20:58:51.500 spid56       BackupDatabase: Writing history records
    22 2013-12-01 20:58:51.500 备份           Database file was backed up. Database: pratice, creation date(time): 2013/11/19(19:35:23), file list: (pratice(D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice.mdf)), pages dumped: 28171, number of dump devices: 1, device informatio
    23 2013-12-01 20:58:51.500 spid56       Writing backup history records
    24 2013-12-01 20:58:51.520 spid56       BackupDatabase: Finished

    在完整备份和差异备份里面为什麽,查询窗口输出的“成功处理页面”比 错误日志里pages dumped的页面还要少??

    就算加上数据库头部的一些关键页面PFS 、DCM、 BCM、 IAM页面加起来也没有那麽多

    数据库头部的一些关键页面PFS 、DCM、 BCM、 IAM参考文章:查看SQLSERVER内部数据页面的小插件Internals Viewer

    下面是完整备份时候的输出,多了17页

    BACKUP DATABASE 成功处理了 28154 页
    pages dumped: 28171

    其实文章里也有提示:还原/备份时做了些什么

    比如,你有个1TB的数据库,但是只储存了100GB的数据,那么备份的时候,只需要备份这100GB的数据。

    然而,在还原数据库的时候,你必须重构1TB的数据库,那将意味着大量的时间将被消耗

    这篇文章也有一些提示:谁用掉了我的数据库空间?

    SQL Server在使用数据页的时候,为了提高速度,会先把一些页面一次预留”reserve”给表格,然后真正有数据插入的时候,再使用

    查询窗口里输出的是实际就是数据库真正存储数据的页面的数量

    BACKUP DATABASE 成功处理了 28154 页

    而错误日志就是所有页面,不论是存储数据还是PFS页面还是预留页面

    相关实验:下面的实验创建了一个3GB大小的数据库,然后插入了一些数据到数据库中

    (1)不对数据库进行收缩,直接备份数据库,然后还原

    (2)先对数据库进行收缩,备份数据库,然后还原

    USE master
    GO
    --创建数据库 初始大小为3G
    CREATE DATABASE [testbackupdb] ON PRIMARY 
    ( NAME = N'testbackupdb', 
    FILENAME = N'D:Program FilesMicrosoft SQL ServerMSSQL10_50.MSSQLSERVERMSSQLDATA	estbackupdb.mdf' , SIZE = 3072000KB , FILEGROWTH = 1024KB )
        LOG ON 
    ( NAME = N'testbackupdb_log', 
    FILENAME = N'D:Program FilesMicrosoft SQL ServerMSSQL10_50.MSSQLSERVERMSSQLDATA	estbackupdb_log.ldf' , SIZE = 1024KB , FILEGROWTH = 10%)
    GO
    
    --创建表
    USE [testbackupdb]
    GO
    
    CREATE TABLE aa (id INT,NAME NVARCHAR(MAX))
    GO
    
    --插入数据
    INSERT INTO aa
    SELECT 1,REPLICATE('aa',500)
    GO 10000
    
    --查看表使用的空间 大概26MB
    sys.sp_spaceused aa
    
    sys.sp_helpdb [testbackupdb]
    
    
    --备份数据库
    BACKUP DATABASE [testbackupdb] TO DISK ='d:	estbackupdb_fullbackup.bak' 
    
    
    --删除数据库
    DROP DATABASE [testbackupdb]
    
    
    
    --1、还原数据库   没有收缩数据库的情况下
    SET STATISTICS TIME ON
    RESTORE DATABASE [testbackupdb] FROM  DISK = N'D:	estbackupdb_fullbackup.bak' WITH  FILE = 1, 
    MOVE N'testbackupdb' TO N'D:	estbackupdb.mdf',  
    MOVE N'testbackupdb_log' TO N'D:	estbackupdb_1.ldf', 
    NOUNLOAD,  REPLACE,  STATS = 10
    GO
    SET STATISTICS TIME OFF
    
     SQL Server 执行时间:
       CPU 时间 = 140 毫秒,占用时间 = 3024 毫秒。
    SQL Server 分析和编译时间: 
       CPU 时间 = 0 毫秒,占用时间 = 0 毫秒。
    -------------------------------------------------------------------------------------------
    --收缩数据库为100MB
    USE [testbackupdb]
    GO
    DBCC SHRINKFILE (N'testbackupdb' , 100)
    GO
    
    
    --备份数据库
    BACKUP DATABASE [testbackupdb] TO DISK ='d:	estbackupdb_fullbackup.bak' 
    
    
    --删除数据库
    DROP DATABASE [testbackupdb]
    
    --2、还原数据库   没有收缩数据库的情况下
    SET STATISTICS TIME ON
    RESTORE DATABASE [testbackupdb] FROM  DISK = N'D:	estbackupdb_fullbackup.bak' WITH  FILE = 1, 
    MOVE N'testbackupdb' TO N'D:	estbackupdb.mdf',  
    MOVE N'testbackupdb_log' TO N'D:	estbackupdb_1.ldf', 
    NOUNLOAD,  REPLACE,  STATS = 10
    GO
    SET STATISTICS TIME OFF
    
     SQL Server 执行时间:
       CPU 时间 = 140 毫秒,占用时间 = 1549 毫秒。
    SQL Server 分析和编译时间: 
       CPU 时间 = 0 毫秒,占用时间 = 10 毫秒。
    
    
    
    --查看数据库大小
    sys.sp_spaceused aa
    
    sys.sp_helpdb [testbackupdb]
    
    --结论:备份数据库前先收缩,还原数据库的时候会比较快
    --因为收缩了数据库之后,数据库的size变成了收缩之后的大小,其实还原数据库的时候
    --SQLSERVER根据根据这个初始大小先初始化出这个数据库初始大小的磁盘空间,然后再复制数据
    View Code

    结论:备份数据库前先收缩,还原数据库的时候会比较快
    因为收缩了数据库之后,数据库的size变成了收缩之后的大小,其实还原数据库的时候
    SQLSERVER根据根据这个初始大小先初始化出这个数据库初始大小的磁盘空间,然后再复制数据

     


    数据库还原时候的信息

    执行下面脚本先kill掉所有连接到pratice数据库的连接

     1 --执行下面脚本先kill掉所有连接到pratice数据库的连接
     2 USE master
     3 GO
     4 DECLARE @spid INT
     5 DECLARE @count INT
     6 WHILE @count > 0
     7     BEGIN
     8         SELECT  @count = COUNT(*)
     9         FROM    sys.[sysprocesses]
    10         WHERE   [dbid] = DB_ID('pratice')
    11         SELECT  @spid = [spid]
    12         FROM    sys.[sysprocesses]
    13         WHERE   [dbid] = DB_ID('pratice')
    14         EXEC('kill '+@spid)
    15     END
    1 --完整备份还原
    2 RESTORE DATABASE [pratice]
    3 FROM DISK ='D:pratice_backup_201207160152.bak' WITH REPLACE

    还原的时候,查询窗口的输出

    1 已为数据库 'pratice',文件 'pratice' (位于文件 1 上)处理了 28152 页。
    2 已为数据库 'pratice',文件 'pratice_log' (位于文件 1 上)处理了 2 页。
    3 RESTORE DATABASE 成功处理了 28154 页,花费 2.267 秒(97.020 MB/秒)。

    错误日志输出

     1 2013-12-01 21:20:47.490 spid56       RestoreDatabase: Database pratice
     2 2013-12-01 21:20:47.490 spid56       Opening backup set  --打开备份集
     3 2013-12-01 21:20:47.500 spid56       SetTargetRestoreAge: 0
     4 2013-12-01 21:20:47.500 spid56       Restore: Configuration section loaded  --读取数据库配置,例如数据库的初始大小
     5 2013-12-01 21:20:47.500 spid56       Restore: Backup set is open
     6 2013-12-01 21:20:47.500 spid56       Restore: Planning begins
     7 2013-12-01 21:20:47.520 spid56       Halting FullText crawls on database pratice  --因为pratice数据库使用了全文搜索,这里会Halting停止全文搜索抓取
     8 2013-12-01 21:20:47.520 spid56       Dismounting FullText catalogs  --卸载FullText目录
     9 2013-12-01 21:20:47.520 spid56       X-locking database: pratice    --用排他锁锁住pratice数据库
    10 2013-12-01 21:20:47.520 spid56       Resuming any halted fulltext crawls  恢复全文搜索抓取
    11 2013-12-01 21:21:28.310 spid56       RestoreDatabase: Database pratice
    12 2013-12-01 21:21:28.310 spid56       Opening backup set
    13 2013-12-01 21:21:28.320 spid56       SetTargetRestoreAge: 0
    14 2013-12-01 21:21:28.320 spid56       Restore: Configuration section loaded
    15 2013-12-01 21:21:28.320 spid56       Restore: Backup set is open
    16 2013-12-01 21:21:28.320 spid56       Restore: Planning begins
    17 2013-12-01 21:21:28.340 spid56       Halting FullText crawls on database pratice
    18 2013-12-01 21:21:28.340 spid56       Dismounting FullText catalogs
    19 2013-12-01 21:21:28.340 spid56       X-locking database: pratice
    20 2013-12-01 21:21:28.340 spid56       Restore: Planning complete
    21 2013-12-01 21:21:28.340 spid56       Restore: BeginRestore (offline) on pratice
    22 2013-12-01 21:21:28.340 spid56       AppDomain 2 (pratice.dbo[runtime].1) is marked for unload due to common language runtime (CLR) or security data definition language (DDL) operations.                    --卸载CLR
    23 2013-12-01 21:21:28.350 spid20s      AppDomain 2 (pratice.dbo[runtime].1) unloaded.
    24 2013-12-01 21:21:28.360 spid56       Restore: PreparingContainers  --准备容器
    25 2013-12-01 21:21:28.390 spid56       Restore: Containers are ready --容器准备完成
    26 2013-12-01 21:21:28.390 spid56       Zeroing D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice_log.ldf from page 1 to 6528 (0x2000 to 0x3300000) --日志填零初始化
    27 2013-12-01 21:21:28.430 spid56       Restore: Restoring backup set
    28 2013-12-01 21:21:28.430 spid56       Restore: Transferring data to pratice   --传输数据到pratice数据库
    29 2013-12-01 21:21:28.570 spid56       Zeroing completed on D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice_log.ldf 
    30 http://blogs.msdn.com/b/apgcdsd/archive/2013/06/17/sql-server-log-write.aspx
    31 2013-12-01 21:21:30.670 spid56       Restore: Waiting for log zero on pratice
    32 2013-12-01 21:21:30.680 spid56       Restore: LogZero complete  --日志填零完毕
    33 2013-12-01 21:21:30.680 spid56       SetTargetRestoreAge: 0
    34 2013-12-01 21:21:30.700 spid56       FileHandleCache: 0 files opened. CacheSize: 12
    35 2013-12-01 21:21:30.700 spid56       Restore: Data transfer complete on pratice  --数据传输完毕
    36 2013-12-01 21:21:30.710 spid56       Restore: Backup set restored  --备份集已经还原
    37 2013-12-01 21:21:30.720 spid56       Starting up database 'pratice'.  --启动pratice数据库
    38 2013-12-01 21:21:30.780 spid56       The database 'pratice' is marked RESTORING and is in a state that does not allow recovery to be run.  --数据库处于正在还原状态,还未能完全恢复进行运行
    39 --SQLSERVER数据库主要状态和切换路径 http://www.cnblogs.com/lyhabc/archive/2012/09/15/2687076.html
    40 2013-12-01 21:21:30.780 spid56       Restore-Redo begins on database pratice  --重做日志!!
    41 2013-12-01 21:21:30.790 spid56       RunOfflineRedo logIter.Init(): FirstLsn(PruId: 0): 0xc0f:0x27dd:0x25
    42 2013-12-01 21:21:30.790 spid56       RunOfflineRedo logIter.Init(): LastLsn(PruId: 0): 0xc0f:0x27ee:0x1
    43 2013-12-01 21:21:30.790 spid56       OfflineRollforward: StopLsn/LastLsn(PruId: 0): 0xc0f:0x27ee:0x1
    44 2013-12-01 21:21:30.790 spid56       Rollforward complete on database pratice --为什麽会有Rollforward http://www.cnblogs.com/lyhabc/p/3448449.html
    45 2013-12-01 21:21:30.810 spid56       Restore: Done with fixups  --checkdb检查完毕 fixup:修正
    46 2013-12-01 21:21:30.810 spid56       Restore: Transitioning database to ONLINE
    47 2013-12-01 21:21:30.810 spid56       Restore: Restarting database for ONLINE
    48 2013-12-01 21:21:30.820 spid56       Starting up database 'pratice'.
    49 2013-12-01 21:21:30.860 spid56       FixupLogTail(progress) zeroing D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice_log.ldf from 0x1efdc00 to 0x1efe000.                           --修正日志尾部
    50 2013-12-01 21:21:30.860 spid56       Zeroing D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice_log.ldf from page 3967 to 4447 (0x1efe000 to 0x22be000)
    51 2013-12-01 21:21:30.870 spid56       Zeroing completed on D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice_log.ldf
    52 2013-12-01 21:21:30.870 spid56       PostRestoreContainerFixups: fixups complete
    53 2013-12-01 21:21:30.870 spid56       CHECKDB for database 'pratice' finished without errors on 2013-11-23 23:35:18.670 (local time). This is an informational message only; no user action is required.
    54 2013-12-01 21:21:30.880 spid56       PostRestoreReplicationFixup for pratice starts  --复制相关
    55 2013-12-01 21:21:30.970 spid56       PostRestoreReplicationFixup for pratice complete
    56 2013-12-01 21:21:30.970 spid56       Restore: Database is restarted   --数据库已经重启
    57 2013-12-01 21:21:30.970 备份           Restore is complete on database 'pratice'.  The database is now available.  --数据库还原完成,数据库现在是可用状态
    58 2013-12-01 21:21:30.980 spid56       Resuming any halted fulltext crawls   --恢复全文搜索抓取
    59 2013-12-01 21:21:30.990 spid56       Restore: Writing history records    --还原数据库记录写入msdb里相关的表
    60 2013-12-01 21:21:30.990 备份           Database was restored: Database: pratice, creation date(time): 2013/11/19(19:35:23), first LSN: 3087:10205:37, last LSN: 3087:10222:1, number of dump devices: 1, device information: (FILE=1, TYPE=DISK: {'D:pratice_backup_201207160152.bak'}). Informational  
    61 2013-12-01 21:21:30.990 spid56       Writing backup history records    --备份历史记录写入到错误日志
    62 2013-12-01 21:21:31.010 spid56       Restore: Done with MSDB maintenance   
    63 2013-12-01 21:21:31.010 spid56       RestoreDatabase: Finished

    还有两个跟踪标志

    跟踪标志:3014、3604

    为了节省篇幅我就补贴出刚才两个跟踪标志的信息了,只贴出3014、3604这两个跟踪标志输出的信息

    1 dbcc traceon(3014, 3604, -1)

    完整备份

     1 2013-12-01 22:22:03.300 spid56       Calculating expected total data to write  --计算需要写入备份设备的数据量
     2 2013-12-01 22:22:03.300 spid56       Fid(1) ExpectedExt(3519) DiffMapAccurate(0)  --文件1 要备份的区 精确的diff位
     3 2013-12-01 22:22:03.300 spid56       Total (230621184)
     4 2013-12-01 22:22:03.300 spid56       Started file D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice.mdf
     5 2013-12-01 22:22:03.300 spid56       BackupStream(0): Starting MSDA of size 3520 extents  --备份流 要备份的区大小
     6 2013-12-01 22:22:05.010 spid56       BackupStream(0): Total MSDA: 3520 extents
     7 2013-12-01 22:22:05.010 spid56       Backup data streams: Initial=230621184 Final=230621184 ExcessMode=0
     8 2013-12-01 22:22:05.010 spid56       Calculating expected total data to write
     9 2013-12-01 22:22:05.010 spid56       Fid(1) ExpectedExt(3519) DiffMapAccurate(0)
    10 2013-12-01 22:22:05.010 spid56       Total (230621184)
    11 2013-12-01 22:22:05.010 spid56       BackupDatabase: Database files done
    12 2013-12-01 22:22:05.010 spid56       BackupLog: Family(0) StreamSize=0x10000
    13 2013-12-01 22:22:05.020 spid56       BackupLog: Family(0) StreamSize=0x0
    14 2013-12-01 22:22:05.020 spid56       BackupLog: Family(0) StreamSize=0x0
    15 2013-12-01 22:22:05.020 spid56       BackupLog: Family(0) StreamSize=0x0
    16 2013-12-01 22:22:05.020 spid56       BackupLog: Family(0) StreamSize=0x0
    17 2013-12-01 22:22:05.020 spid56       BackupLog: Family(0) StreamSize=0x0
    18 2013-12-01 22:22:05.020 spid56       BackupLog: Family(0) StreamSize=0x0
    19 2013-12-01 22:22:05.020 spid56       BackupLog: Family(0) StreamSize=0x0
    20 
    21 2013-12-01 22:22:05.040 spid56       BackupDatabase: Writing history records
    22 2013-12-01 22:22:05.040 备份           Database backed up. Database: pratice, creation date(time): 2013/11/19(19:35:23), pages dumped: 28171, first LSN: 3087:10237:43, last LSN: 3087:10256:1, number of dump devices: 1, device information: (FILE=1, TYPE=DISK: {'D:pratice_fullbackup_201207160152
    23 2013-12-01 22:22:05.040 spid56       Writing backup history records
    24 2013-12-01 22:22:05.070 spid56       BackupDatabase: Finished

    差异备份

    备份时候,查询窗口的输出

     1 BackupDatabase: Database pratice
     2 
     3 Backup: Media open
     4 
     5 Backup: Media ready to backup
     6 
     7 BackupDatabase: Checkpoint done
     8 
     9 Backup: Scanning allocation bitmaps
    10 
    11 Backup: Done with allocation bitmaps
    12 
    13 Calculating expected total data to write
    14 
    15 Fid(1) ExpectedExt(5) DiffMapAccurate(1)
    16 
    17 Total (327680)
    18 
    19 BackupDatabase: Work estimates done
    20 
    21 Backup: Leading metadata section done
    22 
    23 Calculating expected total data to write
    24 
    25 Fid(1) ExpectedExt(5) DiffMapAccurate(1)
    26 
    27 Total (327680)
    28 
    29 Backup:Copying data
    30 
    31 Backup: DBReaderCount = 1
    32 
    33 Backup data streams: Initial=327680 Final=327680 ExcessMode=0
    34 
    35 Calculating expected total data to write
    36 
    37 Fid(1) ExpectedExt(5) DiffMapAccurate(1)
    38 
    39 Total (327680)
    40 
    41 BackupDatabase: Database files done
    42 
    43 已为数据库 'pratice',文件 'pratice' (位于文件 1 上)处理了 40 页。
    44 BackupLog: Family(0) StreamSize=0x10000
    45 
    46 BackupLog: Family(0) StreamSize=0x0
    47 
    48 BackupLog: Family(0) StreamSize=0x0
    49 
    50 BackupLog: Family(0) StreamSize=0x0
    51 
    52 BackupLog: Family(0) StreamSize=0x0
    53 
    54 BackupLog: Family(0) StreamSize=0x0
    55 
    56 BackupLog: Family(0) StreamSize=0x0
    57 
    58 BackupLog: Family(0) StreamSize=0x0
    59 
    60 已为数据库 'pratice',文件 'pratice_log' (位于文件 1 上)处理了 1 页。
    61 慂正灵慄慴慢敳退慂正灵潌g邐%s : Log files done
    62  : Log files done
    63 
    64 Backup: Trailing config done
    65 
    66 Backup: MBC done
    67 
    68 BackupDatabase: Writing history records
    69 
    70 Writing backup history records
    71 
    72 BACKUP DATABASE WITH DIFFERENTIAL 成功处理了 41 页,花费 0.023 秒(13.926 MB/秒)。
    73 BackupDatabase: Finished

    错误日志输出

     1 
     2 2013-12-01 22:33:04.500 spid56       Calculating expected total data to write
     3 2013-12-01 22:33:04.500 spid56       Fid(1) ExpectedExt(5) DiffMapAccurate(1)
     4 2013-12-01 22:33:04.500 spid56       Total (327680)
     5 2013-12-01 22:33:04.510 spid56       BackupStream(0): Starting MSDA of size 16 extents
     6 2013-12-01 22:33:04.510 spid56       Started file D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice.mdf
     7 2013-12-01 22:33:04.510 spid56       Completed file D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice.mdf
     8 2013-12-01 22:33:04.510 spid56       Padding MSDA with 720896 bytes
     9 2013-12-01 22:33:04.510 spid56       BackupStream(0): Total MSDA: 16 extents
    10 2013-12-01 22:33:04.510 spid56       Backup data streams: Initial=327680 Final=327680 ExcessMode=0
    11 2013-12-01 22:33:04.510 spid56       Calculating expected total data to write
    12 2013-12-01 22:33:04.510 spid56       Fid(1) ExpectedExt(5) DiffMapAccurate(1)
    13 2013-12-01 22:33:04.510 spid56       Total (327680)
    14 2013-12-01 22:33:04.510 spid56       BackupDatabase: Database files done
    15 2013-12-01 22:33:04.510 spid56       BackupLog: Family(0) StreamSize=0x10000
    16 2013-12-01 22:33:04.510 spid56       BackupLog: Family(0) StreamSize=0x0
    17 2013-12-01 22:33:04.510 spid56       BackupLog: Family(0) StreamSize=0x0
    18 2013-12-01 22:33:04.510 spid56       BackupLog: Family(0) StreamSize=0x0
    19 2013-12-01 22:33:04.510 spid56       BackupLog: Family(0) StreamSize=0x0
    20 2013-12-01 22:33:04.510 spid56       BackupLog: Family(0) StreamSize=0x0
    21 2013-12-01 22:33:04.510 spid56       BackupLog: Family(0) StreamSize=0x0
    22 2013-12-01 22:33:04.510 spid56       BackupLog: Family(0) StreamSize=0x0
    23 
    24 2013-12-01 22:33:04.510 spid56       Backup: Trailing config done
    25 2013-12-01 22:33:04.510 spid56       Backup: MBC done
    26 2013-12-01 22:33:04.530 spid56       BackupDatabase: Writing history records
    27 2013-12-01 22:33:04.530 备份           Database differential changes were backed up. Database: pratice, creation date(time): 2013/11/19(19:35:23), pages dumped: 139, first LSN: 3087:10264:34, last LSN: 3087:10280:1, full backup LSN: 3087:10237:43, number of dump devices: 1, device information: 
    28 2013-12-01 22:33:04.530 spid56       Writing backup history records
    29 2013-12-01 22:33:04.540 spid56       BackupDatabase: Finished

    日志备份

    备份时候,查询窗口的输出

     1 BackupLog: database pratice
     2 
     3 BackupLog: SafeCheckpoint done
     4 
     5 Backup: Media open
     6 
     7 Backup: Media ready to backup
     8 
     9 BackupLog: Work estimate done
    10 
    11 Backup: Leading metadata section done
    12 
    13 BackupLog: Family(0) StreamSize=0x10000
    14 
    15 BackupLog: Family(0) StreamSize=0x0
    16 
    17 BackupLog: Family(0) StreamSize=0x0
    18 
    19 BackupLog: Family(0) StreamSize=0x0
    20 
    21 BackupLog: Family(0) StreamSize=0x0
    22 
    23 BackupLog: Family(0) StreamSize=0x0
    24 
    25 BackupLog: Family(0) StreamSize=0x0
    26 
    27 BackupLog: Family(0) StreamSize=0x0
    28 
    29 已为数据库 'pratice',文件 'pratice_log' (位于文件 1 上)处理了 4 页。
    30 慂正灵潌g邐%s : Log files done
    31  : Log files done
    32 
    33 Backup: Trailing config done
    34 
    35 Backup: MBC done
    36 
    37 BackupLog: Writing history records
    38 
    39 Writing backup history records
    40 
    41 BACKUP LOG 成功处理了 4 页,花费 0.011 秒(2.574 MB/秒)。
    42 BackupLog: Finished

    错误日志输出

     1 2013-12-01 22:35:59.010 spid56       BackupLog: Family(0) StreamSize=0x10000
     2 2013-12-01 22:35:59.010 spid56       BackupLog: Family(0) StreamSize=0x0
     3 2013-12-01 22:35:59.010 spid56       BackupLog: Family(0) StreamSize=0x0
     4 2013-12-01 22:35:59.010 spid56       BackupLog: Family(0) StreamSize=0x0
     5 2013-12-01 22:35:59.010 spid56       BackupLog: Family(0) StreamSize=0x0
     6 2013-12-01 22:35:59.010 spid56       BackupLog: Family(0) StreamSize=0x0
     7 2013-12-01 22:35:59.010 spid56       BackupLog: Family(0) StreamSize=0x0
     8 2013-12-01 22:35:59.010 spid56       BackupLog: Family(0) StreamSize=0x0
     9 2013-12-01 22:35:59.020 spid56       BackupLog: Writing history records
    10 2013-12-01 22:35:59.020 备份           Log was backed up. Database: pratice, creation date(time): 2013/11/19(19:35:23), first LSN: 3087:10222:1, last LSN: 3087:10280:1, number of dump devices: 1, device information: (FILE=1, TYPE=DISK: {'d:pratice_Log_20070908.bak'}). This is an informational 
    11 2013-12-01 22:35:59.020 spid56       Writing backup history records
    12 2013-12-01 22:35:59.040 spid56       BackupLog: Finished

    文件备份

    备份时候,查询窗口的输出

     1 BackupDatabase: Database pratice
     2 
     3 Backup: Media open
     4 
     5 Backup: Media ready to backup
     6 
     7 Backup: Clearing differential bitmaps
     8 
     9 Backup: Bitmaps cleared
    10 
    11 BackupDatabase: Checkpoint done
    12 
    13 Backup: Scanning allocation bitmaps
    14 
    15 Backup: Done with allocation bitmaps
    16 
    17 Calculating expected total data to write
    18 
    19 Fid(1) ExpectedExt(3519) DiffMapAccurate(0)
    20 
    21 Total (230621184)
    22 
    23 BackupDatabase: Work estimates done
    24 
    25 Backup: Leading metadata section done
    26 
    27 Calculating expected total data to write
    28 
    29 Fid(1) ExpectedExt(3519) DiffMapAccurate(0)
    30 
    31 Total (230621184)
    32 
    33 Backup:Copying data
    34 
    35 Backup: DBReaderCount = 1
    36 
    37 Backup data streams: Initial=230621184 Final=230621184 ExcessMode=0
    38 
    39 Calculating expected total data to write
    40 
    41 Fid(1) ExpectedExt(3519) DiffMapAccurate(0)
    42 
    43 Total (230621184)
    44 
    45 BackupDatabase: Database files done
    46 
    47 已为数据库 'pratice',文件 'pratice' (位于文件 1 上)处理了 28152 页。
    48 BackupLog: Family(0) StreamSize=0x10000
    49 
    50 BackupLog: Family(0) StreamSize=0x0
    51 
    52 BackupLog: Family(0) StreamSize=0x0
    53 
    54 BackupLog: Family(0) StreamSize=0x0
    55 
    56 BackupLog: Family(0) StreamSize=0x0
    57 
    58 BackupLog: Family(0) StreamSize=0x0
    59 
    60 BackupLog: Family(0) StreamSize=0x0
    61 
    62 BackupLog: Family(0) StreamSize=0x0
    63 
    64 已为数据库 'pratice',文件 'pratice_log' (位于文件 1 上)处理了 2 页。
    65 慂正灵慄慴慢敳退慂正灵潌g邐%s : Log files done
    66  : Log files done
    67 
    68 Backup: Trailing config done
    69 
    70 Backup: MBC done
    71 
    72 BackupDatabase: Writing history records
    73 
    74 Writing backup history records
    75 
    76 BACKUP DATABASE...FILE=<name> 成功处理了 28154 页,花费 1.601 秒(137.380 MB/秒)。
    77 BackupDatabase: Finished

    错误日志输出

     1 2013-12-01 22:37:54.430 spid56       Calculating expected total data to write
     2 2013-12-01 22:37:54.430 spid56       Fid(1) ExpectedExt(3519) DiffMapAccurate(0)
     3 2013-12-01 22:37:54.430 spid56       Total (230621184)
     4 2013-12-01 22:37:54.430 spid56       Calculating expected total data to write
     5 2013-12-01 22:37:54.430 spid56       Fid(1) ExpectedExt(3519) DiffMapAccurate(0)
     6 2013-12-01 22:37:54.430 spid56       Total (230621184)
     7 2013-12-01 22:37:54.430 spid56       Backup:Copying data
     8 2013-12-01 22:37:54.440 spid56       Backup: DBReaderCount = 1
     9 2013-12-01 22:37:54.440 spid56       BackupStream(0): Starting MSDA of size 3520 extents
    10 2013-12-01 22:37:56.020 spid56       Completed file D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice.mdf
    11 2013-12-01 22:37:56.030 spid56       Padding MSDA with 65536 bytes
    12 2013-12-01 22:37:56.030 spid56       BackupStream(0): Total MSDA: 3520 extents
    13 2013-12-01 22:37:56.030 spid56       Backup data streams: Initial=230621184 Final=230621184 ExcessMode=0
    14 2013-12-01 22:37:56.030 spid56       Calculating expected total data to write
    15 2013-12-01 22:37:56.030 spid56       Fid(1) ExpectedExt(3519) DiffMapAccurate(0)
    16 2013-12-01 22:37:56.030 spid56       Total (230621184)
    17 2013-12-01 22:37:56.030 spid56       BackupDatabase: Database files done
    18 2013-12-01 22:37:56.030 spid56       BackupLog: Family(0) StreamSize=0x10000
    19 2013-12-01 22:37:56.030 spid56       BackupLog: Family(0) StreamSize=0x0
    20 2013-12-01 22:37:56.030 spid56       BackupLog: Family(0) StreamSize=0x0
    21 2013-12-01 22:37:56.030 spid56       BackupLog: Family(0) StreamSize=0x0
    22 2013-12-01 22:37:56.030 spid56       BackupLog: Family(0) StreamSize=0x0
    23 2013-12-01 22:37:56.030 spid56       BackupLog: Family(0) StreamSize=0x0
    24 2013-12-01 22:37:56.030 spid56       BackupLog: Family(0) StreamSize=0x0
    25 2013-12-01 22:37:56.030 spid56       BackupLog: Family(0) StreamSize=0x0
    26 2013-12-01 22:37:56.030 spid56       BackupDatabase: Writing history records
    27 2013-12-01 22:37:56.030 备份           Database file was backed up. Database: pratice, creation date(time): 2013/11/19(19:35:23), file list: (pratice(D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice.mdf)), pages dumped: 28171, number of dump devices: 1, device informatio
    28 2013-12-01 22:37:56.050 spid56       Writing backup history records
    29 2013-12-01 22:37:56.080 spid56       BackupDatabase: Finished

    文件组备份

    备份时候,查询窗口的输出

     1 BackupDatabase: Database pratice
     2 
     3 Backup: Media open
     4 
     5 Backup: Media ready to backup
     6 
     7 Backup: Clearing differential bitmaps
     8 
     9 Backup: Bitmaps cleared
    10 
    11 BackupDatabase: Checkpoint done
    12 
    13 Backup: Scanning allocation bitmaps
    14 
    15 Backup: Done with allocation bitmaps
    16 
    17 Calculating expected total data to write
    18 
    19 Fid(1) ExpectedExt(3519) DiffMapAccurate(0)
    20 
    21 Total (230621184)
    22 
    23 BackupDatabase: Work estimates done
    24 
    25 Backup: Leading metadata section done
    26 
    27 Calculating expected total data to write
    28 
    29 Fid(1) ExpectedExt(3519) DiffMapAccurate(0)
    30 
    31 Total (230621184)
    32 
    33 Backup:Copying data
    34 
    35 Backup: DBReaderCount = 1
    36 
    37 Backup data streams: Initial=230621184 Final=230621184 ExcessMode=0
    38 
    39 Calculating expected total data to write
    40 
    41 Fid(1) ExpectedExt(3519) DiffMapAccurate(0)
    42 
    43 Total (230621184)
    44 
    45 BackupDatabase: Database files done
    46 
    47 已为数据库 'pratice',文件 'pratice' (位于文件 1 上)处理了 28152 页。
    48 BackupLog: Family(0) StreamSize=0x10000
    49 
    50 BackupLog: Family(0) StreamSize=0x0
    51 
    52 BackupLog: Family(0) StreamSize=0x0
    53 
    54 BackupLog: Family(0) StreamSize=0x0
    55 
    56 BackupLog: Family(0) StreamSize=0x0
    57 
    58 BackupLog: Family(0) StreamSize=0x0
    59 
    60 BackupLog: Family(0) StreamSize=0x0
    61 
    62 BackupLog: Family(0) StreamSize=0x0
    63 
    64 已为数据库 'pratice',文件 'pratice_log' (位于文件 1 上)处理了 2 页。
    65 慂正灵慄慴慢敳退慂正灵潌g邐%s : Log files done
    66  : Log files done
    67 
    68 Backup: Trailing config done
    69 
    70 Backup: MBC done
    71 
    72 BackupDatabase: Writing history records
    73 
    74 Writing backup history records
    75 
    76 BACKUP DATABASE...FILE=<name> 成功处理了 28154 页,花费 1.676 秒(131.232 MB/秒)。
    77 BackupDatabase: Finished

    错误日志输出

     1 2013-12-01 22:40:04.260 spid56       Calculating expected total data to write
     2 2013-12-01 22:40:04.260 spid56       Fid(1) ExpectedExt(3519) DiffMapAccurate(0)
     3 2013-12-01 22:40:04.260 spid56       Total (230621184)
     4 2013-12-01 22:40:04.260 spid56       Calculating expected total data to write
     5 2013-12-01 22:40:04.260 spid56       Fid(1) ExpectedExt(3519) DiffMapAccurate(0)
     6 2013-12-01 22:40:04.260 spid56       Total (230621184)
     7 2013-12-01 22:40:04.260 spid56       Backup:Copying data
     8 2013-12-01 22:40:04.270 spid56       Backup: DBReaderCount = 1
     9 2013-12-01 22:40:04.270 spid56       Started file D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice.mdf
    10 2013-12-01 22:40:04.270 spid56       BackupStream(0): Starting MSDA of size 3520 extents
    11 2013-12-01 22:40:05.920 spid56       Completed file D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice.mdf
    12 2013-12-01 22:40:05.930 spid56       Padding MSDA with 65536 bytes
    13 2013-12-01 22:40:05.930 spid56       BackupStream(0): Total MSDA: 3520 extents
    14 2013-12-01 22:40:05.930 spid56       Backup data streams: Initial=230621184 Final=230621184 ExcessMode=0
    15 2013-12-01 22:40:05.930 spid56       Calculating expected total data to write
    16 2013-12-01 22:40:05.930 spid56       Fid(1) ExpectedExt(3519) DiffMapAccurate(0)
    17 2013-12-01 22:40:05.930 spid56       Total (230621184)
    18 2013-12-01 22:40:05.930 spid56       BackupDatabase: Database files done
    19 2013-12-01 22:40:05.930 spid56       BackupLog: Family(0) StreamSize=0x10000
    20 2013-12-01 22:40:05.930 spid56       BackupLog: Family(0) StreamSize=0x0
    21 2013-12-01 22:40:05.930 spid56       BackupLog: Family(0) StreamSize=0x0
    22 2013-12-01 22:40:05.930 spid56       BackupLog: Family(0) StreamSize=0x0
    23 2013-12-01 22:40:05.930 spid56       BackupLog: Family(0) StreamSize=0x0
    24 2013-12-01 22:40:05.930 spid56       BackupLog: Family(0) StreamSize=0x0
    25 2013-12-01 22:40:05.930 spid56       BackupLog: Family(0) StreamSize=0x0
    26 2013-12-01 22:40:05.930 spid56       BackupLog: Family(0) StreamSize=0x0
    27 2013-12-01 22:40:05.930 spid56       Backup: Trailing config done
    28 2013-12-01 22:40:05.930 spid56       Backup: MBC done
    29 2013-12-01 22:40:05.940 spid56       BackupDatabase: Writing history records
    30 2013-12-01 22:40:05.940 备份           Database file was backed up. Database: pratice, creation date(time): 2013/11/19(19:35:23), file list: (pratice(D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice.mdf)), pages dumped: 28171, number of dump devices: 1, device informatio
    31 2013-12-01 22:40:05.940 spid56       Writing backup history records
    32 2013-12-01 22:40:05.960 spid56       BackupDatabase: Finished

    数据库还原

    还原的时候,查询窗口的输出

     1 Restore: Planning complete
     2 
     3 Restore: BeginRestore (offline) on pratice
     4 
     5 Restore: PreparingContainers
     6 
     7 Restore: Containers are ready
     8 
     9 Restore: Restoring backup set
    10 
    11 Restore: Transferring data to pratice
    12 
    13 FileHandleCache: 0 files opened. CacheSize: 12
    14 
    15 Restore: Data transfer complete on pratice
    16 
    17 已为数据库 'pratice',文件 'pratice' (位于文件 1 上)处理了 28152 页。
    18 已为数据库 'pratice',文件 'pratice_log' (位于文件 1 上)处理了 2 页。
    19 Restore: Backup set restored
    20 
    21 Restore-Redo begins on database pratice
    22 
    23 RunOfflineRedo logIter.Init(): FirstLsn(PruId: 0): 0xc0f:0x27fd:0x2b
    24 
    25 RunOfflineRedo logIter.Init(): LastLsn(PruId: 0): 0xc0f:0x2810:0x1
    26 
    27 OfflineRollforward: StopLsn/LastLsn(PruId: 0): 0xc0f:0x2810:0x1
    28 
    29 Rollforward complete on database pratice
    30 
    31 Restore: Done with fixups
    32 
    33 Restore: Transitioning database to ONLINE
    34 
    35 Restore: Restarting database for ONLINE
    36 
    37 Restore: Database is restarted
    38 
    39 Resuming any halted fulltext crawls
    40 
    41 Restore: Writing history records
    42 
    43 Writing backup history records
    44 
    45 Restore: Done with MSDB maintenance
    46 
    47 RESTORE DATABASE 成功处理了 28154 页,花费 2.317 秒(94.927 MB/秒)。
    48 RestoreDatabase: Finished

    错误日志输出

     1 2013-12-01 22:42:32.430 spid56       Restore: PreparingContainers
     2 2013-12-01 22:42:32.460 spid56       Restore: Containers are ready
     3 2013-12-01 22:42:32.460 spid56       Zeroing D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice_log.ldf from page 1 to 6528 (0x2000 to 0x3300000)
     4 2013-12-01 22:42:32.500 spid56       Restore: Restoring backup set
     5 2013-12-01 22:42:32.500 spid56       Restore: Transferring data to pratice
     6 2013-12-01 22:42:32.530 spid56       Starting MSDA in stream 0, thread 5164, length 0xdc00000
     7 2013-12-01 22:42:32.620 spid56       Zeroing completed on D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice_log.ldf
     8 2013-12-01 22:42:34.790 spid56       Completed MSDA in stream 0, thread 5164
     9 2013-12-01 22:42:34.790 spid56       Restore: Waiting for log zero on pratice
    10 2013-12-01 22:42:34.800 spid56       Restore: LogZero complete
    11 2013-12-01 22:42:34.800 spid56       SetTargetRestoreAge: 0
    12 2013-12-01 22:42:34.820 spid56       FileHandleCache: 0 files opened. CacheSize: 12
    13 2013-12-01 22:42:34.820 spid56       Restore: Data transfer complete on pratice
    14 2013-12-01 22:42:34.830 spid56       Restore: Backup set restored
    15 2013-12-01 22:42:34.840 spid56       Starting up database 'pratice'.
    16 2013-12-01 22:42:34.890 spid56       The database 'pratice' is marked RESTORING and is in a state that does not allow recovery to be run.
    17 2013-12-01 22:42:34.900 spid56       Restore-Redo begins on database pratice
    18 2013-12-01 22:42:34.900 spid56       RunOfflineRedo logIter.Init(): FirstLsn(PruId: 0): 0xc0f:0x27fd:0x2b
    19 2013-12-01 22:42:34.900 spid56       RunOfflineRedo logIter.Init(): LastLsn(PruId: 0): 0xc0f:0x2810:0x1
    20 2013-12-01 22:42:34.900 spid56       OfflineRollforward: StopLsn/LastLsn(PruId: 0): 0xc0f:0x2810:0x1
    21 2013-12-01 22:42:34.900 spid56       Rollforward complete on database pratice
    22 2013-12-01 22:42:34.920 spid56       Restore: Done with fixups
    23 2013-12-01 22:42:34.920 spid56       Restore: Transitioning database to ONLINE
    24 2013-12-01 22:42:34.920 spid56       Restore: Restarting database for ONLINE
    25 2013-12-01 22:42:34.940 spid56       Starting up database 'pratice'.
    26 2013-12-01 22:42:34.980 spid56       Zeroing D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice_log.ldf from page 3969 to 4449 (0x1f02000 to 0x22c2000)
    27 2013-12-01 22:42:34.980 spid56       Zeroing completed on D:Program FilesMicrosoft SQL ServerMSSQL11.SQL2012MSSQLDATApratice_log.ldf
    28 2013-12-01 22:42:35.000 spid56       PostRestoreContainerFixups: fixups complete
    29 2013-12-01 22:42:35.000 spid56       CHECKDB for database 'pratice' finished without errors on 2013-11-23 23:35:18.670 (local time). This is an informational message only; no user action is required.
    30 2013-12-01 22:42:35.000 spid56       PostRestoreReplicationFixup for pratice starts
    31 2013-12-01 22:42:35.120 spid56       PostRestoreReplicationFixup for pratice complete
    32 2013-12-01 22:42:35.120 spid56       Restore: Database is restarted
    33 2013-12-01 22:42:35.120 备份           Restore is complete on database 'pratice'.  The database is now available.
    34 2013-12-01 22:42:35.130 spid56       Resuming any halted fulltext crawls
    35 2013-12-01 22:42:35.130 spid56       Restore: Writing history records
    36 2013-12-01 22:42:35.130 备份           Database was restored: Database: pratice, creation date(time): 2013/11/19(19:35:23), first LSN: 3087:10237:43, last LSN: 3087:10256:1, number of dump devices: 1, device information: (FILE=1, TYPE=DISK: {'D:pratice_fullbackup_201207160152.bak'}). Informati
    37 2013-12-01 22:42:35.130 spid56       Writing backup history records
    38 2013-12-01 22:42:35.160 spid56       Restore: Done with MSDB maintenance
    39 2013-12-01 22:42:35.160 spid56       RestoreDatabase: Finished


    还原时候输出的日志好像跟刚才两个跟踪标志输出的日志没有什么差别


    跟踪标志3213查看Transfer Size

    Transfer Size即是数据传输大小,备份的时候从mdf文件的数据传输到bak备份文件的传输单位大小

    1 DBCC traceon(3605, 3004, 3014, 3213, -1)

    这几个跟踪标志要一起打开,不能只打开3213,不然显示不出信息的

    备份

    1 --完整备份
    2 BACKUP DATABASE [pratice]
    3 TO DISK='D:pratice_fullbackup_201207160152.bak'

    错误日志输出

     1 2013-12-01 22:57:32.810 spid56       Backup/Restore buffer configuration parameters
     2 2013-12-01 22:57:32.810 spid56       Memory limit: 188MB
     3 2013-12-01 22:57:32.810 spid56       BufferCount:                7
     4 2013-12-01 22:57:32.810 spid56       Sets Of Buffers:            1
     5 2013-12-01 22:57:32.810 spid56       MaxTransferSize:            1024 KB
     6 2013-12-01 22:57:32.810 spid56       Min MaxTransferSize:        64 KB
     7 2013-12-01 22:57:32.810 spid56       Total buffer space:         7 MB
     8 2013-12-01 22:57:32.810 spid56       Tabular data device count:  1
     9 2013-12-01 22:57:32.810 spid56       Fulltext data device count: 0
    10 2013-12-01 22:57:32.810 spid56       Filestream device count:    0
    11 2013-12-01 22:57:32.810 spid56       TXF device count:           0
    12 2013-12-01 22:57:32.810 spid56       Filesystem i/o alignment:   512
    13 2013-12-01 22:57:32.810 spid56       Media Buffer count:            7
    14 2013-12-01 22:57:32.810 spid56       Media Buffer size:          1024KB

    还原

     1 --执行下面脚本先kill掉所有连接到pratice数据库的连接
     2 USE master
     3 GO
     4 DECLARE @spid INT
     5 DECLARE @count INT
     6 WHILE @count > 0
     7     BEGIN
     8         SELECT  @count = COUNT(*)
     9         FROM    sys.[sysprocesses]
    10         WHERE   [dbid] = DB_ID('pratice')
    11         SELECT  @spid = [spid]
    12         FROM    sys.[sysprocesses]
    13         WHERE   [dbid] = DB_ID('pratice')
    14         EXEC('kill '+@spid)
    15     END
    16 
    17 --完整备份还原
    18 RESTORE DATABASE [pratice]
    19 FROM DISK ='D:pratice_fullbackup_201207160152.bak' WITH REPLACE

     错误日志输出

     1 2013-12-01 23:07:29.890 spid57       Backup/Restore buffer configuration parameters
     2 2013-12-01 23:07:29.890 spid57       Memory limit: 188MB
     3 2013-12-01 23:07:29.890 spid57       BufferCount:                6
     4 2013-12-01 23:07:29.890 spid57       Sets Of Buffers:            1
     5 2013-12-01 23:07:29.890 spid57       MaxTransferSize:            1024 KB
     6 2013-12-01 23:07:29.890 spid57       Min MaxTransferSize:        64 KB
     7 2013-12-01 23:07:29.890 spid57       Total buffer space:         6 MB
     8 2013-12-01 23:07:29.890 spid57       Tabular data device count:  1
     9 2013-12-01 23:07:29.890 spid57       Fulltext data device count: 0
    10 2013-12-01 23:07:29.890 spid57       Filestream device count:    0
    11 2013-12-01 23:07:29.890 spid57       TXF device count:           0
    12 2013-12-01 23:07:29.890 spid57       Filesystem i/o alignment:   512
    13 2013-12-01 23:07:29.890 spid57       Media Buffer count:            6
    14 2013-12-01 23:07:29.890 spid57       Media Buffer size:          1024KB

    参考文章:SQL Server Backup/Restore具体做什么

    如有不对的地方,欢迎大家拍砖o(∩_∩)o

    ----------------------------------------------------------------------------------------

    2013-12-2晚更正和补充:

    这里谢谢QQ群里的高大侠

    在完整备份的错误日志解释里面有一句话解释错了

    2013-12-01 19:17:50.330 spid56       BackupDatabase: Checkpoint done   --做checkpoint,将已提交事务的数据写入磁盘,未提交事务的继续留在内存

    应该改为

    2013-12-01 19:17:50.330 spid56       BackupDatabase: Checkpoint done   --做checkpoint,将所有修改的数据都被写入磁盘

    为什麽这样改??

    大家可以参考一下宋大师写的文章:

    SQL Server CheckPoint的几个误区

    再谈SQL Server中日志的的作用

     ----------------------------------------------------------------------------------------------------

    在文章开头的那篇文章:还原/备份时做了些什么 说到了

    SQL Server的备份和还原是如何选择Transfer Size的

    一个客户问道:为什么Transfer Size在备份时设置为1MB,还原时为64KB,除非我修改BUFFERCOUNT 和MAXTRANSFERSIZE?

    我们指定MAXTRANSFERSIZE为最大的数值和不指定的情况下看一下备份和还原所需要的时间和输出的日志

    备份和还原时候所消耗内存我就不测试了,我这里仅仅测试time

    至于MAXTRANSFERSIZE的最大值是多少可以看一下下面的《SQL SERVER BACKUP DATABASE 加快备份速度方法》

    备份比较

    指定的情况下:

    1 --完整备份
    2 SET STATISTICS TIME ON
    3 BACKUP DATABASE [pratice]
    4 TO DISK='D:pratice_fullbackup_201207160152.bak'  
    5 WITH BUFFERCOUNT = 50, MAXTRANSFERSIZE = 4194304
    6 SET STATISTICS TIME OFF
    1 已为数据库 'pratice',文件 'pratice' (位于文件 1 上)处理了 28152 页。
    2 已为数据库 'pratice',文件 'pratice_log' (位于文件 1 上)处理了 2 页。
    3 BACKUP DATABASE 成功处理了 28154 页,花费 1.377 秒(159.728 MB/秒)。
    4 
    5  SQL Server 执行时间:
    6    CPU 时间 = 63 毫秒,占用时间 = 1437 毫秒。
    7 
    8  SQL Server 执行时间:
    9    CPU 时间 = 0 毫秒,占用时间 = 0 毫秒。
     1 2013-12-02 20:16:57.700 spid58       Memory limit: 188MB
     2 2013-12-02 20:16:57.700 spid58       BufferCount:                50
     3 2013-12-02 20:16:57.700 spid58       Sets Of Buffers:            1
     4 2013-12-02 20:16:57.700 spid58       MaxTransferSize:            4096 KB
     5 2013-12-02 20:16:57.700 spid58       Min MaxTransferSize:        64 KB
     6 2013-12-02 20:16:57.700 spid58       Total buffer space:         200 MB
     7 2013-12-02 20:16:57.700 spid58       Tabular data device count:  1
     8 2013-12-02 20:16:57.700 spid58       Fulltext data device count: 0
     9 2013-12-02 20:16:57.700 spid58       Filestream device count:    0
    10 2013-12-02 20:16:57.700 spid58       TXF device count:           0
    11 2013-12-02 20:16:57.700 spid58       Filesystem i/o alignment:   512
    12 2013-12-02 20:16:57.700 spid58       Media Buffer count:           50
    13 2013-12-02 20:16:57.700 spid58       Media Buffer size:          4096KB

    MaxTransferSize:            4096 KB=4MB

    BufferCount:                50

    不指定的情况下:

    1 --完整备份
    2 SET STATISTICS TIME ON
    3 BACKUP DATABASE [pratice]
    4 TO DISK='D:pratice_fullbackup_201207160152.bak'  
    5 SET STATISTICS TIME OFF
    1 已为数据库 'pratice',文件 'pratice' (位于文件 1 上)处理了 28152 页。
    2 已为数据库 'pratice',文件 'pratice_log' (位于文件 1 上)处理了 2 页。
    3 BACKUP DATABASE 成功处理了 28154 页,花费 1.685 秒(130.531 MB/秒)。
    4 
    5  SQL Server 执行时间:
    6    CPU 时间 = 77 毫秒,占用时间 = 1742 毫秒。
    7 
    8  SQL Server 执行时间:
    9    CPU 时间 = 0 毫秒,占用时间 = 0 毫秒。
     1 2013-12-02 20:21:22.090 spid58       Memory limit: 188MB
     2 2013-12-02 20:21:22.090 spid58       BufferCount:                7
     3 2013-12-02 20:21:22.090 spid58       Sets Of Buffers:            1
     4 2013-12-02 20:21:22.090 spid58       MaxTransferSize:            1024 KB
     5 2013-12-02 20:21:22.090 spid58       Min MaxTransferSize:        64 KB
     6 2013-12-02 20:21:22.090 spid58       Total buffer space:         7 MB
     7 2013-12-02 20:21:22.090 spid58       Tabular data device count:  1
     8 2013-12-02 20:21:22.090 spid58       Fulltext data device count: 0
     9 2013-12-02 20:21:22.090 spid58       Filestream device count:    0
    10 2013-12-02 20:21:22.090 spid58       TXF device count:           0
    11 2013-12-02 20:21:22.090 spid58       Filesystem i/o alignment:   512
    12 2013-12-02 20:21:22.090 spid58       Media Buffer count:            7
    13 2013-12-02 20:21:22.090 spid58       Media Buffer size:          1024KB

    MaxTransferSize:            1024 KB=1MB

    BufferCount:                7

    默认的时候MaxTransferSize确实是1MB大小:为什么Transfer Size在备份时设置为1MB,还原时为64KB,除非我修改BUFFERCOUNT 和MAXTRANSFERSIZE?

    所用时间比较:

     

    还原比较

    指定的情况下:

    1 --完整备份还原
    2 SET STATISTICS TIME ON
    3 RESTORE DATABASE [pratice]
    4 FROM DISK ='D:pratice_fullbackup_201207160152.bak' 
    5 WITH REPLACE,BUFFERCOUNT = 50, MAXTRANSFERSIZE = 4194304
    6 SET STATISTICS TIME OFF
    1 已为数据库 'pratice',文件 'pratice' (位于文件 1 上)处理了 28152 页。
    2 已为数据库 'pratice',文件 'pratice_log' (位于文件 1 上)处理了 2 页。
    3 RESTORE DATABASE 成功处理了 28154 页,花费 1.691 秒(130.068 MB/秒)。
    4 
    5  SQL Server 执行时间:
    6    CPU 时间 = 140 毫秒,占用时间 = 2118 毫秒。
     1 2013-12-02 20:39:52.740 spid58       Memory limit: 188MB
     2 2013-12-02 20:39:52.740 spid58       BufferCount:                50
     3 2013-12-02 20:39:52.740 spid58       Sets Of Buffers:            1
     4 2013-12-02 20:39:52.740 spid58       MaxTransferSize:            4096 KB
     5 2013-12-02 20:39:52.740 spid58       Min MaxTransferSize:        64 KB
     6 2013-12-02 20:39:52.740 spid58       Total buffer space:         200 MB
     7 2013-12-02 20:39:52.740 spid58       Tabular data device count:  1
     8 2013-12-02 20:39:52.740 spid58       Fulltext data device count: 0
     9 2013-12-02 20:39:52.740 spid58       Filestream device count:    0
    10 2013-12-02 20:39:52.740 spid58       TXF device count:           0
    11 2013-12-02 20:39:52.740 spid58       Filesystem i/o alignment:   512
    12 2013-12-02 20:39:52.740 spid58       Media Buffer count:           50
    13 2013-12-02 20:39:52.740 spid58       Media Buffer size:          4096KB

    不指定的情况下:

    1 --完整备份还原
    2 SET STATISTICS TIME ON
    3 RESTORE DATABASE [pratice]
    4 FROM DISK ='D:pratice_fullbackup_201207160152.bak' 
    5 WITH REPLACE
    6 SET STATISTICS TIME OFF
    1 已为数据库 'pratice',文件 'pratice' (位于文件 1 上)处理了 28152 页。
    2 已为数据库 'pratice',文件 'pratice_log' (位于文件 1 上)处理了 2 页。
    3 RESTORE DATABASE 成功处理了 28154 页,花费 2.240 秒(98.190 MB/秒)。
    4 
    5  SQL Server 执行时间:
    6    CPU 时间 = 94 毫秒,占用时间 = 2636 毫秒。
     1 2013-12-02 20:41:51.890 spid58       Memory limit: 188MB
     2 2013-12-02 20:41:51.890 spid58       BufferCount:                6
     3 2013-12-02 20:41:51.890 spid58       Sets Of Buffers:            1
     4 2013-12-02 20:41:51.890 spid58       MaxTransferSize:            1024 KB
     5 2013-12-02 20:41:51.890 spid58       Min MaxTransferSize:        64 KB
     6 2013-12-02 20:41:51.890 spid58       Total buffer space:         6 MB
     7 2013-12-02 20:41:51.890 spid58       Tabular data device count:  1
     8 2013-12-02 20:41:51.890 spid58       Fulltext data device count: 0
     9 2013-12-02 20:41:51.890 spid58       Filestream device count:    0
    10 2013-12-02 20:41:51.890 spid58       TXF device count:           0
    11 2013-12-02 20:41:51.890 spid58       Filesystem i/o alignment:   512
    12 2013-12-02 20:41:51.890 spid58       Media Buffer count:            6
    13 2013-12-02 20:41:51.890 spid58       Media Buffer size:          1024KB

    MaxTransferSize:            1024 KB=1MB

    BufferCount:                6

    还原时为64KB,但是从错误日志里只看出了Min TransferSize为64KB

    不过从下图可以看到还原时候buffer count比备份时候少了1

    时间比较

    可以看出无论是备份还是还原,指定MaxTransferSize比不指定MaxTransferSize都要快

    是不是指定MAXTRANSFERSIZE = 4194304就是最好的?

    还原/备份时做了些什么 文章中给了一些建议

    不同的设备类型有其自己的GetSuggestedIoSize实现方式.

    硬盘

    读/写操作有不同的默认值

    • 如果设备处于读状态(还原),或者这是个Desktop或者Express版本,使用64K
    • 如果设备处于写状态(备份),而且既不是Desktop也不是Express版本,使用1MB。(更大的写操作容量将降低文件的拓展性,而且不利于NTFS的元数据的维护性)

    磁带 

    备份或者还原都是用64K除非磁带介质上的Block Size设置为其他的默认值。

    VDI

    备份或者还原都是用64K。

    BUFFERCOUNT没有被设置时,每种设备类型有自己的实现方式。.

    每个设备都暴露一个GetSuggestedIoDepth成员来在BUFFERCOUNT未被设置时来决定默认值。

    硬盘

    深度默认为3

    磁带

    深度默认为1

    VDI

    默认为1,最大为4,基于设备的跨度需求。

    推荐值会做相应修改。

    备份数据库

    bufferCount += backupDeviceCount

    bufferCount += 2 * databaseDeviceCount

    还原数据库或者还原文件

    bufferCount += 2 * databaseDeviceCount

    备份日志或者还原日志

    bufferCount += 2 * backupDeviceCount

    当目标确立后,他们会调整Transfer Size和Block Counts来确定每个Steam都会在适当的内存分配下有缓存来进行工作。

    最大可使用容量(缓存池的物理内存 / 16)。参见GlobalMemoryStatusEx (ullTotalPhys )。这是这台机器上所有的物理内存。所以如果你为一个64GM的机器开启/PAE,而SQL Server的实例没有使用AWE,有可能更多的物理内存将会试图允许更大的备份只是因为/PAE被开启。这个问题你依然在缓存池之外的内存中,它将会限制或者使备份的尝试在大的MAXTRANSFERSIXE和大BUFFERCOUNT下失败。

    如果计算超出了内存的1/16,容量将会被调整到一个合理的缓存和Transfer Size

     我做了一些测试,默认值在不同的配置文件下被合理的设置以满足备份和还原在性能上的需要。你可以调整这些参数来符合你对特殊系统的性能需要。

    -------------------------------------------------------------------------------------------------------

    SQL SERVER BACKUP DATABASE 加快备份速度方法

    最近在研究了BACKUP DATABASE 参数后,发现可以通过设置一下参数,加快备份速度:

    1.备份的时候,设置多个备份集,比如 TO DISK = N'd:/1.bak',DISK = N'd:/2.bak',DISK = N'd:/3.bak',DISK = N'd:/4.bak'

    2.使用BUFFERCOUNT 和MAXTRANSFERSIZE 选项。

    BUFFERCOUNT  :指定用于备份操作的 I/O 缓冲区总数。可以指定任何正整数; 但是,较大的缓冲区数可能导致由于 Sqlservr.exe 进程中的虚拟地址空间不足而发生“内存不足”错误。 缓冲区使用的总计空间由下面公式确定:buffercount*maxtransfersize。

    MAXTRANSFERSIZE  :指定要在 SQL Server 和备份介质之间使用的最大传输单元(字节)。 可能的值是 65536 字节 (64 KB) 的倍数,最多可到 4194304 字节 (4 MB)。

    3.启用备份压缩选项(COMPRESSION)

    该选项只在SQL Server 2008 Enterprise版本和SQL Server 2008 R2 Standard 以及所有更高版本都支持。

    注意:压缩选项会需要额外的CPU资源,因此建议不要在系统繁忙时候使用。

    4.作为DBA,你可能需要保证数据的安全,一般会加上校验和参数(CHECKSUM),保证数据安全。

    1 --完整备份
    2 BACKUP DATABASE [pratice]
    3 TO DISK='D:pratice_fullbackup_201207160152.bak'
    4 WITH CHECKSUM ,COMPRESSION
    1 --还原的时候要指定CHECKSUM选项才可以检查校验和
    2 RESTORE DATABASE pratice FROM DISK='C:pratice_fullbackup_201207160152.bak' 
    3 WITH REPLACE ,CHECKSUM, RECOVERY
    4 GO

    在备份和还原期间可能的介质错误 (SQL Server)

    备份校验和

    SQL Server 支持三种校验和:页校验和、日志块校验和以及备份校验和。

    日志块

    生成备份校验和时,BACKUP 将验证从数据库读取的数据是否与数据库中存在的任意校验和或页残缺指示一致。

    向备份介质写入页之前,备份操作将验证页级信息(页校验和或页残缺检测)是否存在。

    如果两者都不存在,则备份无法验证页。 将按原样包含未经验证的页,并且其内容将添加到总备份校验和中。


    如果备份操作在验证过程中遇到页错误,备份将失败

    备份集标记为包含备份校验和(在 msdb..backupsethas_backup_checksums 列中)

    将备份介质中的备份集标记为包含错误,并跟踪 msdb 数据库的 suspect_pages 表中的页

    默认情况下,在遇到页校验和错误后,BACKUP 或 RESTORE 操作将失败,而 RESTORE VERIFYONLY 操作将继续。

    但是,您可以控制某一给定操作在遇到错误时是失败还是尽可能继续。

    ---------------------------------------------------------------------------------------------------

    SQLSERVER备份语句的详细语法以及各个with选项的详细解释

    http://msdn.microsoft.com/zh-cn/library/ms186865.aspx

     1 BACKUP LOG { database_name | @database_name_var } 
     2   TO <backup_device> [ ,...n ] 
     3   [ <MIRROR TO clause> ] [ next-mirror-to ]
     4   [ WITH { <general_WITH_options> | <log-specific_optionspec> } [ ,...n ] ]
     5 [;]
     6 
     7 <backup_device>::= 
     8  {
     9    { logical_device_name | @logical_device_name_var } 
    10  | { DISK | TAPE | URL} = 
    11      { 'physical_device_name' | @physical_device_name_var }
    12  } 
    13 Note: URL is the format used to specify the location and the file name for the Windows Azure Blob. Although Windows Azure storage is a service, the implementation is similar to disk and tape to allow for a consistent and seemless backup experince for all the three devices. This option requires WITH CREDENTIAL argument. 
    14 
    15 <MIRROR TO clause>::=
    16  MIRROR TO <backup_device> [ ,...n ]
    17 
    18 <file_or_filegroup>::=
    19  {
    20    FILE = { logical_file_name | @logical_file_name_var } 
    21  | FILEGROUP = { logical_filegroup_name | @logical_filegroup_name_var }
    22  } 
    23 
    24 <read_only_filegroup>::=
    25 FILEGROUP = { logical_filegroup_name | @logical_filegroup_name_var }
    26 
    27 <general_WITH_options> [ ,...n ]::=  
    28 --Backup Set Options
    29    COPY_ONLY 
    30  | { COMPRESSION | NO_COMPRESSION } 
    31  | DESCRIPTION = { 'text' | @text_variable } 
    32  | NAME = { backup_set_name | @backup_set_name_var } 
    33  | { EXPIREDATE = { 'date' | @date_var } 
    34         | RETAINDAYS = { days | @days_var } } 
    35 
    36 --Media Set Options
    37    { NOINIT | INIT } 
    38  | { NOSKIP | SKIP } 
    39  | { NOFORMAT | FORMAT } 
    40  | MEDIADESCRIPTION = { 'text' | @text_variable } 
    41  | MEDIANAME = { media_name | @media_name_variable } 
    42  | BLOCKSIZE = { blocksize | @blocksize_variable } 
    43 
    44 --Data Transfer Options
    45    BUFFERCOUNT = { buffercount | @buffercount_variable } 
    46  | MAXTRANSFERSIZE = { maxtransfersize | @maxtransfersize_variable }
    47 
    48 --Error Management Options
    49    { NO_CHECKSUM | CHECKSUM }
    50  | { STOP_ON_ERROR | CONTINUE_AFTER_ERROR }
    51 
    52 --Compatibility Options
    53    RESTART 
    54 
    55 --Monitoring Options
    56    STATS [ = percentage ] 
    57 
    58 --Tape Options
    59    { REWIND | NOREWIND } 
    60  | { UNLOAD | NOUNLOAD } 
    61 
    62 --Log-specific Options
    63    { NORECOVERY | STANDBY = undo_file_name }
    64  | NO_TRUNCATE
    65 
    66 --Encryption Options
    67  ENCRYPTION (ALGORITHM = { AES_128 | AES_192 | AES_256 | TRIPLE_DES_3KEY } , encryptor_options ) 
    68 <encryptor_options> ::= 
    69    SERVER CERTIFICATE = Encryptor_Name | SERVER ASYMMETRIC KEY = Encryptor_Name 
    View Code

    --Data Transfer Options
    BUFFERCOUNT = { buffercount | @buffercount_variable }
    | MAXTRANSFERSIZE = { maxtransfersize | @maxtransfersize_variable }

    -------------------------------------------------------------------------------------------------------

    SQLSERVER还原语句的详细语法以及各个with选项的详细解释

    http://msdn.microsoft.com/zh-cn/library/ms186858(v=sql.120).aspx

      1 --To Restore an Entire Database from a Full database backup (a Complete Restore):
      2 RESTORE DATABASE { database_name | @database_name_var } 
      3  [ FROM <backup_device> [ ,...n ] ]
      4  [ WITH 
      5    {
      6     [ RECOVERY | NORECOVERY | STANDBY = 
      7         {standby_file_name | @standby_file_name_var } 
      8        ]
      9    | ,  <general_WITH_options> [ ,...n ]
     10    | , <replication_WITH_option>
     11    | , <change_data_capture_WITH_option>
     12    | , <FILESTREAM_WITH_option>
     13    | , <service_broker_WITH options> 
     14    | , <point_in_time_WITH_options—RESTORE_DATABASE> 
     15    } [ ,...n ]
     16  ]
     17 [;]
     18 
     19 --To perform the first step of the initial restore sequence 
     20 -- of a piecemeal restore:
     21 RESTORE DATABASE { database_name | @database_name_var } 
     22    <files_or_filegroups> [ ,...n ]
     23  [ FROM <backup_device> [ ,...n ] ] 
     24    WITH 
     25       PARTIAL, NORECOVERY 
     26       [  , <general_WITH_options> [ ,...n ] 
     27        | , <point_in_time_WITH_options—RESTORE_DATABASE> 
     28       ] [ ,...n ] 
     29 [;]
     30 
     31 --To Restore Specific Files or Filegroups: 
     32 RESTORE DATABASE { database_name | @database_name_var } 
     33    <file_or_filegroup> [ ,...n ]
     34  [ FROM <backup_device> [ ,...n ] ] 
     35    WITH 
     36    {
     37       [ RECOVERY | NORECOVERY ]
     38       [ , <general_WITH_options> [ ,...n ] ]
     39    } [ ,...n ] 
     40 [;]
     41 
     42 --To Restore Specific Pages: 
     43 RESTORE DATABASE { database_name | @database_name_var } 
     44    PAGE = 'file:page [ ,...n ]' 
     45  [ , <file_or_filegroups> ] [ ,...n ]
     46  [ FROM <backup_device> [ ,...n ] ] 
     47    WITH 
     48        NORECOVERY   
     49       [ , <general_WITH_options> [ ,...n ] ]
     50 [;]
     51 
     52 --To Restore a Transaction Log:
     53 RESTORE LOG { database_name | @database_name_var } 
     54  [ <file_or_filegroup_or_pages> [ ,...n ] ]
     55  [ FROM <backup_device> [ ,...n ] ] 
     56  [ WITH 
     57    {
     58      [ RECOVERY | NORECOVERY | STANDBY = 
     59         {standby_file_name | @standby_file_name_var } 
     60        ]
     61     | ,  <general_WITH_options> [ ,...n ]
     62     | , <replication_WITH_option>
     63     | , <point_in_time_WITH_options—RESTORE_LOG> 
     64    } [ ,...n ]
     65  ] 
     66 [;]
     67 
     68 --To Revert a Database to a Database Snapshot:   
     69 RESTORE DATABASE { database_name | @database_name_var } 
     70 FROM DATABASE_SNAPSHOT = database_snapshot_name  
     71 
     72 <backup_device>::=
     73 { 
     74    { logical_backup_device_name |
     75       @logical_backup_device_name_var }
     76  | { DISK | TAPE | URL } = { 'physical_backup_device_name' |
     77       @physical_backup_device_name_var } 
     78 } 
     79 Note: URL is the format used to specify the location and the file name for the Windows Azure Blob. Although Windows Azure storage is a service, the implementation is similar to disk and tape to allow for a consistent and seemless restore experince for all the three devices. 
     80 <files_or_filegroups>::= 
     81 { 
     82    FILE = { logical_file_name_in_backup | @logical_file_name_in_backup_var } 
     83  | FILEGROUP = { logical_filegroup_name | @logical_filegroup_name_var } 
     84  | READ_WRITE_FILEGROUPS
     85 } 
     86 
     87 <general_WITH_options> [ ,...n ]::=  
     88 --Restore Operation Options
     89    MOVE 'logical_file_name_in_backup' TO 'operating_system_file_name' 
     90           [ ,...n ] 
     91  | REPLACE 
     92  | RESTART 
     93  | RESTRICTED_USER 
     94  | CREDENTIAL
     95 
     96 --Backup Set Options
     97  | FILE = { backup_set_file_number | @backup_set_file_number } 
     98  | PASSWORD = { password | @password_variable } 
     99 
    100 --Media Set Options
    101  | MEDIANAME = { media_name | @media_name_variable } 
    102  | MEDIAPASSWORD = { mediapassword | @mediapassword_variable } 
    103  | BLOCKSIZE = { blocksize | @blocksize_variable } 
    104 
    105 --Data Transfer Options
    106  | BUFFERCOUNT = { buffercount | @buffercount_variable } 
    107  | MAXTRANSFERSIZE = { maxtransfersize | @maxtransfersize_variable }
    108 
    109 --Error Management Options
    110  | { CHECKSUM | NO_CHECKSUM } 
    111  | { STOP_ON_ERROR | CONTINUE_AFTER_ERROR } 
    112 
    113 --Monitoring Options
    114  | STATS [ = percentage ] 
    115 
    116 --Tape Options
    117  | { REWIND | NOREWIND } 
    118  | { UNLOAD | NOUNLOAD } 
    119   
    120 <replication_WITH_option>::=
    121  | KEEP_REPLICATION 
    122 
    123 <change_data_capture_WITH_option>::=
    124  | KEEP_CDC
    125 
    126 <FILESTREAM_WITH_option>::=
    127  | FILESTREAM ( DIRECTORY_NAME = directory_name )
    128 
    129 
    130 <service_broker_WITH_options>::= 
    131  | ENABLE_BROKER 
    132  | ERROR_BROKER_CONVERSATIONS 
    133  | NEW_BROKER 
    134 
    135 
    136 <point_in_time_WITH_options—RESTORE_DATABASE>::= 
    137  | {
    138    STOPAT = { 'datetime'| @datetime_var } 
    139  | STOPATMARK = 'lsn:lsn_number'
    140                  [ AFTER 'datetime'] 
    141  | STOPBEFOREMARK = 'lsn:lsn_number'
    142                  [ AFTER 'datetime'] 
    143    } 
    144 
    145 <point_in_time_WITH_options—RESTORE_LOG>::= 
    146  | {
    147    STOPAT = { 'datetime'| @datetime_var } 
    148  | STOPATMARK = { 'mark_name' | 'lsn:lsn_number' }
    149                  [ AFTER 'datetime'] 
    150  | STOPBEFOREMARK = { 'mark_name' | 'lsn:lsn_number' }
    151                  [ AFTER 'datetime'] 
    152    } 
    View Code

    参考文章:SQL SERVER BACKUP DATABASE 加快备份速度方法

  • 相关阅读:
    lib-qqwry v1.0 发布 nodejs解析纯真IP库(qqwry.dat)
    queue-fun —— nodejs下基于Promise的队列控制模块。
    javascript 高效按字节截取字符串
    最短JS判断是否为IE6(IE的写法) (转)
    javascript把IP地址转为数值几种方案,来挑战一下效率吧
    Android的ViewPager的学习
    【感悟】一次不太好的寻找bug的体验,RecyclerView
    Android的SQlite的使用
    Android的几种Manager
    Android的Service的创建与使用
  • 原文地址:https://www.cnblogs.com/lyhabc/p/3452894.html
Copyright © 2011-2022 走看看