资源描述:
《第09章实训指导》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、实验九:数据库的备份和还原1.创建压缩的、镜像的完整备份执行以下代码,为AdventureWorks数据库创建一个压缩备份,并对备份镜像以实验数据冗余,并对面的“校验和”进行校验。BACKUPDATABASEAdventureWorks2008R2TODISK=*C:TESTAdventureWorks_l.bak1MIRRORTODISK=*C:TESTAdventureWorks_2.bak1WITHCOMPRESSION,INIT,FORMAT,CHECKSUM,STOP_ON_ERROR2.创建事务日志备份执行以下代码来修改数据,并
2、执行第一个事务日志备份。USEAdventureWorks2008R2GOINSERTINTOHumanResources.Department(Name,GroupName)VALUES(1Test11,ResearchandDevelopment1)GOBACKUPLOGAdventureWorks2008R2TODISK=!C:TESTAdventureWorks_l.trnfWITHCOMPRESSION,INIT,CHECKSUM,STOP_ON_ERRORGO执行以下代码执行一次数据修改并执行第二次事务日志备份。INSERTINTO
3、HumanResources.Department(Name,GroupName)VALUES(fTest21,ResearchandDevelopment1)GOBACKUPLOGAdventureWorks2008R2TODISK='C:TESTAdventureWorks_2•trn1WITHCOMPRESSION,INIT,CHECKSUM,STOP_ON_ERRORGO3.创建差异备份INSERTINTOHumanResources.Department(Name,GroupName)VALUES(!Test31,Researchan
4、dDevelopment‘)GOBACKUPDATABASEAdventureWorks2008R2TODISK=1C:TESTAdventureWorks_l.dif1MIRRORTODISK='C:TESTAdventureWorks_2・dif'WITHDIFFERENTIAL,COMPRESSION,INIT,FORMAT,CHECKSUM,STOP_ON_ERRORGO1.故意损坏数据库执行以下代码,添加记录。INSERTINTOHumanResources.Department(Name,GroupName)VALUES(fTe
5、st41,ResearchandDevelopment1)GO停止SQLServer实例服务。删除AdventureWorks2008R2.mdf文件,注意不要删除ldf文件。启动SQLServer实例服务。5.恢复完整备份恢复过程的第一步是备份“口志结尾”。执行如下代码。BACKUPLOGAdventureWorks2008R2TODISK='C:TESTAdventureWorks_3.trn*WITHCOMPRESSION,INITzNO_TRUNCATEGO现在已经捕获了H志结尾,请执行以下代码恢复完整备份。RESTOREDATABAS
6、EAdventureWorks2008R2FROMDISK='C:TESTAdventureWorks_1.bmk1WITHSTANDBY=*C:TESTAdventureWorks.stn'验证能够读取数据但不能修改,验证添加的部门在数据库中丢失。6.恢复差异备份执行以下代码來恢复差异备份RESTOREDATABASEAdventureWorks2008R2FROMDISK='C:TESTAdventureWorks_l.dif*WITHSTANDBY=*C:TESTAdventureWorks.stn1验证TESTI,TEST2
7、,TEST3部门都存在。执行以下代码来恢复数据库并终止恢复过程。RESTOREDATABASEAdventureWorks2008R2WITHRECOVERY7.恢复事务Fl志备份执行以卜代码来恢复AdventureWorks数据库的完整备份。RESTOREDATABASEAdventureWorks2008R2FROMDISK='C:TESTAdventureWorks_:L・bak'WITHSTANDBY=*C:TESTAdventureWorks.stn',REPLACE验证数据变化恢复第1个事务日志RESTOREDATABASEAd
8、ventureWorks2008R2FROMDISK='C:TESTAdventureWorks_l.trn*WITH