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