Sometimes the unexpected happens when you are in the middle of a lengthy database restore. Perhaps your restore has been interrupted by a power failure or your network connection to the server has dropped out. Luckily, SQL Server’s RESTORE
command comes with ability to resume interrupted restores.
-- The initial restore operation.
RESTORE DATABASE [ AdventureWorks2012 ]
FROM [ AdventureWorks2012_Backup ];
-- Disaster strikes :-( (sad trombone)
-- SQL Server's RESTORE command to the rescue.
RESTORE DATABASE [ AdventureWorks2012 ]
FROM [ AdventureWorks2012_Backup ] WITH RESTART ;
This even works with database snapshots .
-- The initial database snapshot revert operation.
RESTORE DATABASE [ AdventureWorks2012 ]
FROM DATABASE_SNAPSHOT = 'AdventureWorks2012_DatabaseSnapshot' ;
-- Disaster strikes :-( (sad trombone)
-- SQL Server's RESTORE command to the rescue now with snapshots.
RESTORE DATABASE [ AdventureWorks2012 ]
FROM DATABASE_SNAPSHOT = 'AdventureWorks2012_DatabaseSnapshot' WITH RESTART ;
I often use database snapshots when testing changes in development environments. I was skeptical that the database snapshot revert process was restartable when I first came across the need. The documentation for the RESTORE
command does not obviously state that RESTART
works with snapshots, however it does in my testing.
Perhaps the ability to resume a database restore will save you some time in the future as it has me.
There are comments .