SQL Server: Maintenance Plan

Please see my other Database Development articles.

Ensure successful disaster recovery for databases

This section describes steps taken for database to backup data in preparation for a disaster.

Recovery Model

Of the three recovery models provided by SQL Server for its databases (Full, Simple, Bulk), the Full recovery model was chosen for its ability to recover from a disaster to a specific point-in-time.
Note: Databases in full recovery model won’t have their transaction log cleared unless a transaction log backup has occurred. Performing a full or differential backup (see backup types below) won’t clear the log.

This may be set in the properties of a database or via t-sql script.

ALTER DATABASE [database_name] SET RECOVERY FULL WITH NO_WAIT

Backup Types

Each database regularly performs the following types of backups:

  • Full: A complete copy of the database at a point in time.
    • This occurs once a week.
  • Differential: Changes to the database since the last full backup.
    • This occurs every 4 hours.
    • Note: Since this represents all changes since the last full backup, only the last differential backup needs to be restored.
  • Transaction log: All changes (transactions from CRUD operations) since the last log backup.
    • This occurs every hour.
    • Note: Since each log backup captures all changes since the last log backup, all log backups since the last differential would need to be restored to ensure all changes were restored.

Maintenance Plan – Full, Differential, and Log Backups

This section describes how to setup a maintenance plan to perform full, differential, and log backups of a database.

1) R-click Maintenance Plans -> Maintenance Plan Wizard.

1.SQL Server-Maintenance Plans

*Wizard starts.

2) Next.

2.SQL Server-Maintenance Plans

3) Set the following properties, Next.
*Type Description into Notepad, then copy back to keep formatting.
*Use Schedule Change button set the desired schedule.

Name: [Database name] – Backup – Full, Differential, Log
Description:
Database: [Database name].
Backup types: Full, Differential, Log.
Schedules
– Full: Friday, 6pm.
– Differential: Every 4 hours.
– Log: Every hour.

3.SQL Server-Maintenance Plans

4) Set the properties, Next.

4.SQL Server-Maintenance Plans

5) Reorder tasks if necessary, Next.

5.SQL Server-Maintenance Plans

Configure Full Backup Properties

1) Set the following properties, Next.

1a) General Tab.

6.SQL Server-Maintenance Plans7.SQL Server-Maintenance Plans

1b) Destination tab: Choose a target folder for the database.

8.SQL Server-Maintenance Plans

1c) Options tab: Set the desired options, Next.

9.SQL Server-Maintenance Plans

1d) Configure the schedule.

Click Change.

10.SQL Server-Maintenance Plans

Update the name to reflect only the current backup type.

11.SQL Server-Maintenance Plans

Configure Differential Backup Properties

1) Set the following properties, Next.

1a) General Tab.
(same as previous step)

1b) Destination tab: Choose a target folder for the database.
(same as previous step, ensuring the backup is written to the same folder as the previous step)

1c) Options tab: Set the desired options, Next.
(same as previous step, except don’t use compression for backups)

1d) Configure the schedule.

Click Change.

Update the name to reflect only the current backup type.

12.SQL Server-Maintenance Plans

13.SQL Server-Maintenance Plans

Configure Optional Report

1) Choose a target for optional reports, Next.

14.SQL Server-Maintenance Plans

*You’ll now be presented with an overview.

9) Review the overview, make changes (Back) or Finish.

15.SQL Server-Maintenance Plans

10) A report is generated, Close.

16.SQL Server-Maintenance Plans

*You should now see your Maintenance Plan.
*Ensure the current instance SQL Server Agent is started.

When you’ve saved the maintenance plan, you should be able to view its steps.

17.SQL Server-Maintenance Plans

11) Execute the plan to confirm its success.

Note: Should the plan contain multiple steps (sub plan) with different schedules, you’ll need to execute the job instead.

18.SQL Server-Maintenance Plans

12) Confirm the backup resides at your target folder from the previous step.
*If any issues occurred, view the report file in the same folder.