【正文】
RUNCATE,表示追加性的和允許在數(shù)據(jù)庫損壞時備份日志 ) insert into student(sno,sname,sex) values(888,39。 首先刪除數(shù)據(jù)庫 drop database school 然后再創(chuàng)建數(shù)據(jù)庫 create database school 從文件恢復數(shù)據(jù)庫 RESTORE DATABASE school FROM DISK = 39。 TO 39。 2022/11/11 14:39:0039。c:\back_device\39。disk39。,39。 將數(shù)據(jù)庫備份到臨時備份文件 backup database d4 to disk=39。 backup database d4 to bak4,bak5,bak6 with medianame=39。 建立表 b1 create table b1(c1 int not null,c2 char(10) not null) 每次插入更新的數(shù)據(jù)后,都進行差異數(shù)據(jù)備份 backup database d2 to bak2 with differential,name=39。) backup database d2 to bak2 with differential,name=39。 create table b1(c1 int not null,c2 char(10) not null) 每次插入更新的數(shù)據(jù)后,都進行日志文件備份 backup log d3 to bak3 with name=39。) backup log d3 to bak3 with name=39。 insert b1 values(1,39。 insert b1 values(3,39。 insert b1 values(5,39。, size=2MB), filegroup FG2 創(chuàng)建數(shù)據(jù)庫時創(chuàng)建 filegroup FG2 (name=d5_data2, filename=39。, size=2MB) to filegroup FG3 查詢數(shù)據(jù)庫 d5 Exec sp_helpdb d5 create table t1(c1 int not null,c2 char(10) not null) on [primary] 將不同表放到不同 filegroup中 create table t2(c1 int not null,c2 char(10) not null) on FG2 create table t3(c1 int not null,c2 char(10) not null) on FG3 backup database d5 to bak5 with init,name=39。 backup database d5 filegroup=39。 to bak5 with name=39。 to bak6 with name=39。 backup log d5 to bak6 with name=39。 backup database d5 file=39。 實驗 還原文件組備份 restore database d5 filegroup=39。, size=2MB) go backup database d6 to bak6 with init drop database d6 restore database d6 from bak6 with move 39。 查看數(shù)據(jù)庫信息 Exec sp_helpdb d6 72 本章總結(jié) ? 了解數(shù)據(jù)庫備份的基本概念以及備份的基本類別是什么? ? 掌握如何分別在可視化及命令行方式建立和刪除數(shù)據(jù)庫磁盤備份設備。 to 39。, size=2MB) log on (name=d6_log, filename=39。 restore headeronly from bak6 68 數(shù)據(jù)庫備份與恢復技術實訓 實訓 6: SQL Server數(shù)據(jù)還原實訓 實驗 驗證備份設備 restore headeronly from bak3 restore filelistonly from bak3 with file=1 restore labelonly from bak3 restore verifyonly from bak3 實驗 從備份中還原 restore headeronly from bak1 實驗 從完全備份中恢復 restore database d1 from bak1 with file=2 69 數(shù)據(jù)庫備份與恢復技術實訓 實訓 6: SQL Server數(shù)據(jù)還原實訓 實驗 從差異備份中恢復 restore headeronly from bak2 restore database d2 from bak2 with file=1,norecovery restore database d2 from bak2 with file=5,recovery 實驗 從日志備份中恢復 restore headeronly from bak3 restore database d3 from bak3 with file=1,norecovery restore log d3 from bak3 with file=2,norecovery restore log d3 from bak3 with file=3,norecovery restore log d3 from bak3 with file=4,norecovery restore log d3 from bak3 with file=5,recovery 70 數(shù)據(jù)庫備份與恢復技術實訓 實訓 6: SQL Server數(shù)據(jù)還原實訓 實驗 恢復到指定時間 restore database d3 from bak3 with file=1,norecovery restore log d3 from bak3 with file=2,norecovery restore log d3 from bak3 with file=3,norecovery restore log d3 from bak3 with file=4,recovery,stopat=39。 backup log d5 to bak6 with name=39。 to bak6 with name=39。 backup database d5 file=39。 backup database d5 filegroup=39。 backup log d5 to bak5 with name=39。, size=2MB) to filegroup FG2 將 d5_data3加到文件組 FG2中 alter database d5 add filegroup FG3 增加文件組 FG3 alter database d5 將 d5_data4加到文件組 FG2中 add file (name=d5_data4, filename=39。 create database d5 on primary (name=d5_data1, filename=39。) backup log d4 to bak4 with name=39。) backup database d4 to bak4 with differential,name=39。 restore headeronly from bak3 63 數(shù)據(jù)庫備份與恢復技術實訓 實訓 4: SQL Server備份方法實訓 實驗 4:下面的實驗包括:完全數(shù)據(jù)備份,差異數(shù)據(jù)備份和日志文件備份 create table b1(c1 int not null,c2 char(10) not null) backup log d4 to bak4 with name=39。 insert b1 values(2,39。 restore headeronly from bak2 62 數(shù)據(jù)庫備份與恢復技術實訓 實訓 4: SQL Server備份方法實訓 實驗 3:下面開始進行日志備份,第一次備份時應做完全備份 backup database d3 to bak3 with init,name=39。 insert b1 values(2,39。,format backup database d1 to bak1 with init with init重寫備份設備中內(nèi)容 backup database d2 to bak1 with noinit with noinit將內(nèi)容追加到備份設備中 restore headeronly from bak1 61 數(shù)據(jù)庫備份與恢復技術實訓 實訓 4: SQL Server備份方法實訓 實驗 1:首先開始進行完全數(shù)據(jù)備份 backup database d1 to bak1 with init backup database d1 to bak1 with noinit 注意,參數(shù) init和 noinit的差異性 實驗 2:下面開始進行差異備份,第一次備份時應做完全備份 backup database d2 to bak2 with init,name=39。另一方面,媒體集中的文件必須同時使用,而不能單獨使用。 刪除備份設備 backup database d3 to bak3 將數(shù)據(jù)庫備份到備份設備 backup database d4 to bak4 restore headeronly from bak2 查看備份設備中的內(nèi)容 backup database d3 to disk=39。 exec sp_addumpdevice 39。c:\back_device\39。bak239。 第三步:而后開始根據(jù)具體的最后備份時間,進行日志文件的還原工作。 ,MOVE 39。 52 SQL Server 2022的數(shù)據(jù)庫恢復 通過命令行進行數(shù)據(jù)庫還原 實驗:數(shù)據(jù)庫備份與還原命令綜合實驗 第五步: 下面查看第二個備份的 school數(shù)據(jù)庫備份相關信息,學習 with file參數(shù)的用法 。,39。 49 SQL Server 2022的數(shù)據(jù)庫恢復 通過命令行進行數(shù)據(jù)庫還原 實驗:數(shù)據(jù)庫備份與還原命令綜合實驗 第二步: 對數(shù)據(jù)庫 school和 family進行完全的數(shù)據(jù)庫備份 。,39。,39??捎檬÷? FROM 子句的辦法嘗試恢復通過 NORECOVERY 選項還原的數(shù)據(jù)庫,或切換到一臺備用服務器上。當使用該選項時,系統(tǒng)取消事務日志中任何未提交的事務,并提交任何完成的事務。 41 SQL Server 2022的數(shù)據(jù)庫恢復 通過命令行進行數(shù)據(jù)庫還原 ( 1) 數(shù)據(jù)庫還原前準備 ? 第一點:限制數(shù)據(jù)庫的訪問,避開網(wǎng)絡流量較大的時間段。重復第一步的事務日志備份工作,此時在 已經(jīng)保存了兩次數(shù)據(jù)插入的日志信息(一次是張飛,一次是貂蟬)。如圖所示。 33 SQL Server 2022的數(shù)據(jù)庫恢復 在管理平臺中通過數(shù)據(jù)庫備份文件恢復數(shù)據(jù)庫 實驗 2:在管理平臺中中利用差異數(shù)據(jù)備份還原數(shù)據(jù)庫實驗 第二步:刪除 school數(shù)據(jù)庫,而后先進性一次完全數(shù)據(jù)備份,但是過程和實驗 1卻不完全一致。c:\39。 26 ( 3)日志文件