2. Differential backup
While
a full backup represents the most complete version of the database,
performing full backups on a nightly basis may not be possible (or
desirable) for a variety of reasons. If only a small percentage of
this database changes on a daily basis, the merits of performing a full
nightly backup are questionable, particularly considering the storage
costs and the impact on users during the backup.
A differential backup, an example of which is shown here, is one that includes all database changes since the last full backup:
-- Differential Backup to Disk
BACKUP DATABASE [AdventureWorks2008]
TO DISK = N'G:\SQL Backup\AdventureWorks-Diff.bak'
WITH DIFFERENTIAL, INIT
A classic backup design is one in which a full backup is performed weekly, with nightly differential backups. Figure 2 illustrates a weekly full/nightly differential backup design.
Compared
to nightly full backups, a nightly differential with a weekly full
backup offers a number of advantages, primarily the speed and reduced
size (and therefore storage cost) of each nightly differential backup.
However, there comes a point at which differential backups become
counterproductive; the further from the full backup, the larger the
differential, and depending on the rate of change, it may be quicker to
perform a full backup. It follows that in a differential backup design,
the frequency of the full backup needs to be assessed on the basis of
the rate of database change.
When restoring a differential backup, the corresponding full backup, known as the base
backup, needs to be restored with it. In the previous example, if we
needed to restore the database on Friday morning, the full backup from
Sunday, along with the differential backup from Thursday night, would
be restored, as in this example:
-- Restore from Disk. Leave in NORECOVERY state for subsequent restores
RESTORE DATABASE [AdventureWorks2008]
FROM DISK = N'G:\SQL Backup\AdventureWorks.bak'
WITH NORECOVERY, REPLACE
GO
-- Complete the restore process with a Differential Restore
RESTORE DATABASE [AdventureWorks2008]
FROM DISK = N'G:\SQL Backup\AdventureWorks-Diff.bak'
GO
Here, we can see the full backup is restored using the WITH NORECOVERY option. This leaves the database in a recovering state, and thus able to restore additional backups. We follow the restore of the full backup with the differential restore.
As
you'll recall from the restore of the full backup shown earlier,
without transaction log backups, changes made to the database since the
differential backup will be lost.