This post is part of a series called “TITLO – Things I learned teaching others“
Have you ever wondered if your database backups are taking too long to back up and that, perhaps, there is a way to make them complete quicker?
You haven’t? Firstly, consider why you would want backups to complete faster.
Why you want faster backups
- A faster backup can often mean a shorter maintenance window. In some cases, you may simply not have a choice – if your off-peak hours are only 12-4 AM, you need to find a way to complete your backup in those 4 hours.
- A faster backup can some times put more strain on the server during off-peak hours, but the trade-off is that it means less strain during working hours
- There is a reduced risk of data-loss. If your backup takes 12 hours to complete, remember that you are relatively unprotected for those 12 hours until the backup finishes.
Now that we’ve established that you want a faster backup, let’s look at some ways of accomplishing this.
Basic ways to make backups go faster
Turn on backup compression
This option has been available even in Standard edition since SQL Server 2008 R2. It allow SQL Server to compress the data as it writes the backup. This gives you a smaller and more manageable backup file. But more importantly, a compressed backup actually finishes faster. Though this may sound counter-intuitive, think of it this way: a smaller file means less I/O. SQL Server uses the CPU for compression, while nearly all backups are usually bottle-necked at either disk or network. Because there are fewer bytes to write, there is less contention at the disk or network endpoint and this leads to a shorter completion time!
Since compression requires significant CPU usage, make sure you have enough spare CPU capacity during this period.
Read more about it on MSDN here: https://msdn.microsoft.com/en-us/library/bb964719.aspx
Striping backups across multiple files
Many people aren’t aware that you can specify multiple files as your backup destination. SQL Server will split your backup across these files, which can often lead to much faster backups. Depending on your RAID setup, you may see a significant boost with multiple files even on the same drive; but for best performance, use one file per physical volume or LUN. If you are backing up across the network, use one file per NIC.
Keep in mind that you will need all the files from that backup in order to restore your database.
For more information, read this excellent guide by Thomas LaRock: https://www.mssqltips.com/sqlservertip/1941/striping-sql-server-database-backups/
Advanced options
If you’ve exhausted the basic options, then you can try changing advanced settings such as MaxTransferSize, BufferCount and BlockSize. These are truly YMMV settings, so no single configuration is known to improve performance for every one. Take your time to figure out how these work and what will work best in your own environment.
A word of warning here: MaxTransferSize and BufferCount determine how much memory is required for the backup operation. Don’t go crazy with these settings or you could run out of memory!
Another tip: these options are also available for the RESTORE command. Test them to see if you can improve restore performance; after all, that is exactly when you want things to go as fast as possible!
Here’s a slightly dated but still relevant post on these settings: http://henkvandervalk.com/how-to-increase-sql-database-full-backup-speed-using-compression-and-solid-state-disks