Skip to content

SQL Server Backup strategy for various scenarios

    SQL Server backups, in itself, is a vast subject; so vast, there are multiple books written about them. In this article, however, we are going to focus on the types of backups that are available to us, and understand how to pick what we need, and what aspects we base that decision on. This understanding would, in turn, help us decide our backup-and-restore strategy.

    Following are the most common types of backups available in SQL Server:

    1. Full
    2. Differential
    3. Transaction log
    4. Tail Log backup

    There are other backup types available as well:

    1. Copy-only backup
    2. File backups
    3. Partial backups.

    Full backups

    A full backup, as the name implies, backs up everything. It is the foundation of any kind of backup. This is a complete copy, which stores all the objects of the database: Tables, procedures, functions, views, indexes etc. Having a full backup, you will be able to easily restore a database in exactly the same form as it was at the time of the backup.

    A full backup creates a complete backup of the 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 single backup.

    A full backup must be done at least once before any of the other types of backups can be run—this is the foundation for every other kind of backup.

    How to create full database backup using T-SQL

    The BACKUP DATABASE is the command used to create a full database backup. It requires at least two input parameters: the database name and the backup device.

    Following is the example for a full database backup to be stored in a device:

    To DISK=’f:\PowerSQL\SQLShackDemoATC.BAK’
    WITH FORMAT,      
    MEDIANAME = ‘Native_SQLServerBackup’,      
    NAME = ‘Full-SQLShackDemoATC backup’;

    Full Database Backup to Multiple files

    Sometimes in some instances, we’re limited by the amount of space we have. What if we wanted to backup an entire database that is huge? Or what if we have to copy the backup files over the network? It might be a good idea in these cases to split the backup into smaller chunks—each being a separate file.

    TO DISK = ‘f:\PowerSQL\SQLShackDemoATC_1.BAK’,
    DISK = ‘f:\PowerSQL\SQLShackDemoATC_2.BAK’,
    DISK = ‘f:\PowerSQL\SQLShackDemoATC_3.BAK’,
    DISK = ‘f:\PowerSQL\SQLShackDemoATC_4.BAK’ WITH INIT,
    NAME = ‘FULL SQLShackDemoATC backup’, STATS = 5

    If you’d like to create a mirror copy of the backup file:

    1234BACKUP DATABASE ProdSQLShackDemo TO DISK = ‘F:\PowerSQL\ProdSQLShackDemo_1.BAK’MIRROR TO DISK =  ‘F:\PowerSQL\ProdSQLShackDemo_2.BAK’WITH FORMAT

    You can, in fact, have up to three mirror copies:

    1234567BACKUP DATABASE ProdSQLShackDemo
    TO DISK = ‘F:\PowerSQL\ProdSQLShackDemo_1.BAK’
    MIRROR TO DISK =  ‘F:\PowerSQL\ProdSQLShackDemo_2.BAK’
    MIRROR TO DISK =  ‘F:\PowerSQL\ProdSQLShackDemo_3.BAK’
    MIRROR TO DISK =  ‘F:\PowerSQL\ProdSQLShackDemo_4.BAK’

    Differential Backups

    A differential database backup is the superset of the last full backup and contains all changes that have been made since the last full backup. So, if there are very few transactions that have happened recently, a differential backup might be small in size, but if you have made a large number of transactions, the differential backup could be very large in size. 

    As a differential backup doesn’t back up everything, the backup usually runs quicker than a full backup. A differential database backup captures the state of the changed extents at the time that backup was created. If you create a series of differential backups, a frequently-updated database is likely to contain different data in each differential. As the differential backups increase in size, restoring a differential backup can significantly increase the time that is required to restore a database. Therefore, it is recommended to take a new full backup, at set intervals, to establish a new differential base for the data.

    Differential backups save storage space and the time it takes for a backup. However, as data changes over time, the differential backup size also increases. The longer the age of a differential backup and larger the size and at some point in time it may reach the size of the full backup. A large differential backup loses the advantages of a faster and smaller backup as it requires the full backup to be restored before restoring the recent differential backup. Typically, we would restore the most recent full backup followed by the most recent differential backup that is based on that full backup.

    How to create Differential database backup using T-SQL

    The BACKUP DATABASE command is used with the differential clause to create the differential database backup. It requires three parameters:

    1. Database name
    2. Backup device
    3. The DIFFERENTIAL clause

    For example,

    12345BACKUP DATABASE [SQLShackDemoATC]  
    To DISK=’f:\PowerSQL\SQLShackDemoATC_Diff.BAK’  
    MEDIANAME = ‘Native_SQLServerDiffBackup’,    
    NAME = ‘Diff-SQLShackDemoATC backup’;

    Transaction Log Backup

    The log backup, as its name implies, backs up the transaction logs. This backup type is possible only with full or bulk-logged recovery models. A transaction log file stores a series of the logs that provide the history of every modification of data, in a database. A transaction log backup contains all log records that have not been included in the last transaction log backup.

    It allows the database to be recovered to a specific point in time. This means that the transaction log backups are incremental and differential backups are cumulative in nature. If you want to restore the database to a specific point in time, you need restore a full, recent differential, and all the corresponding transaction log records which are necessary to build the database up to that specific point, or to a point very close to the desired point in time, just before the occurrence of the accident that resulted in the data loss. This series of modifications is contained and maintained using LSN (Log Sequence Number) in the log chain. A log backup chain is an unbroken series of logs that contain all the transaction log records necessary to recover a database to a point in time. A log chain always starts with a full database backup and continues until for reason it breaks the chain (for example, changing the recovery model of database to simple, or taking an extra full backup), thus by preventing log backups from being taken on the database until another full (or differential) backup is initiated for that database.

    How to create Transactional log backup using T-SQL

    The BACKUP LOG command is used to backup the transaction log. It requires the database name, the destination device and the TRANSACTION LOG clause to initiate the transaction log backup.

    123456BACKUP LOG [SQLShackDemoATC]  
    To DISK=’f:\PowerSQL\SQLShackDemoATC_Log.trn’  
    WITH   MEDIANAME = ‘Native_SQLServerLogBackup’,    
    NAME = ‘Log-SQLShackDemoATC backup’;GO

    Tail log backups

    In the event of a failure, when you need the database to get back up and running, and the database is operating in FULL or BULK_LOGGED recovery model, it’s always easy to start the recovery operation and start restoring the backups. But before that, the first action to be taken after the failure is what is called as a tail log backup of the live transaction log.

    This is an intermediate step that we need to take before we start the restoration. This process is called tail log backup restoration.

    1234567USE master;
    — create a tail-log backup
    TO DISK = ‘f:\PowerSQL\SQLShackDemoATCTailLog.log’

    The WITH CONTINUE_AFTER_ERROR clause will force SQL Server to store the log file, even though it’s generating an error.

    Copy_Only backup

    A copy-only backup is a special type of full backup, which is independent of the conventional sequence of backups. The difference between copy-only and a full backup is that a copy-only backup doesn’t become a base for the next differential backup.

    A full backup works on all database recovery models. Copy-only backup, on the other hand, is applicable only to a full or bulk-logged recovery models. The restoration of a copy-only backup is no different than a normal restoration process.

    Performing the copy-only backup is pretty simple. The syntax would look something like this:

    123456789BACKUP DATABASE [SQLShackDemoATC]
    To DISK=’f:\PowerSQL\SQLShackDemoATC_1.BAK’
    WITH COPY_ONLY,      
    MEDIANAME = ‘Native_SQLServerFullBackup’,      
    NAME = ‘Full-SQLShackDemoATC backup’;
    TO DISK = ‘f:\PowerSQL\SQLShackDemoATCCopyOnly.log’WITH COPY_ONLY;

    The BACKUP LOG command with the COPY_ONLY option generates a copy-only log backup. It doesn’t involve in transaction log truncation.

    It is necessary to use “COPY_ONLY” backup option in order to preserve the database backup sequence.

    Partial backups

    Partial backups are one of the least-used backup methods available in SQL Server. All database recovery models support partial backups, but partial backups are mostly used in the simple recovery model in order to improve flexibility when backing up large databases that contain read-only filegroups.

    The READ_WRITE_FILEGROUPS option is used with the BACKUP DATABASE command. This command is for partial backup. It processes the backup of read-write file groups.

    SQLShackPartialBackup is the database created with primary and secondary file groups. Let’s use this database for this demo.

    CREATE DATABASE SQLShackPartialBackup ON  
    PRIMARY( NAME = N’SQLShackPartialBackup_1′,
    FILENAME = N’f:\PowerSQL\SQLShackPartialBackup_1.mdf’ ,
    SIZE = 5000KB , FILEGROWTH = 1024KB ),
    FILEGROUP [Secondary] ( NAME = N’SQLShackPartialBackup_2′,
    FILENAME = N’f:\PowerSQL\SQLShackPartialBackup_2.mdf’ ,
    SIZE = 5000KB ,
    FILEGROWTH = 1024KB )
    LOG ON( NAME = N’SQLShackPartialBackup_Log’,
    FILENAME = N’f:\PowerSQL\SQLShackPartialBackup_log.ldf’ ,
    SIZE = 1024KB , FILEGROWTH = 10%)

    Let’s change the recovery model of the database to SIMPLE using the following ALTER statement


    Now, set the secondary file-group to READONLY mode


    Initiate a backup using the READ_WRITE_FILEGROUPS option

    123BACKUP DATABASE SQLShackPartialBackup
    TO DISK = N’f:\PowerSQL\SQLShackPartialBackup_Full.bak’

    We can see in the following screenshot that the SQLShackPartialBackup_2 filegroup is not been backed up in the backup process.

    File and File Group Backups

    This topic is relevant for SQL Server databases that contain multiple files or filegroups. File backups of read-only filegroups can be combined with partial backups. Partial backups include all the read/write filegroups and, optionally, one or more read-only filegroups. 

    Let’s create a database with multiple files and filegroups.

    12345678910111213CREATE DATABASE SQLShackFileBackup
    ON  PRIMARY( NAME = N’SQLShackFileBackup_1′,
    FILENAME = N’f:\PowerSQL\SQLShackFileBackup_1.mdf’ ,
    SIZE = 5000KB ,
    FILEGROWTH = 1024KB ),
    FILEGROUP [Secondary] ( NAME = N’SQLShackFileBackup_2′,
    FILENAME = N’f:\PowerSQL\SQLShackFileBackup_2.ndf’ ,
    SIZE = 5000KB ,
    FILEGROWTH = 1024KB )LOG ON( NAME = N’SQLShackFileBackup_Log’,
    FILENAME = N’f:\PowerSQL\SQLShackFileBackup_Log.ldf’ ,
    SIZE = 1024KB ,
    FILEGROWTH = 10%)

    The following examples demonstrates how to create the file-level backup of the files:

    12345BACKUP DATABASE SQLShackFileBackup    
    FILE = ‘SQLShackFileBackup_1’,     
    FILE = ‘SQLShackFileBackup_2’     
    TO DISK = ‘f:\PowerSQL\SQLShackGroupfiles.bak’;  

    The following example illustrates the full file backup of all the files in both of the primary and secondary file-groups.

    12345BACKUP DATABASE SQLShackFileBackup    
    FILEGROUP = ‘Secondary’   
    TO DISK = ‘f:\PowerSQL\SQLShackGroupfilegroup.bak’;  

    The manager wants you to create a backup strategy for the following conditions:

    It’s a test database

    It’s a small database (1 gig)

    Must have full backups

    Can recreate data in a short time

    Not too much activity during week


    Take a full database backup weekly

    Select Simple Recovery Mode

    The manager wants you to create a backup strategy for the following conditions:

    It’s a production database

    It’s a midsize database (20 gig)

    Must have full backups

    Cannot recreate data in a short time

    Daily activity during week

    Restore must be within 1 day


    Take a full database backup weekly

    Select Full Recovery Mode

    Create hourly transaction log backups

    Create differential backups each six hours

    The manager wants you to create a backup strategy for the following conditions:

    It’s a production database

    It’s a large database (200 gig)

    Must have full backups

    Cannot recreate data in a short time

    Daily intense activity during the week

    Restore must be within 3 hour


    Take a full database backup Monday, Wednesday, Friday,

    Select Full Recovery Mode

    Create 15 min transaction log backups

    Create differential backups each 3 hours