In Lesson 1, you learned about the SQL Server backup process. In this lesson, you will learn how to apply this process to develop a reliable backup strategy that is appropriate for the requirements of your organization. This lesson presents samples of various backup strategies that will help you to develop your own strategy.
After this lesson, you will be able to
- Design an appropriate backup strategy
Estimated lesson time: 30 minutes
There are two overall backup and restore strategies, each with its own strengths and weaknesses:
The primary advantage of using only database backups is simplicity. Backing up is a single operation, normally scheduled at regular intervals. Should a restore be necessary, it can be accomplished easily in one step.
Transaction log backups provide the information necessary to redo changes made after a database backup was performed. They make it possible to back up large production databases at short intervals, as well as to restore a database up to a specific point in time.
CAUTION
Recovery of the active transaction log will be possible only if the transaction log and primary data files are undamaged. For this reason, consider placing the transaction log and primary data files on fault-tolerant disks.
Both of these strategies can be augmented by the use of differential database backups to increase the speed of the backup and restore processes.
Finally, it is possible to perform database backups of individual files or filegroups, segmenting a database backup into smaller backup procedures that can be completed in less time. This may be necessary for very large, busy databases.
When using the database backup strategy, you back up the entire database every time a backup is performed. Figure 8.1 illustrates this backup strategy. Database size and frequency of data modification determine the time and resources involved in implementing a database backup strategy.
Figure 8.1 The database backup strategy
Use database backups if
Consider the following example of a backup plan and the steps you would take to restore your database. Assume the following:
To recover the database, you would restore the database backup from the previous night at 6:00 p.m., overwriting the corrupted version of the database.
The limitation of this approach is that all data modifications that were made since the last database backup at 6:00 p.m. are lost.
NOTE
You may be able to recover changes since the backup of the previous night if the transaction log and the primary data file are not damaged (using the BACKUP LOG statement with the NO_TRUNCATE option). However, if the potential data loss is too great, you should consider implementing a backup strategy that includes periodic transaction log backups.
When using a strategy that combines database backups and transaction log backups, you make complete database backups at less frequent regular intervals. Between database backups, the transaction log is backed up, so that you have a record of all database activities that occurred between database backups. This common backup strategy is illustrated in Figure 8.2.
Figure 8.2 The database and transaction log backup strategy
Restoring a database that has been backed up using a database and transaction log strategy involves two steps. First you must restore the most recent complete database backup. Then you apply all of the transaction log backups that were created since the most recent complete database backup.
Use this backup strategy when you cannot afford to lose changes since the most recent database backup or when you need to be able to restore data to a specific point in time.
Consider the following example of a backup plan and the steps you would take to restore your database. Assume the following:
You would go through the following steps to recover the database:
Applying the transaction log created at the beginning of the restore brings the database back to the state it was in when it was damaged. If you are not able to make a backup of the transaction log before starting the restore, you will be able to restore the database to the state it was in at 12:00 noon.
Figure 8.3 illustrates the differential backup strategy. Use this strategy to augment either a database backup strategy or a database and transaction log backup strategy. Differential backups consist only of the portions of the database that have changed since the last database backup.
Figure 8.3 The differential backup strategy
Recovery using a differential backup requires that you restore the most recent complete database backup and the most recent differential backup. If transaction log backups are also made, only those created since the most recent differential backup need to be applied to fully recover the database. Use this strategy to reduce recovery time if the database becomes damaged.
For example, rather than applying many transaction logs, you would use the most recent differential backup to restore data that has changed since the last complete database backup and then apply only the transaction log backups taken since that differential backup.
Consider the following example of a backup plan and the steps that you would take to restore your database. Assume the following:
You would go through the following steps to recover the database:
The application of the last transaction log backup brings the database back to where it was at the time it was damaged. If you are not able to make a backup of the transaction log before starting the restore then you will be able to restore the database to the state it was in at 9:00 A.M on Wednesday.
Figure 8.4 illustrates the database file backup strategy. The database filegroup strategy works similarly, except that it works with filegroups rather than individual files. When you implement a database file or filegroup backup strategy, you must back up the transaction log as part of the strategy.
Figure 8.4 The database file backup strategy
Use this strategy for very large databases that are partitioned among multiple files. When combined with regular transaction log backups, this technique makes it possible to perform backups when time is limited.
For example, if you have only one hour to perform a database backup that would normally take four hours, you could create the database using four data files, back up only one file each night, and still ensure data consistency. Transaction log backups could be performed at short intervals during the day.
Consider the following example of a backup plan and the steps you would take to restore your database. Assume the following:
You would go through the following steps to recover the database:
The performance that is gained by using this strategy results from the fact that only transaction log events that affect data stored in the failed file need to be applied. In this example, only transactions for File2 made after 1:00 a.m. on Wednesday are applied. If File1 had failed, transaction log backups made after 1:00 a.m. on Tuesday would have been applied. If File3 had failed, transaction log backups made after 1:00 a.m. on Thursday would have been applied.
Consider some of the issues that affect the performance of SQL Server when you back up databases:
There are two approaches administrators can take when planning a backup strategy. They can back up only the database at frequent intervals, or they can back up the database and the transaction logs. The first strategy allows a simple restore of the database in case of data loss but can result in data being lost during the interval between backups. The second strategy may involve more work when restoring data but often can bring your database back to the state it was in before the loss.