SQL Server .BAK files - what's in there exactly?

Posted on 2008-10-10
Last Modified: 2013-12-03
I'm wondering how SQL Server creates its backups.  Does it always put the same table, index, namespace, etc in the same place in the file?  Can normal use or maintenance activity (like defragging, reindexing) radically alter how the .BAK file gets put together?

The reason I'm asking this is because I'm having some issues with a large file (100+GB) and an offsite backup utility.  Here's the current process:
1.  SQL Server makes a backup to local disk.
2.  Backup server copies the .BAK file to its local cache
3.  Backup server compares it to yesterday's backup at block level and records the differences
4.  Differences are uploaded to offsite storage

This system is working great with all our other data, but this one large file is causing some headaches.  At first it can get the daily changes calculated and moved offsite in a few hours, but over a couple months it takes longer and longer until it's taking over 12 hours.  Then we have to start all over and it's a big hassle.

I'm wondering if it has anything to do with the organization of that .BAK file.  I know that the inside of the .MDF where the live DB lives is very dynamic and a single table can get fragmented over hundreds or thousands of places on the physical disk.  If that organization is reflected in the backup, the daily changes could appear to be huge, even if all we did that day was run some maintenance tasks and the amount of data stored remained unchanged.
Question by:neortho
  • 2
  • 2
LVL 12

Expert Comment

Comment Utility
You are correct in that the MSSQL BAK file works poorly with block-level backup schemes.  This is why the Volume Shadow Service (VSS) on W2K3/W2K8 lets SQL Server implement its own native VSS-writer for backup.

Since you are using a 3rd party backup the best approach is probably to avoid doing a full 100GB backup every night, and instead do daily incremental backups of the transaction log, with full backups at a longer interval.

Example of T-SQL to back up the translaction log:

BACKUP LOG MyDatabase TO DISK = 'E:\MSSQL\BACKUPS\MyDatabase_20081010.trn'
WITH INIT, SKIP, NAME='MyDatabase_20081010.trn',
DESCRIPTION='Backup of log for MyDatabase on 2008/10/10'

A full backup will truncate the log.

To restore, reload the main backup as usual, followed by each log backup starting with the oldest:

FROM DISK='E:\MSSQL\BACKUPS\MyDatabase_20081009.trn'
WITH NORECOVERY -- indicate we want to apply another log

FROM DISK='E:\MSSQL\BACKUPS\MyDatabase_20081010.trn'  -- final log

The log backups will be much smaller, containing only the actual changes since the last full backup.

Author Comment

Comment Utility
Thanks for the advice!  I've been meaning to change it to something like that for awhile now.  With all these offsite backup headaches, now might be a good time to go ahead and do it.

I'm still curious as to which DB operations can cause the biggest block level differences from day to day.  Are there any good reference sites you're aware of?  I spent a lot of time searching on Google but couldn't get the results narrowed down enough.
LVL 12

Accepted Solution

Gideon7 earned 500 total points
Comment Utility
The .BAK file is a sequential data stream, not a fixed random-access file.  Adding one block of extra data near the beginning of the backup will shove every foillowing block down wrt to previous .BAK file.  This will cause a low-level block-level comparator to mismatch on every single block between the old and new .BAK files, except where they are coincidetally the same, such as two blocks that happen to both be all-zero.

Author Closing Comment

Comment Utility
Exactly what I was looking for, and great advice for altering my backup set.  

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now