Sql server Database Backup、恢複等
來源:互聯網
上載者:User
--完整備份Backup Database NorthwindCSTo disk='G:\Backup\NorthwindCS_Full_20070908.bak'--差異備份Backup Database NorthwindCSTo disk='G:\Backup\NorthwindCS_Diff_20070908.bak'With Differential--記錄備份,預設截斷日誌Backup Log NorthwindCSTo disk='G:\Backup\NorthwindCS_Log_20070908.bak'--記錄備份,不截斷日誌Backup Log NorthwindCSTo disk='G:\Backup\NorthwindCS_Log_20070908.bak'With No_Truncate--截斷日誌不保留Backup Log NorthwindCSWith No_Log--或者Backup Log NorthwindCSWith Truncate_Only--截斷之後記錄檔不會變小--有必要可以進行收縮--檔案備份Exec Sp_Helpdb NorthwindCS --查看資料檔案Backup Database NorthwindCSFile='NorthwindCS' --資料檔案的邏輯名To disk='G:\Backup\NorthwindCS_File_20070908.bak'--檔案組備份Exec Sp_Helpdb NorthwindCS --查看資料檔案Backup Database NorthwindCSFileGroup='Primary' --資料檔案的邏輯名To disk='G:\Backup\NorthwindCS_FileGroup_20070908.bak'With init--分割備份到多個目標--恢複的時候不允許丟失任何一個目標Backup Database NorthwindCSTo disk='G:\Backup\NorthwindCS_Full_1.bak' ,disk='G:\Backup\NorthwindCS_Full_2.bak'--鏡像備份--每個目標都是相同的Backup Database NorthwindCSTo disk='G:\Backup\NorthwindCS_Mirror_1.bak'MirrorTo disk='G:\Backup\NorthwindCS_Mirror_2.bak'With Format --第一次做鏡像備份的時候格式化目標--鏡像備份到本地和遠程Backup Database NorthwindCSTo disk='G:\Backup\NorthwindCS_Mirror_1.bak'MirrorTo 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 NorthwindCSTo disk=@Path--從NoRecovery或者--Standby模式恢複資料庫為可用Restore Database NorthwindCS_BakWith Recovery--查看目標備份中的備份組Restore HeaderOnlyFrom Disk ='G:\Backup\NorthwindCS_Full_20070908.bak'--查看目標備份的第一個備份組的資訊Restore FileListOnlyFrom Disk ='G:\Backup\NorthwindCS_Full_20070908_2.bak'With File=1--查看目標備份的卷標Restore LabelOnlyFrom Disk ='G:\Backup\NorthwindCS_Full_20070908_2.bak'--備份設定密碼保護備份Backup Database NorthwindCSTo disk='G:\Backup\NorthwindCS_Full_20070908.bak'With Password = '123',initRestore Database NorthwindCSFrom disk='G:\Backup\NorthwindCS_Full_20070908.bak'With Password = '123'