Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « Running static code analysis on SQL Server database with Visual Studio Team System for database architectsUse sys.dm_os_performance_counters to get your Buffer cache hit ratio and Page life expectancy counters »
    comments

    Most DR solutions include log shipping strategies. Log shipping (LS) is an extremely inexpensive solution for DR and also one I recommend. There is little learning curve to individuals just coming into the administration career for setting LS up and maintaining the flow.

    One thing that will undoubtedly be asked of you at some point in time will be to make a backup of the warm-standby database for other purposes. Reasoning for this is commonly due to the geographical location of the standby database verses the online production environment. Often in order to move a backup that is larger in size, there will be several hours involved in the actual copy of the phsyical files and sometimes even days depending on the variables in place on the WAN.

    When you go to make a backup of a database in standby, you will be presented with the following

    The database "bah" is in warm-standby state (set by executing RESTORE WITH STANDBY) and cannot be backed up until the entire restore sequence is completed.

    In the state the database is in, you will not be able to use normal methods to get this task done. Depending on the restore rate you have for LS, you could also break the LS stream and in the worst case scenario, cause you to reinitialize the entire LS plan. I’d like to show you a quick and easy solution to that though.

    Note: This method is the quickest way I have found. As always with my work, I am open to others knowing better and more efficient methods. There is a break point below in the copy. It is a good idea to disable you LS plan while you perform this to prevent failed restore job.

    Let’s setup a test database to play with. We’ll create, backup and restore to standby…

    1. CREATE DATABASE bah
    2. GO
    3. BACKUP DATABASE bah TO DISK = 'C:\bah.bak'
    4. GO
    5. RESTORE DATABASE [bah] FROM  
    6. DISK = N'C:\bah.bak'
    7. WITH  FILE = 1,  STANDBY = N'C:\ROLLBACK_UNDO_bah.BAK',  
    8. NOUNLOAD,  REPLACE,  STATS = 10
    9. GO



    We should now have, “bah (Standby /Read-Only) listed in our database tree.

    The regular Copy Database with either detaching or SMO is not ideal for us at this point. We can however take this database offline, grab the mdf, ndf’s and ldf’s to bring to the other instance we want to restore them to.

    To do this we perform the following steps

    1. USE MASTER
    2. GO
    3. ALTER DATABASE bah SET OFFLINE
    Now go to the default folder where the mdf and other files are located and copy/paste them to a local drive. I mentioned local drive because we need to do this as quickly as possible. If there is enough free space locally, it will be the fastest copy transmission. Otherwise at this stage it is crucial to ensure you have disabled the LS plans so no unwanted jobs attempt to access the database while it is offline.

    Once you’ve copied the files off, run the following to bring the database back up

    1. USE MASTER
    2. GO
    3. ALTER DATABASE bah SET ONLINE

    We should see the database has come back up in standby mode and log shipping can proceed as normal.

    Next, we only need to attach the files to a new instance given the following commands or using SSMS attach/detach wizard.

    Note: You cannot bring these files up on the same instance. This is due to being required to leave the database "as is" and with the same file names. When the database was taken offline, it was in standby mode and will be the same when attached again during the initial loading. Once on the new instance, you can bring the database into any state you require and move it back to the other instance is required.

    On the secondary instance do the following steps

    1. CREATE DATABASE bah
    2. ON
    3. ( NAME = bah_data,FILENAME = 'c:\restore\bah.mdf')
    4. LOG ON
    5. ( NAME = 'bah_log',
    6.    FILENAME = 'c:\restore\bah_1.ldf' )
    7. GO
    8. ALTER DATABASE bah SET OFFLINE
    9. GO
    10. --Copy the bah files from our original standby database into the location you just created the
    11. --new database to.  in my case C:\restore\
    12. --make sure you replace the files and that the file names, both data and logs are identical to the original
    13. ALTER DATABASE bah SET ONLINE
    14. GO



    Now we can see already in the tree of object explorer that the database online and read-write state. There is no need to issue a restore to recovery or anything.

    To verify, we can check the read only state in sys.databases

    1. select is_read_only from sys.databases where [name] = 'bah'
    This will result in 0 meaning the database is read-write

    We now have a backup of a warm-standby database that is used in a log shipping plan.

    About the Author

    Ted Krueger is a SQL Server MVP and has been working in development and database administration for 13+ years. Specialties range from High Availability and Disaster / Recovery setup and testing methods down to custom assembly development for SQL Server Reporting Services. Ted blogs and is also one of the founders of LessThanDot.com technology community. Some of the articles focused on are Backup / Recovery, Security, SSIS and working on SQL Server and using all of the SQL Server features available to create stable and scalable database services. @onpnt
    Social SitingsTwitterLinkedInLTD RSS Feed
    3722 views
    Instapaper

    4 comments

    Comment from: Sankar [Visitor] Email · http://sankarreddy.com/
    Sankar I hadn't thought of this option earlier. good one Ted helped me today.
    03/11/10 @ 10:47
    Comment from: Ted Krueger (onpnt) [Member]
    Ted Krueger (onpnt) :-) Glad it helped. It has saved me a few times from going other directions to get it accomplished.
    03/11/10 @ 13:50
    Comment from: Brian [Visitor] Email
    Brian Hi Ted,
    Wow, it actually worked! Wonder why I couldn't use the copy database wizard on the "Standby / Read-Only".
    01/03/11 @ 15:40
    Comment from: Charles [Visitor] Email
    Charles It won't work when I tested it on a multiple data files warm-standby database. Has anyone tested copy a multiple data files warm-standby database?
    03/13/12 @ 08:01

    Leave a comment


    Your email address will not be revealed on this site.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)