SQL Server: Database stuck in “Restoring” state

前端 未结 26 2033
后悔当初
后悔当初 2020-11-28 17:09

I backed up a database:

BACKUP DATABASE MyDatabase
TO DISK = \'MyDatabase.bak\'
WITH INIT --overwrite existing

And then tried to restore it

26条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 17:54

    WITH RECOVERY option is used by default when RESTORE DATABASE/RESTORE LOG commands is executed. If you're stuck in "restoring" process you can bring back a database to online state by executing:

    RESTORE DATABASE YourDB WITH RECOVERY
    GO
    

    If there's a need for multiple files restoring, CLI commands requires WITH NORECOVERY and WITH RECOVERY respectively - only the last file in command should have WITH RECOVERY to bring back the database online:

    RESTORE DATABASE YourDB FROM DISK = 'Z:\YourDB.bak'
    WITH NORECOVERY
    GO
    RESTORE LOG YourDB FROM DISK = 'Z:\YourDB.trn'
    WITH RECOVERY
    GO
    

    You can use SQL Server Management Studio wizard also:

    enter image description here

    There is also virtual restoring process, but you'll have to use 3rd party solutions. Usually you can use a database backup as live online database. ApexSQL and Idera has their own solutions. Review by SQL Hammer about ApexSQL Restore. Virtual restoring is good solution if you're dealing with large numbers of backups. Restore process is much faster and also can save a lot of space on disk drive. You can take a look on infographic here for some comparison.

提交回复
热议问题