You are on page 1of 13

SQL Server Full Backups

Overview
The most common types of SQL Server backups are complete or full backups, also known as database
backups. These backups create a complete backup of your database as well as part of the transaction log,
so the database can be recovered. This allows for the simplest form of database restoration, since all of the
contents are contained in one backup.
Explanation
A full backup can be completed either using T-SQL or by using SSMS. The following examples show you
how to create a full backup.

Create a full backup of the AdventureWorks database to one disk file


T-SQL

BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.BAK'


GO
SQL Server Management Studio

Right click on the database name


Select Tasks > Backup
Select "Full" as the backup type
Select "Disk" as the destination
Click on "Add..." to add a backup file and type "C:\AdventureWorks.BAK" an click "OK"
Click "OK" again to create the backup

SQL Server Differential Backups


Overview
Another option to assist with your recovery is to create "Differential" backups. A "Differential" backup is a
backup of any extent that has changed since the last "Full" backup was created.

Explanation
The way differential backups work is that they will backup all extents that have changed since the last full
backup. An extent is made up of eight 8KB pages, so an extent is 64KB of data. Each time any data has
been changed a flag is turned on to let SQL Server know that if a "Differential" backup is created it should
include the data from this extent. When a "Full" backup is taken these flags are turned off.
So if you do a full backup and then do a differential backup, the differential backup will contain only the
extents that have changed. If you wait some time and do another differential backup, this new differential
backup will contain all extents that have changed since the last full backup. Each time you create a new
differential backup it will contain every extent changed since the last full backup. When you go to restore
your database, to get to the most current time you only need to restore the full backup and the most recent
differential backup. All of the other differential backups can be ignored.
If your database is in the Simple recovery model, you can still use full and differential backups. This does
not allow you to do point in time recovery, but it will allow you to restore your data to a more current point
in time then if you only had a full backup.
If your database is in the Full or Bulk-Logged recovery model you can also use differential backups to
eliminate the number of transaction logs that will need to be restored. Since the differential will backup all
extents since the last full backup, at restore time you can restore your full backup, your most recent
differential backup and then any transaction log backups that were created after the most recent differential
backup. This cuts down on the number of files that need to be restored.

Create a differential backup of the AdventureWorks database to one disk file


T-SQL

BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.DIF' WITH


DIFFERENTIAL
GO
SQL Server Management Studio

Right click on the database name


Select Tasks > Backup
Select "Differential" as the backup type
Select "Disk" as the destination
Click on "Add..." to add a backup file and type "C:\AdventureWorks.DIF" and click "OK"
Click "OK" again to create the backup

SQL Server Transaction Log Backups

Overview
If your database is set to the "Full" or "Bulk-logged" recovery model then you will be able to issue
"Transaction Log" backups. By having transaction log backups along with full backups you have the ability
to do a point in time restore, so if someone accidently deletes all data in a database you can recover the
database to the point in time right before the delete occurred. The only caveat to this is if your database is
set to the "Bulk-logged" recovery model and a bulk operation was issued, you will need to restore the entire
transaction log.
Explanation
A transaction log backup allows you to backup the active part of the transaction log. So after you issue a
"Full" or "Differential" backup the transaction log backup will have any transactions that were created after
those other backups completed. After the transaction log backup is issued, the space within the transaction
log can be reused for other processes. If a transaction log backup is not taken, the transaction log will
continue to grow.
A transaction log backup can be completed either using T-SQL or by using SSMS. The following examples
show you how to create a transaction log backup.

Create a transaction log backup of the AdventureWorks database to one disk file
T-SQL

BACKUP LOG AdventureWorks TO DISK = 'C:\AdventureWorks.TRN'


GO
SQL Server Management Studio

Right click on the database name


Select Tasks > Backup
Select "Transaction Log" as the backup type
Select "Disk" as the destination
Click on "Add..." to add a backup file and type "C:\AdventureWorks.TRN" and click "OK"
Click "OK" again to create the backup

SQL Server Partial Backups

Overview
A new option is "Partial" backups which was introduced with SQL Server 2005. This allows you to backup
the PRIMARY filegroup, all Read-Write filegroups and any optionally specified files. This is a good option if
you have Read-Only filegroups in the database and do not want to backup the entire database all of the
time.
Explanation
A Partial backup can be issued for either a Full or Differential backup. This can not be used for Transaction
Log backups. If a filegroup is changed from Read-Only to Read-Write it will be included in the next Partial
backup, but if you change a filegroup from Read-Write to Read-Only you should create a filegroup backup,
since this filegroup will not be included in the next Partial backup.
A partial backup can be completed only by using T-SQL. The following examples show you how to create a
partial backup.

Create a partial backup of the TestBackup database


For this example I created a new database called TestBackup that has three data files and one log file. Two
data files are the PRIMARY filegroup and one file is in the ReadOnly filegroup. The code below shows how to
do a partial backup.
T-SQL
Create a full partial backup

BACKUP DATABASE TestBackup READ_WRITE_FILEGROUPS


TO DISK = 'C:\TestBackup_Partial.BAK'
GO
Create a differential partial backup

BACKUP DATABASE TestBackup READ_WRITE_FILEGROUPS


TO DISK = 'C:\TestBackup_Partial.DIF'
WITH DIFFERENTIAL
GO

SQL Server Filegroup Backups


Overview
In addition to doing "File" backups you can also do "Filegroup" backups which allows you to
backup all files that are in a particular filegroup. By default each database has a PRIMARY
filegroup which is tied to the one data file that is created. You have an option of creating
additional filegroups and then placing new data files in any of the filegroups. In most cases
you will probably only have the PRIMARY filegroup, so this is topic is not relevant.

Explanation
As mentioned above you can back up each filegroup individually. The one advantage of
using filegroup backups over file backups is that you can create a Read-Only filegroup which
means the data will not change. So instead of backing up the entire database all of the
time you can just backup the Read-Write filegroups.
A filegroup backup can be completed either using T-SQL or by using SSMS.

Create a filegroup backup of the TestBackup database


For this example I created a new database called TestBackup that has three data files and
one log file. Two data files are the PRIMARY filegroup and one file is in the ReadOnly
filegroup. The code below shows how to do a filegroup backup.
T-SQL
BACKUP DATABASE TestBackup FILEGROUP = 'ReadOnly'
TO DISK = 'C:\TestBackup_ReadOnly.FLG'
GO
SQL Server Management Studio

Right click on the database name


Select Tasks > Backup
Select either "Full" or "Differential" as the backup type
Select "Files and filegroups"
Select the appropriate filegroup and click "OK"

Select "Disk" as the destination


Click on "Add..." to add a backup file and type "C:\TestBackup_ReadOnly.FLG" and
click "OK"
Click "OK" again to create the backup and repeat for other filegroups

SQL Server File Backups

Overview
Another option for backing up your databases is to use "File" backups. This allows you to backup each file
independently instead of having to backup the entire database. This is only relevant when you have created
multiple data files for your database. One reason for this type of backup is if you have a very large files and
need to back them up individually. For the most part you probably only have one data file, so this is option
is not relevant.
Explanation
As mentioned above you can back up each data file individually. If you have a very large database and have
large data files this option may be relevant.
A file backup can be completed either using T-SQL or by using SSMS. The following examples show you
how to create a transaction log backup.

Create a file backup of the TestBackup database


For this example I created a new database called TestBackup that has two data files and one log file. The
two data files are called 'TestBackup' and 'TestBackup2'. The code below shows how to backup each file
separately.
T-SQL

BACKUP DATABASE TestBackup FILE = 'TestBackup'


TO DISK = 'C:\TestBackup_TestBackup.FIL'
GO
BACKUP DATABASE TestBackup FILE = 'TestBackup2'
TO DISK = 'C:\TestBackup_TestBackup2.FIL'
GO
SQL Server Management Studio

Right click on the database name


Select Tasks > Backup
Select either "Full" or "Differential" as the backup type
Select "Files and filegroups"
Select the appropriate file and click "OK"

Select "Disk" as the destination


Click on "Add..." to add a backup file and type "C:\TestBackup_TestBackup.FIL" and click "OK"
Click "OK" again to create the backup and repeat for other files

You might also like