用 log explorer 恢復(fù),如果沒有l(wèi)og explorer可以用日志文件進(jìn)行時間點(diǎn)恢復(fù),
將會失去此時間點(diǎn)之后的所有數(shù)據(jù)庫改變
example:
首先對數(shù)據(jù)庫進(jìn)行日志備份
查詢分析器里
1.use northwind
insert employees(lastname,firstname) values('aaa','bf')
記下這時的時間
2.過3分鐘輸入
use northwind
insert employees(lastname,firstname) values('bbb','cd')
3.此時select * from employees 將能看到這兩條記錄
4.進(jìn)行日志備份,選中northwind數(shù)據(jù)庫,所有任務(wù),backup database
在對話框中,選擇事務(wù)日志備份為備份類型,選擇已有的備份設(shè)備,和追加到媒體
單擊ok進(jìn)行備份.這樣生成了兩個新紀(jì)錄的日志備份
5.以下演示恢復(fù)
所有任務(wù) restore database
對話框中選擇時點(diǎn)還原,輸入剛才記錄的時間,單擊ok恢復(fù)
6.執(zhí)行select * from employees ,此時只能看到第一個新插入的記錄
如何在數(shù)據(jù)庫文件損壞(日志文件完好)情況下,進(jìn)行恢復(fù)
數(shù)據(jù)庫文件損壞的時候如何恢復(fù)
1 建一個測試數(shù)據(jù)庫test(數(shù)據(jù)庫類型為完全)
2 建一個表,插入點(diǎn)記錄
create table a(c1 varchar(2))
go
insert into a values('aa')
go
insert into a values('bb')
go
3 作完全備份,到文件test_1.bak
4 在作一點(diǎn)修改
insert into a values('cc')
go
create table b(c1 int)
go
insert into b values(1)
go
insert into b values(2)
go
5 shutdown 數(shù)據(jù)庫服務(wù)器
6 用ultraedit編輯數(shù)據(jù)庫文件test_data.mdf,隨便修改點(diǎn)字節(jié)內(nèi)容
7 啟動數(shù)據(jù)庫,并且運(yùn)行企業(yè)管理器,點(diǎn)開數(shù)據(jù)庫,看到test變成灰色,而且顯示置
疑。
8 運(yùn)行isql -slocalhost -usa -p
1> backup log test to disk='d:/program files/microsoft sql
server/mssql/backup/t
est_2.bak' with no_truncate
2>go
已處理 2 頁,這些頁屬于數(shù)據(jù)庫 'test' 的文件 'test_log'(位于文件 1 上)。
backup log 操作成功地處理了 2 頁,花費(fèi)了 0.111 秒(0.087 mb/秒)。
9 進(jìn)行恢復(fù)最老的完全備份
1> restore database test from disk='d:/program files/microsoft sql
server/mssql/
backup/test_1.bak' with norecovery
2> go
已處理 96 頁,這些頁屬于數(shù)據(jù)庫 'test' 的文件 'test_data'(位于文件 1 上)。
已處理 1 頁,這些頁屬于數(shù)據(jù)庫 'test' 的文件 'test_log'(位于文件 1 上)。
restore database 操作成功地處理了 97 頁,花費(fèi)了 0.107 秒(7.368 mb/秒)。
10 恢復(fù)最近的日志
1> restore log test from disk='d:/program files/microsoft sql
server/mssql/backu
p/test_2.bak' with recovery
2> go
已處理 2 頁,這些頁屬于數(shù)據(jù)庫 'test' 的文件 'test_log'(位于文件 1 上)。
restore log 操作成功地處理了 2 頁,花費(fèi)了 0.056 秒(0.173 mb/秒)。
數(shù)據(jù)已經(jīng)完全恢復(fù)了,可以使用了。
select * from a
go
select * from b
go
c1
----
aa
bb
cc
有老的備份的話
1 backup log db to disk='e:/db2.bak' with no_truncate
2 恢復(fù)最老的完全備份
restore database db from disk='e:/db1.bak' with norecovery
3 恢復(fù)最近的日志
restore log db from disk='e:/db2.bak' with recovery
新聞熱點(diǎn)
疑難解答
圖片精選