What can I do to an offline database?

  • I am in the process of migrating DBs from an old server to a new server. Currently, what I've been doing is:

    1. Take a full backup

    2. Set the old DB offline using ALTER DATABASE [Whatever] SET OFFLINE WITH ROLLBACK IMMEDIATE

    3. Restore the backup over-top the "test" restore on the new server.

    My questions are:

    1. Can I backup a DB that is in an offline state? I'm inclined to think no.

    2. Can I restore over-top a DB that is in an offline state (using WITH REPLACE)?

    Although, seeing as no one uses the "test" restore on the new server, except the Dev to verify they can get to it, it's not a big deal if I can or can't restore over-top it, as I can leave it online for the restore...

    Thanks,

    Jason

  • Jason both your suspicions are correct:

    1 you cannot backup a database that is set offline;

    you simply get this error:

    Msg 942, Level 14, State 4, Line 2

    Database 'MyDatabase' cannot be opened because it is offline.

    Msg 3013, Level 16, State 1, Line 2

    BACKUP DATABASE is terminating abnormally.

    .

    2. yes,you can restore over-top a DB that is in an offline,WITH REPLACE.

    The advantage when it's offline, is there's no way for a fast-connecting application or user to reconnect to the database when you are trying to do a restore process.

    setting a database to single_user or restricted_user still leaves possible avenues for connecting to the database, which can interfere with a restoration process, especially if it was scripted and assumed to be able to complete without any errors.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • jasona.work (7/8/2013)


    1. Can I backup a DB that is in an offline state? I'm inclined to think no.

    No, you cannot backup an offline database, however you can copy or move or even delete the raw database files (mdf and ldf).

    jasona.work (7/8/2013)


    2. Can I restore over-top a DB that is in an offline state (using WITH REPLACE)?

    If a database is offline you can restore over the top of it no problem.

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • That's what I thought. I figured setting it to offline for the restore would prevent connections, having seen several postings here from people trying to do maintenance in single-user and getting beat to the connection by an application or other user...

    Once more, thanks,

    Jason

  • jasona.work (7/8/2013)


    seen several postings here from people trying to do maintenance in single-user and getting beat to the connection by an application or other user..

    The trick is to set the database single user and then in the same query session restore the database that waxy you will hold the single user connection 😉

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

Viewing 5 posts - 1 through 4 (of 4 total)

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