Blog Post

One-stop Shopping for Backups

,

superhero_supply

First, let me say that yes, I’m aware of Ola Hallengren’s excellent set of maintenance scripts, including those for doing backups. Truly awesome stuff – but not exactly what I wanted in a backup solution. What I’ve built is not meant to improve upon, replace, or in any way make a statement about Ola’s scripts. This is my solution that I built to address my specific needs. I’m sharing it with the three people who read my blog, just in case they might find it useful.

My team is responsible for dozens of SQL Server instances. Some of them we’ve built, some we’ve inherited, some just appeared one day out of thin air. We try to standardize our builds, but for those servers that just fall into our laps, it’s hard to do. As a result, there’s a lot of inconsistencies in how maintenance tasks are done. Some backup jobs use stored procedures. Some of them issue BACKUP commands directly from the job step. Some use maintenance plans, which makes me ill.

I wanted, OK, needed, a way to quickly configure backups on a server, something that would cover 99% of our backup needs with little or no configuration. I needed a “set it and forget it” solution. Specifically, some of the things I wanted were:

  • something generic that could be dropped onto a new server, starting backups immediately
  • something flexible enough to cover 99% of our needs, but also handle the exceptions
  • something maintenance-free
  • something robust enough to automatically fix simple problems, like a missing directory
  • something that uses native SQL features so that I can enhance it over time
What I came up with is sp_BackupDatabases. One stored procedure with a flexible array of parameters that can be called from a SQL Agent job to handle all of my backup needs. In practice, I’m actually using two jobs – one for log backups, one for full and differential backups. Why two jobs? I like to do my transaction log backups in 5-minute intervals. If I’m using just one job for backups, and a backup takes a long time to complete, for example a full backup that takes an hour, I won’t be getting log backups during that hour.

The full/diff backup job calls the stored procedure in this way:

EXECUTE dbo.sp_BackupDatabases
 @backup_type = 'D',    -- Do full backups only
 @full_backup_frequency = 'W'; -- Do a full backup each week (starting on Sunday)
EXECUTE dbo.sp_BackupDatabases
 @backup_type = 'I',    -- Do differential backups only
 @diff_backup_frequency = 'D'; -- Do a differential backup each day

The log backup job calls it with slightly different parameters, giving me a log backup of each database every 5 minutes:

EXECUTE dbo.sp_BackupDatabases
 @backup_type = 'L';    -- Do log backups only

All of the options are documented in the comments of the code. I plan to keep adding new features to this as I find the need for them. I’m also open to suggestions on how to improve it, understanding that it’s not meant to be the end-all backup solution, it’s just something that works for me and I’m sharing it with you.

Thoughts? Comments? Criticism? Let me know by posting a comment…

The post One-stop Shopping for Backups appeared first on RealSQLGuy.

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating