Weird Issue Restoring DB in SQL 2012

  • Scenario

    Test Server

    Database A. Needs to be backed up and restored as Database B.

    1 Backup Database A. Fine

    2 Restore Backup of A as DATABASE B. Problem.

    Although the destination db using the GUI has been changed to DATABASE B and the overwrite existing database is NOT ticked. This has been overwriting DATABASE A even through the overwrite option is not checked. When this is scripted out via the script button on the GUI it states restore database [DATABASE B}.

    Workaround has been to rename DATABASE A to DATABASE x, do the restore it restores as DATABASE B correctly. Then return DATABSE X to DATABASE A.

    If the original database that was used for the backup doesn’t exist it will create the database correctly with no overwrite. Has anyone seen this before its very strange.

    SQL 2012 on WINDOWS 2012.

  • When using the GUI, have it generate a CREATE script for Database A, a CREATE script for Database B, a RESTORE script for Database B, and a RESTORE FILELISTONLY of the backup file. Show us all of this and there will be an answer in there somewhere.

    The only thing I can think of is if you detached Database A, and Database B had files pointing to the same location. You restore B without a WITH MOVE clause and it overwrites A's files.

  • Yeah, I'd make sure that you're using WITH MOVE. It could just be that it's overwriting the files... which would only be possible if the database is offline.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thanks for the replies, but the dbs are not offline. I am using the GUI not T-SQL. The database nor db files should be able to be overwritten. As long as I change the destination db in the GUI and change the file names it should restore correctly.

    If the database name is changed from what it was when the backup was taken it works fine. So it is not the files as they remain the same when the db is renamed. It's a very strange one.

    Again my work around for now is to rename the db(Original db_a)the backed up db rename to(db_a1), restore it from the backup file as (db x).

    Rename db_a1 back to db_a.

    It seems if the origanl db used to create the backup file exists it overwrites it. Even when the option is not selected. This should not be possible. Honestly this is the case.

  • Just played around with it myself (don't usually use the GUI very often) and it's pretty misleading.

    By default, when selecting a backup file that has the same DB name as one that exists on that server, if you don't go onto the options tab, you'll put your source database in the RESTORING state as it does a tail log backup of it, even if your destination name is different.

    It's not actually restoring over the top (you can still bring it back ONLINE), but can see why you'd think it was restoring over the top!

  • Yes the link seems to be the issue, this is pretty poor from MS as the overwrite is not ticked so you would expect failure.

    I usually use T-SQL for restores, this caught me out as it was supposed to be a quick smash and grab restore for someone in the DEV environment who was struggling to get it done.

    THANKS

  • Holy cow that article (and more specifically the related Connect item) are crazy, and that they've been sitting there since February with no reply is ridiculous!

    On the other hand I now have legitimate reasons to tell businesses that the SQL Server GUI can destroy databases just while trying to restore them, and so they really need my services because I would use T-SQL. Hehe.

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply