Use Backup to Copy a DB

  • Hi All

    I want to be able to use a backup to create a different copy of my DB for training purposes. Eg.

    1) backup Northwind

    2) restore the resulting .BAK as TestNorthwind

    My App then allows to dynamically switch between the two different DBs, so that users can test scenarios before they commit themselves to use the 'live' DB

    Anyone out there done this? I can't fuigure out how I can convince restore to use a different DB name. I worked it out, using Detach/Attach, but then the DB is offline for some short time, which is inconvenient...

    Thanks anyone

    Felix Burkhard

  • Hi,

    if I got you right, in EM right-click on the db you want to restore -> All tasks -> Restore Database. From the following dialog choose the db you want and some other settings AND don't forget on the Options tab to change the filename in the 'Restore As' row!!!!

    Cheers,

    Frank

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • in addition to my previous post. On the General tab you can simply overwrite the value in the 'Restore as database' combo. You shouldn't forget this as well 🙂

    Cheers,

    Frank

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • To perform this via Query Analyzer, first do (adjust file and path accordingly):

    RESTORE FILELISTONLY FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL\Backup\Northwind.BAK'

    Take note of the logical file names listed.

    Then do (replace 'Northwind_Data' and 'Northwind_Log' with the logical file names from the previous step and adjust the paths as necessary):

    RESTORE DATABASE [TestNorthwind]

    FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL\Backup\Northwind.BAK'

    WITH RECOVERY, MOVE 'Northwind_Data' TO N'C:\Program Files\Microsoft SQL Server\MSSQL\Data\TestNorthwind_Data.MDF', MOVE 'Northwind_Log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL\Data\TestNorthwind_Log.LDF'

    Once that is complete, you may optionally correct the logical file names by doing (adjust logical name as necessary):

    ALTER DATABASE [TestNorthwind]

    MODIFY FILE (NAME = 'Northwind_Data', NEWNAME = 'TestNorthwind_Data')

    GO

    ALTER DATABASE [TestNorthwind]

    MODIFY FILE (NAME = 'Northwind_Log', NEWNAME = 'TestNorthwind_Log')

    GO

    We do this frequently in-house. It drives me nuts for the logical names to reflect incorrect database names, so I always do the MODIFY NAME to make everything consistent.


    David R Buckingham, MCDBA,MCSA,MCP

  • Fixing the file names saves a lot of headaches, worth the extra minute to do.

    Andy

    http://www.sqlservercentral.com/columnists/awarren/

  • Thanks DRBuckingham for the very useful reply, particularly the rename of the logical names. Everything is working now like I wanted.

    I have a 'Globals' table and at the end I insert a timestamp so that I can check in the program, when I updated the test DB the last time.

    Thanks everyone for your time!

  • What exactly does N'string' do? Is it really necessary?

  • Hi,

    quote:


    What exactly does N'string' do? Is it really necessary?


    not sure if it is really necessary, but it convert the string to unicode

    Cheers,

    Frank

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • It takes a special sort of genius to name a function so that is so short it qualifies for a noise word in search engines!

    I can't see that anyone would want to cast a character in the ASCII range to the same number, still in the ASCII range.

  • quote:


    It takes a special sort of genius to name a function so that is so short it qualifies for a noise word in search engines!

    I can't see that anyone would want to cast a character in the ASCII range to the same number, still in the ASCII range.


    These are strange days

    Cheers,

    Frank

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • No, the N'string' is not necessary. It's a carry-over from the Query Analyzer template that I've never bothered to remove. The conversion will obviously take place without it being specified.


    David R Buckingham, MCDBA,MCSA,MCP

Viewing 11 posts - 1 through 10 (of 10 total)

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