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

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

USEmaster–(Can’tsitinthedatabasewhilstitsbeingrestored!)
GO
ALTERDATABASEMyDatabaseSETSINGLE_USERWITHROLLBACKIMMEDIATE
GO
–RestoreFullBackup
RESTOREDATABASEMyDatabase
FROMDISK=’x:\MSSQL\BACKUP\MyBackupFilename_Full.BAK’
WITH
REPLACE,NORECOVERY,–UseifmoreT/Logstorecover
–RECOVERY,–UseifNOmoreT/Logstorecover
STATS=10,–Showprogress(every10%)
MOVE’MyDatabase_Data’TO’x:\MSSQL\DATA\MyDatabase.mdf’,MOVE’MyDatabase_Log’TO’x:\MSSQL\DATA\MyDatabase.ldf’
GO
–OptionalrestoreDifferentialBackup
RESTOREDATABASEMyDatabase
FROMDISK=’x:\MSSQL\BACKUP\MyDatabase_Diff.BAK’
WITH
–RECOVERY–UseifNOmorefiletorecover
NORECOVERY–UseifthereareT/Logstorecover
GO
–OptionalrestoreTransactionLogBackup
RESTOREDATABASEMyDatabase
FROMDISK=’x:\MSSQL\BACKUP\MyDatabase_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

作者: dawei

【声明】:永州站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

为您推荐

联系我们

联系我们

0577-28828765

在线咨询: QQ交谈

邮箱: xwei067@foxmail.com

工作时间:周一至周五,9:00-17:30,节假日休息

返回顶部