• subscribe

Unused Secret Weapon: COPY_ONLY Backups


Posted @ 11/17/2011 12:21 PM By Michael K. Campbell

 

[UPDATE: This post contains INCORRECT content in terms of the scope/nature of the problems described. While COPY_ONLY backups ARE useful to protect against ‘extra’/’accidental’ backups, this post incorrectly targets TLOG backups instead of DIFF backups. See more about why this is incorrect here.]

COPY_ONLY backups were a great addition to SQL Server 2005 (and up). Without them, it was all to easy for DBAs, devs, and SysAdmins to create a ‘backup’ for dev/testing purposes which would actually, silently, break the Log Chain and put production data in severe risk.

In other words, if:
a) A Non COPY_ONLY backup was made,
b) A new or scheduled FULL/DIFFERENTIAL backup hadn’t yet been made, and
c) A database disaster occurred

Then DBAs _HAD_ to have that non-copy only backup on hand or they wouldn’t be able to recover from the disaster properly – because they’d be missing the proper baseline from which to begin applying transaction log backups.

What’s So Secret?

As I’ve mentioned before, the notion of breaking the log chain can be a bit counter-intuitive. (Seriously, backing something up can actually BREAK it? That’s not something you expect to find with many systems. Yet, if you understand what’s going on and WHY the log file is so essential to SQL Server, then the fact that you CAN break the log chain becomes something that is not only second nature – but which you’re constantly vigilant against.)

Yet, while I think that increasing numbers of DBAs (including even reluctant DBAs) have a decent understanding of the benefits of COPY_ONLY backups in terms of protecting the log chain, I think that the overwhelming majority of DBAS don’t realize that log file backups can ALSO be used against COPY_ONLY backups as well.

Therefore, since a picture is worth a thousand words, here’s a diagram that I think increasing numbers of DBAs understand and get – in terms of why COPY_ONLY backups are so important.

NonCOPYONLY

Figure 1: Why it’s so important to use COPY_ONLY Backups (or keep non-COPY_ONLY backups on hand until next FULL/DIFF backup).

On the other hand, while the benefits of COPY_ONLY backups are understood from the sole standpoint of PROTECTING the log chain for a PRODUCTION database, Figure 2 shows that there are also some other, very important, benefits that come from COPY_ONLY backups as well.

COPYONLY

Figure 2: With COPY_ONLY backups, you can easily set up MULTIPLE copies that can remain synchronized with Log File Backups.

And this benefit, in turn, is the secret weapon – as we’ll see in a couple of upcoming posts because this can have HUGE implications when it comes to various types of high-availability situations or even in terms of disaster recovery purposes as well.

And, the fact that DBAs rarely use this benefit of COPY_ONLY databases is really what makes it an Unused Secret Weapon – as we’ll see in subsequent posts.

Related Content:

Comments

Add A Comment
  • Posted @ November 28, 2011 01:27 PM by Michael K. Campbell

    @rxmoore No worries on the cross post. I'm obviously pretty bummed that I've a) presented bad info here, b) carried along an INCORRECT understanding of the basics for so long. (I could swear I've been burned by t-log problems here in the past - and have, accordingly, always assumed that they were at risk of this issue. And so, this is just one of those cases where an incorrect assumption (on my part) can slowly blossom over time into almost paranoia - where I've always stayed SAFE by being a bit 'extra' cautious even though that extra caution wasn't warranted.)

    So, thanks a ton for calling me out on this - I really appreciate learning that I was wrong. (I just wish I had known BEFORE this post ;) )

    Still trying to figure out the best way to salvage this post and the basics of this thought/cautionary-tale.

    --Mike

  • Posted @ November 28, 2011 01:07 PM by rxmoore

    I guess I have to applogize as well as my last post overlapped yours. I appreciate the fact that you tested out the scenarios and have come to the same conclusion. Thanks much for your update.

  • Posted @ November 28, 2011 01:03 PM by rxmoore

    I'm sorry, but I still have to disagree and point back to my original post. It doesn't matter that you have taken a 2nd full backup or several full backups nor does it matter if a 3rd party utility was used. It also has nothing to do with whether or not that backup has been lost. Any transaction logs taken after any subsequent full backup can still be applied to any previous full backup as if the other full backup(s) were never taken as long as all of the logs between the 1st full backup and the time you need to recover to still exist. The pertains to only transaction logs and can't be done using differential backups as those are directly tied to the previous non-copy only full backup. You can take Nightly full backups every night and hourly transaction log backups during the day and you could restore Sunday nights full backup and every hourly log through Friday and not have any issues with LSNs.

    The reference to Pauls blog is completely different as it's using nothing but full backups and differential backups. It has nothing to do with transaction logs and therefore the example doesn't apply to this scenario. I've also included an update from Pauls blog as noted below.

    [Edit: In the initial version of this post, the DBA's backup strategy included log backups. I went through a couple of versions of this post before settling on full + diffs, but I forgot to remove the reference to log backups. In the first comment, Mark House correctly points out that an accidental full backup doesn't prevent a DBA with a complete log backup chain from recovering to any point in time. Apologies for the confusion!]

    Please note that he is saying the exact same thing that I have already pointed out.

  • Posted @ November 28, 2011 12:53 PM by Michael K. Campbell

    Sigh.

    No sooner than had I posted my previous comment did I notice this disclaimer in Paul's post:
    [Edit: In the initial version of this post, the DBA's backup strategy included log backups. I went through a couple of versions of this post before settling on full + diffs, but I forgot to remove the reference to log backups. In the first comment, Mark House correctly points out that an accidental full backup doesn't prevent a DBA with a complete log backup chain from recovering to any point in time. Apologies for the confusion!]

    Which, frankly, is news to me - as I could swear I've been burned by this in the past (i.e., with transaction logs).

    Even worse is that I spent some decent time testing this out in two test environments to make sure that my statements about the use of log-files was correct. Sadly, I just tested that FULL/COPY_ONLY + TLOG backups worked - which was a moot point (as they'll always work). What I should have tested was whether they'd work WITHOUT the COPY_ONLY test going on.

    Or, stated differently, I was WRONG.

    So, I'll have to post a follow-up/correction.

  • Posted @ November 28, 2011 12:37 PM by Michael K. Campbell

    Thanks for the comments everyone. I think I'll address them a bit more with a follow-up post - because this stuff IS confusing. And, the peril REALLY is there.

    The big thing that I think you are all missing is that you have to 'lose' access to that additional/secondary FULL backup. In my previous post about this problem the assumption was that some 3rd party backup solution was making this FULL (or differential) backup for you - and you didn't 'know' about it - or wouldn't remember it in a crisis. In which case, any log files applied after that backup was taken would NOT be able to be applied.

    Same thing in this case, IF you or a developer or SOMEONE/SOMETHING else takes a 'test' backup in the middle of the day and you NO LONGER have access to that file/backup, then you're dead in the water and you're NOT able to restore t-logs after that point until the next FULL/DIFFERENTIAL backup when the LSN is re-seeded and the backup chain is restarted.

    Again, a bit counter-intuitive - and I potentially (sadly) muddled that a bit with my diagram by NOT specifically calling out that the 2ndary backup has to be gone/missing. BUT, the key point is still the same: you can't apply T-Log backups to a FULL/DIFFERENTIAL backup after a non-COPY_ONLY backup has been made. (If you have access to that non-COPY_ONLY backup, then you're FINE as you can use it. BUT if it's GONE and you no longer have access to it, you'll be hating life.)

    Paul Randall covers a pretty technical example of this here:
    http://sqlskills.com/BLOGS/PAUL/post/BACKUP-WITH-COPY_ONLY-how-to-avoid-breaking-the-backup-chain.aspx

    I think I'll follow up in a day or so with a more simple example that readers can try for themselves in order to be able to better see this problem in action.

    Regards,

    --Mike

You must log on before posting a comment.

Are you a new visitor? Register Here