go --创建数据库 create database test go --打开创建的数据 use test go --创建测试表 create table t(a int) --切换回master数据库 use master go --插入数据1 insert into test..t select 1 go --然后进行一次完整备份 backup database test to disk='c:\test.bak' go --插入数据2 insert into test..t select 2 go --再进行一次完整备份 backup database test to disk='c:\test.bak' go --插入3,4 insert into test..t select 3 insert into test..t select 4 go --差异备份: backup database test to disk='c:\test.bak' with differential --删除数据库 drop database test --还原数据库和差异数据库备份 --还原完整备份 restore database test from disk='c:\test.bak' with file=2,norecovery --还原差异备份的内容 restore database test from disk='c:\test.bak' with file=3,recovery --显示恢复后的数据 select * from test..t --------------------------------------------------------------- 都已经说的好明白了,怎么可能会不行呢? 前段时间我就做过类似程序的! 必须说明的是:在恢复差异备份时,必须恢复最后一次的完整备份!!(切记) 而且下面的两个语句必须同时执行,即放在一个事务中。
[1] [2]
restore database test from disk='c:\test.bak' with file=离你要恢复的差异备份最近一次的完整备份号,norecovery restore database test from disk='c:\test.bak' with file=你要还原的差异备份号,recovery 具体的备份号可以从下面得到:(你可以认真研究一下backupfile,backupset,backmediaset,backupmediafamily几个表,可以发现规律) select backup_start_date as 备份时间,position as 备份号, case type when 'D' then '完整备份' when 'I' then '差异备份' end as 备份类型 from msdb..backupset where database_name='test' and media_set_id in (select distinct media_set_id from msdb..backupmediafamily where physical_device_name='c:\test.bak') order by position 如果还不行的话,可以给我留言~ --------------------------------------------------------------- ---执行下面的序列: create database test go use test go create table test..t(a int) insert test..t select 1 backup database test to disk='c:\test.bak' insert test..t select 2 backup database test to disk='c:\test.bak' insert test..t select 3 insert test..t select 4 backup database test to disk='c:\test.bak' with differential delete test..t go --下面开始恢复: restore database test from disk='c:\test.bak' with file=2,norecovery --对应你最后一次的完整备份restore database test from disk='c:\test.bak' with file=3 --对应你要还原的差异备份 go select * from test
(出处:http://www.sheup.com)
(出处:http://www.sheup.com/)