欢迎来到福编程网,本站提供各种互联网专业知识!
您的位置:网站首页 > 数据库 > MsSql

如何恢复数据库备份到一个已存在的正在使用的数据库上

发布时间:2007-01-13 作者: 来源:转载
USEmaster--(Can’tsitinthedatabasewhilstitsbeingrestored!)GOALTERDATABASEMyDatabaseSETSINGLE_USERWITHROLLBACKIMMEDIATEGO--RestoreFullBackupRESTOREDATABASEMyDatabaseFROMDISK=’x:\MSSQL\BACKUP\MyBackupFilename_Full.BAK’WI
USEmaster--(Can’tsitinthedatabasewhilstitsbeingrestored!)

GO

ALTERDATABASEMyDatabaseSETSINGLE_USERWITHROLLBACKIMMEDIATE

GO

--RestoreFullBackup

RESTOREDATABASEMyDatabase

FROMDISK=’x:MSSQLBACKUPMyBackupFilename_Full.BAK’

WITH

REPLACE,

NORECOVERY,--UseifmoreT/Logstorecover

--RECOVERY,--UseifNOmoreT/Logstorecover

STATS=10,--Showprogress(every10%)

MOVE’MyDatabase_Data’TO’x:MSSQLDATAMyDatabase.mdf’,

MOVE’MyDatabase_Log’TO’x:MSSQLDATAMyDatabase.ldf’

GO

--OptionalrestoreDifferentialBackup

RESTOREDATABASEMyDatabase

FROMDISK=’x:MSSQLBACKUPMyDatabase_Diff.BAK’

WITH

--RECOVERY--UseifNOmorefiletorecover

NORECOVERY--UseifthereareT/Logstorecover

GO

--OptionalrestoreTransactionLogBackup

RESTOREDATABASEMyDatabase

FROMDISK=’x:MSSQLBACKUPMyDatabase_yyyymmdd_hhmm_Trans.BAK’

WITH

--RECOVERY--UseifNOmoreT/Logstorecover

NORECOVERY--UseifmoreT/Logstorecover

GO

--Setthedatabasereadyforuse(afterallbackupshavebeenrestored)

RESTOREDATABASEMyDatabaseRECOVERY

GO

--Renamelogicalnames(onlyneededifrestoringfromabackupforaDifferentdatabase):

ALTERDATABASEMyDatabase

MODIFYFILE(NAME=’OrigDatabase_Data’,NEWNAME=’MyDatabase_data’)

GO

ALTERDATABASEMyDatabase

MODIFYFILE(NAME=’OrigDatabase_Log’,NEWNAME=’MyDatabase_log’)

GO

相关推荐