IT貓撲網(wǎng):您身邊最放心的安全下載站! 最新更新|軟件分類|軟件專題|手機版|論壇轉(zhuǎn)貼|軟件發(fā)布

您當(dāng)前所在位置: 首頁數(shù)據(jù)庫MSSQL → 差異備份的恢復(fù)問題

差異備份的恢復(fù)問題

時間:2015-06-28 00:00:00 來源:IT貓撲網(wǎng) 作者:網(wǎng)管聯(lián)盟 我要評論(0)

A :?情況是這樣的?

create? database? test?

create? table? t(a? int)?

insert? into? test..t? select? 1?

然后進(jìn)行一次完整備份?

backup? database? test? to? disk='c:\test.bak'?

insert? into? test..t? select? 2?

再進(jìn)行一次完整備份?

backup? database? test? to? disk='c:\test.bak'?

insert? into? test..t? select? 3?

此時用? restore? database? test? from? disk='c:\test.bak'? with? file=1?

結(jié)果為? 1,? 此為正確?

用? restore? database? test? from? disk='c:\test.bak'? with? file=2?

結(jié)果為? 1,?

2? 此也為正確?

當(dāng)表t中為1,2,3的時候,在插入一條紀(jì)錄結(jié)果為1,2,3,4然后進(jìn)行一次差異備份?

backup? database? test? to? disk='c:\test.bak'? with? differential?

然后往執(zhí)行delete? from? t? 刪除所有紀(jì)錄?

我現(xiàn)在想恢復(fù)最后的那次差異備份(結(jié)果為1,2,3,4),用語句改如何實現(xiàn)呢??

---------------------------------------------------------------???

下面的是詳細(xì)的過程,在我的電腦上測試成功:???

--清除環(huán)境,防止現(xiàn)有的數(shù)據(jù)影響測試結(jié)果?

exec? master..xp_cmdshell? 'del? c:\text.bak'?

if? exists(select? *? from? master..sysdatabases? where? name='test')?

drop? database? test?

go???

--創(chuàng)建數(shù)據(jù)庫?

create? database? test?

go?

--打開創(chuàng)建的數(shù)據(jù)?

use? test?

go???

--創(chuàng)建測試表?

create? table? t(a? int)???

--切換回master數(shù)據(jù)庫?

use? master?

go?

--插入數(shù)據(jù)1?

insert? into? test..t? select? 1?

go???

--然后進(jìn)行一次完整備份?

backup? database? test? to? disk='c:\test.bak'?

go??

--插入數(shù)據(jù)2?

insert? into? test..t? select? 2?

go?

--再進(jìn)行一次完整備份?

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??

--刪除數(shù)據(jù)庫?

drop? database? test??

--還原數(shù)據(jù)庫和差異數(shù)據(jù)庫備份?

--還原完整備份?

restore? database? test? from? disk='c:\test.bak'? with? file=2,norecovery?

--還原差異備份的內(nèi)容?

restore? database? test? from? disk='c:\test.bak'? with? file=3,recovery???

--顯示恢復(fù)后的數(shù)據(jù)?

select? *? from? test..t?

---------------------------------------------------------------?

都已經(jīng)說的好明白了,怎么可能會不行呢??

前段時間我就做過類似程序的!?

必須說明的是:在恢復(fù)差異備份時,必須恢復(fù)最后一次的完整備份?。。ㄇ杏洠?

而且下面的兩個語句必須同時執(zhí)行,即放在一個事務(wù)中。???

restore? database? test? from? disk='c:\test.bak'? with? file=離你要恢復(fù)的差異備份最近一次的完整備份號,norecovery???

restore? database? test? from? disk='c:\test.bak'? with? file=你要還原的差異備份號,recovery???

具體的備份號可以從下面得到:(你可以認(rèn)真研究一下backupfile,backupset,backmediaset,backupmediafamily幾個表,可以發(fā)現(xiàn)規(guī)律)?

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?

如果還不行的話,可以給我留言~?

---------------------------------------------------------------??

---執(zhí)行下面的序列:??

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??

--下面開始恢復(fù):??

restore? database? test? from? disk='c:\test.bak'? with? file=2,norecovery? --對應(yīng)你最后一次的完整備份

restore? database? test? from? disk='c:\test.bak'? with? file=3? --對應(yīng)你要還原的差異備份??

go??

select? *? from? test

關(guān)鍵詞標(biāo)簽:問題,恢復(fù),備份,差異,

相關(guān)閱讀

文章評論
發(fā)表評論

熱門文章 淺談JSP JDBC來連接SQL Server 2005的方法 淺談JSP JDBC來連接SQL Server 2005的方法 SqlServer2005對現(xiàn)有數(shù)據(jù)進(jìn)行分區(qū)具體步驟 SqlServer2005對現(xiàn)有數(shù)據(jù)進(jìn)行分區(qū)具體步驟 sql server系統(tǒng)表損壞的解決方法 sql server系統(tǒng)表損壞的解決方法 MS-SQL2005服務(wù)器登錄名、角色、數(shù)據(jù)庫用戶、角色、架構(gòu)的關(guān)系 MS-SQL2005服務(wù)器登錄名、角色、數(shù)據(jù)庫用戶、角色、架構(gòu)的關(guān)系

相關(guān)下載

    人氣排行 配置和注冊O(shè)DBC數(shù)據(jù)源-odbc數(shù)據(jù)源配置教程 如何遠(yuǎn)程備份(還原)SQL2000數(shù)據(jù)庫 SQL2000數(shù)據(jù)庫遠(yuǎn)程導(dǎo)入(導(dǎo)出)數(shù)據(jù) SQL2000和SQL2005數(shù)據(jù)庫服務(wù)端口查看或修改 修改Sql Server唯一約束教程 SQL Server 2005降級到2000的正確操作步驟 sql server系統(tǒng)表損壞的解決方法 淺談JSP JDBC來連接SQL Server 2005的方法