Author: way0utwest

  • Restoring a Copy Only Backup–#SQLNewBlogger

    Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

    There was a question posted recently at SQLServerCentral about whether a copy only backup could be restore with a transaction log backup from a database. I was positive this could, but decided I needed to repro and test for someone as there wasn’t a good BOL reference.

    The Tests

    Here’s what I did. First, I created a table in a database. I often do this and drop in messages to allow me to track the progress of backups and restores. This post follows my progress.

    The Backups

    Here’s my basic script:

    CREATE TABLE logger(msg VARCHAR(200), msgdate DATETIME DEFAULT GETDATE())
    
    INSERT logger (msg) SELECT 'pre full backup'

    Next, I made a backup and added a message.

    INSERT logger (msg) SELECT 'pre-log backup 1'
    BACKUP LOG nba TO disk = 'nba_1.trn'
    INSERT logger (msg) SELECT 'log backup 1 complete'

    Once this is done, I’m in a state that I expect. A normal full backup, a normal log backup, and some data to help me track where I am.

    Now let’s make a copy only backup.

    INSERT logger (msg) SELECT 'pre copy-only backup '
    BACKUP DATABASE nba TO DISK  = 'nba_copy.bak' WITH COPY_ONLY
    INSERT logger (msg) SELECT 'copy-only backup complete'

    This now means I have an open log sequence in the first log backup (post full backup) and a few log records since then. Some of these are inside the copy only backup.

    Now let’s add more data and make a new, regular, log backup.

    INSERT logger (msg) SELECT 'pre-log backup 2'
    BACKUP LOG nba TO disk = 'nba_2.trn'
    INSERT logger (msg) SELECT 'log backup 2 complete'

    It’s at this point that I have this sequence:

    • Full backup
    • Log backup
    • Copy-Only Full backup
    • Log backup

    The Restore

    What I want to test is can I restore the Copy-Only backup and a log backup? I think I can, so let’s do that. First, restore from the copy-only backup, using the MOVE option.

    USE [master]
    RESTORE DATABASE [NBA2] 
    FROM  DISK = N'D:\SQLServerBackup\MSSQL13.SQL2016\MSSQL\Backup\nba_copy.bak' 
    WITH  FILE = 1,  
          MOVE N'NBA' TO N'E:\SQLServer\MSSQL13.SQL2016\MSSQL\Data\NBA2.mdf',  
          MOVE N'NBA_log' TO N'E:\SQLServer\MSSQL13.SQL2016\MSSQL\Data\NBA2_log.ldf',  
          MOVE N'nba_mo_file1' TO N'E:\SQLServer\MSSQL13.SQL2016\MSSQL\Data\NBA2_mo',  
          MOVE N'nba_mo_file2' TO N'E:\SQLServer\MSSQL13.SQL2016\MSSQL\Data\NBA2_mo2'
    ,  NOUNLOAD,  STATS = 5
    , NORECOVERY

    Tip: Always use NORECOVERY

    Now let’s try to restore the log.

    RESTORE LOG NBA2 FROM DISK = 'nba_2.trn' WITH NORECOVERY
    
    RESTORE DATABASE nba2 WITH RECOVERY

    This works:

    2017-12-06 17_57_56-SQLQuery2.sql - (local)_SQL2016.master (PLATO_Steve (63))_ - Microsoft SQL Serve

    That should prove things. Let’s check the logger table.

    2017-12-06 18_00_45-SQLQuery2.sql - (local)_SQL2016.NBA2 (PLATO_Steve (63))_ - Microsoft SQL Server

    That’s what we expect. The final message after log backup2 wasn’t captured in our backup files.

    Copy Only Backups

    What is a copy only backup? If we check the Copy-Only Backups page, we find that this is a regular backup in and of-itself, but it has the restriction that it cannot be used with differential backups. This also doesn’t change the differential bitmap, so that any differentials that are made ignore this backup and go back to include data changed since the last “normal” full backup.

    SQLNewBlogger

    Understanding backup and recovery is critical for a data professional. I’d say this is the most important skill, and it’s always worth writing about. Spend a few minutes reviewing scenarios and creating some posts like this to show you understand how the system works.

  • Back to Work

    It seems like it’s been a long time since I wrote any SQL code or did any work. Two weeks ago I was in the UK for SQL in the City, which was a lot of prep work when I arrived with little actual work on the site or with customers. The few days after the broadcast involved meetings and getting ready for the annual Redgate Christmas Party and company awards. I was hosting, so I had to practice and prep for the night. It went well, with everyone indulging me with an on-stage selfie:

    IMG_3405

    Last week was another trip, my final of the year, but a good one. I was luck to spend a week unwired with my wife in Athens. We enjoyed the time, and got to relax without commitments, something that I don’t do often. We didn’t do much except enjoy the time and sights.

    Now it’s back to work after Christmas. I’m ready to go, though that might have something to do with my body still being on GMT time, but in any case, I’m ready to fire up SSMS and do some work.

    Merry Christmas, Happy Holidays, and Happy New Year to everyone.

  • Holiday

    I’m off on vacation this week, enjoying Athens with my wife. I’ll be unlikely to respond to communications during this time.

    Have a great week and I’ll be back after Christmas.

  • Making Choices

    I wrote about shutting down some travel for the foreseeable future. Its been a long couple of years for me. If you look at my speaking schedule, I’ve presented at an average of 20+ events for the last few years. This year was a few less, but I’ve had more travel outside of that. By the end of the year, I’ll have spent 9 weeks outside of the US. While some of that is vacation, it’s a lot of time away from home. In addition to the events, I’ve had other travel for work that doesn’t appear there, as well as some vacation time for volleyball (my daughter competes) and family time.

    Lately I’ve been seeing all the tweets and posts about SQL Bits 2018. I won’t be going, which is sad for me. I love the event, it’s my favorite and my wife would love to go with me sometime, maybe in 2018. As I see speakers submitting and the excitement building, it feels like I should just send in a session, but I realize I need to stick with my decision.

    Making choices is hard. For a couple years I’ve been saying  I need to travel a bit less, but I haven’t done a good job of slowing down my travel. I find that I’ve done that with other work demands in the past (and personal ones), and I see plenty of other people doing the same thing. This fall I made the commitment that I’d limit travel next year, and I talked to my manager as well. We agreed on a plan, and she’s holding me to the plan, even when I get a bit excited about new events.

    My current job allows me some flexibility in how I work, but in past jobs I’ve had similar ways that I could change my job, if I made the effort do so. Your employer will ask a lot of you, and often keep asking. I’ve certainly had some bosses that were unreasonable and demanded too much, but most were willing to work with me. It took me a number of years to learn to push back and say no, as well as learn to make choices among different situations. I find if I don’t make choices, I’ll tend to over commit and under deliver, while being disappointed in myself that I couldn’t make it all work. Or I become a little burned out, spending too much time trying to keep all the balls in the air and running myself ragged.

    Balance is important, not only between work and life, but also within work. I find that the more I make choices and stick with them, the better adjusted I am in all of my life. I’m a little sad that I won’t speak at as many events next year, but I’ll pick and choose a few, and hopefully get some things done at work that I’ve been putting off. I’m also hoping that life will seem less chaotic and busy in general, with a little more time to relax and smell the sawdust.

    Steve Jones

    The Voice of the DBA Podcast

    Listen to the MP3 Audio ( 4.3MB) podcast or subscribe to the feed at iTunes and Libsyn.