--完整備份
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Full_20070908.bak'
--差異備份
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Diff_20070908.bak'
With Differential
--日志備份,默認截斷日志
Backup Log NorthwindCS
To disk='G:\Backup\NorthwindCS_Log_20070908.bak'
--日志備份,不截斷日志
Backup Log NorthwindCS
To disk='G:\Backup\NorthwindCS_Log_20070908.bak'
With No_Truncate
--截斷日志不保留
Backup Log NorthwindCS
With No_Log
--或者
Backup Log NorthwindCS
With Truncate_Only
--截斷之后日志文件不會變小
--有必要可以進行收縮
--文件備份
Exec Sp_Helpdb NorthwindCS --查看數(shù)據(jù)文件
Backup Database NorthwindCS
File='NorthwindCS' --數(shù)據(jù)文件的邏輯名
To disk='G:\Backup\NorthwindCS_File_20070908.bak'
--文件組備份
Exec Sp_Helpdb NorthwindCS --查看數(shù)據(jù)文件
Backup Database NorthwindCS
FileGroup='Primary' --數(shù)據(jù)文件的邏輯名
To disk='G:\Backup\NorthwindCS_FileGroup_20070908.bak'
With init
--分割備份到多個目標
--恢復的時候不允許丟失任何一個目標
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Full_1.bak'
,disk='G:\Backup\NorthwindCS_Full_2.bak'
--鏡像備份
--每個目標都是相同的
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Mirror_1.bak'
Mirror
To disk='G:\Backup\NorthwindCS_Mirror_2.bak'
With Format --第一次做鏡像備份的時候格式化目標
--鏡像備份到本地和遠程
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Mirror_1.bak'
Mirror
To disk='\\192.168.1.200\Backup\NorthwindCS_Mirror_2.bak'
With Format
--每天生成一個備份文件
Declare @Path Nvarchar(2000)
Set @Path ='G:\Backup\NorthwindCS_Full_'
+Convert(Nvarchar,Getdate(),112)+'.bak'
Backup Database NorthwindCS
To disk=@Path
--從NoRecovery或者
--Standby模式恢復數(shù)據(jù)庫為可用
Restore Database NorthwindCS_Bak
With Recovery
--查看目標備份中的備份集
Restore HeaderOnly
From Disk ='G:\Backup\NorthwindCS_Full_20070908.bak'
--查看目標備份的第一個備份集的信息
Restore FileListOnly
From Disk ='G:\Backup\NorthwindCS_Full_20070908_2.bak'
With File=1
--查看目標備份的卷標
Restore LabelOnly
From Disk ='G:\Backup\NorthwindCS_Full_20070908_2.bak'
--備份設置密碼保護備份
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Full_20070908.bak'
With Password = '123',init
Restore Database NorthwindCS
From disk='G:\Backup\NorthwindCS_Full_20070908.bak'
With Password = '123'