--完整備份
Backup Database NorthwindCS
To disk=’G:BackupNorthwindCS_Full_20070908.bak’
--差異備份
Backup Database NorthwindCS
To disk=’G:BackupNorthwindCS_Diff_20070908.bak’
With Differential
--日志備份,默認截斷日志
Backup Log NorthwindCS
To disk=’G:BackupNorthwindCS_Log_20070908.bak’
--日志備份,不截斷日志
Backup Log NorthwindCS
To disk=’G:BackupNorthwindCS_Log_20070908.bak’
With No_Truncate
--截斷日志不保留
Backup Log NorthwindCS
With No_Log
--或者
Backup Log NorthwindCS
With Truncate_Only
--截斷之后日志文件不會變小
--有必要可以進行收縮
--文件備份
Exec Sp_Helpdb NorthwindCS --查看數據文件
Backup Database NorthwindCS
File=’NorthwindCS’ --數據文件的邏輯名
To disk=’G:BackupNorthwindCS_File_20070908.bak’
--文件組備份
Exec Sp_Helpdb NorthwindCS --查看數據文件
Backup Database NorthwindCS
FileGroup=’Primary’ --數據文件的邏輯名
To disk=’G:BackupNorthwindCS_FileGroup_20070908.bak’
With init
--分割備份到多個目標
--恢復的時候不允許丟失任何一個目標
Backup Database NorthwindCS
To disk=’G:BackupNorthwindCS_Full_1.bak’
,disk=’G:BackupNorthwindCS_Full_2.bak’
--鏡像備份
--每個目標都是相同的
Backup Database NorthwindCS
To disk=’G:BackupNorthwindCS_Mirror_1.bak’
Mirror
To disk=’G:BackupNorthwindCS_Mirror_2.bak’
With Format --第一次做鏡像備份的時候格式化目標
--鏡像備份到本地和遠程
Backup Database NorthwindCS
To disk=’G:BackupNorthwindCS_Mirror_1.bak’
Mirror
To disk=’\192.168.1.200BackupNorthwindCS_Mirror_2.bak’
With Format
--每天生成一個備份文件
Declare @Path Nvarchar(2000)
Set @Path =’G:BackupNorthwindCS_Full_’
+Convert(Nvarchar,Getdate(),112)+’.bak’
Backup Database NorthwindCS
To dick=@path
--從NoRecovery或者
--Standby模式恢復數據庫為可用
Restore Database NorthwindCS_Bak
With Recovery
--查看目標備份中的備份集
Restore HeaderOnly
From Disk =’G:BackupNorthwindCS_Full_20070908.bak’
--查看目標備份的第一個備份集的信息
Restore FileListOnly
From Disk =’G:BackupNorthwindCS_Full_20070908_2.bak’
With File=1
--查看目標備份的卷標
Restore LabelOnly
From Disk =’G:BackupNorthwindCS_Full_20070908_2.bak’
--備份設置密碼保護備份
Backup Database NorthwindCS
To disk=’G:BackupNorthwindCS_Full_20070908.bak’
With Password = ’123’,init
Restore Database NorthwindCS
From disk=’G:BackupNorthwindCS_Full_20070908.bak’
With Password = ’123’
備份:backup database dbname to disk=';d:dbn.aa';
恢復:restore database dbname from disk=';d:dbn.aa';
恢復必須在單用戶模式下操作才能夠成功,我們需要斷開其他用戶的連接,并且切換到其他數據庫,才能夠成功