Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1 of 17
http://solutioncenter.apexsql.com/how-to-create-a-sql-server-scheduled...
Backup types
1. Full database backups include all database objects, system tables, data, and transactions that occur during the backup. Full database backups allow performing a complete restoration to a state before the
backup is performed.
2. Differential backups contain data that has changed since the last full backup was performed and transactions that occur during the backup process. A differential backup is used alongside with the last full database backup. After taking a differential backup, as it is taken after the last full backup all of the old differential backups become obsolete.
3. Transaction log backups records all the transactions that have occurred on a database since the previous
transaction log backup and then truncates the transaction log and then truncates a transaction log. A
transaction log backup ensures database recovery to a specific point of time e.g. to a moment prior to data
loss.
4. File and filegroup backups option is most suitable for backing up very large databases. Afile backup will
contain all the data in one or more files or filegroups. A transaction log backup has also be performed to
span all the file backups from start to finish when using file backups to restore a database.
5. Copy-only backups are mostly used when its needed to backup a database without affecting the processes of backup and restore for a specific database. Functionality of a copy-only backup is the same as full
database with a difference that a transaction log backup will backup all transactions since the last full
backup is performed and ignore the existence of the copy backup, therefore a copy backup cannot be used
as the basis for differential and transaction log backups.
2 of 17
http://solutioncenter.apexsql.com/how-to-create-a-sql-server-scheduled...
Test backups
Backup and recovery strategy cannot be complete until backups are successfully restored on a test server and
verified that backup can be restored to fulfill all the requirements and conditions including all the combinations
that the recovery strategy requires. There is a variety of factors to consider such as: the organizations requirements regarding the usage of data, protection etc.
Backup verification
Verifying backup ensures that a backup is created correctly, intact physically, that all the files in the backup are
readable and can be restored in the event that the user needs to use it, and that all the transactions are consistent. It is important to understand that verifying a backup does not verify the structure of the data on the
backup. However, if the backup was created using WITH CHECKSUMS, verifying the backup using WITH CHECKSUMS can provide a good indication of the reliability of the data on the backup.
By using T-SQL:
Including the CHECKSUM statement ensures consistency of data on the backup destination. To include CHECKSUM use the following query:
SQL Server Management Studio also provides options to include backup verification a CHECKSUM check when
creating a backup as a task:
5/26/2016 12:20 PM
3 of 17
http://solutioncenter.apexsql.com/how-to-create-a-sql-server-scheduled...
The Verify backup when finished option and Perform checksum before writing to media are used as an insurance
that both backup and its data are consistent.
We will also show how to include verifications when scheduling backups.
In this article we will create a SQL Server scheduled backup by using a SQL Server Agent job, SQL Server Maintenance Plans, and ApexSQL Backup.
Create a SQL Server scheduled backup by using a SQL Server Agent job
To automate and schedule a backup with SQL Server Agent:
1. In the Object Explorer pane, under the SQL Server Agent node, right click Jobs and select New job from
4 of 17
http://solutioncenter.apexsql.com/how-to-create-a-sql-server-scheduled...
USE AdventureWorks2012
GO
BACKUP DATABASE [AdventureWorks2012]
TO DISK = N'F:\Backup\AW12.bak'
WITH CHECKSUM;
Note: To create a differential or a transaction log SQL Server database backup a full database backup has
to exist. If a desired database has never been backed up, before creating differential backups, first create
a full database backup. Differential and transaction log backups can be used along a full database
backup. For example, a full backup can be scheduled every 24 hours, a differential backup can be performed every 5 hours, and a transaction log backup every 15 minutes.
5/26/2016 12:20 PM
5 of 17
http://solutioncenter.apexsql.com/how-to-create-a-sql-server-scheduled...
5. To schedule a job, in the New Job dialog, under the Schedule tab click New.
6. In the Job Schedule select an occurring frequency and a start date and click OK:
5/26/2016 12:20 PM
6 of 17
http://solutioncenter.apexsql.com/how-to-create-a-sql-server-scheduled...
To check a created job in the Object Explorer pane and under the SQL Server Agent Jobs node right click the
job create above and select the Start job at step option:
5/26/2016 12:20 PM
7 of 17
http://solutioncenter.apexsql.com/how-to-create-a-sql-server-scheduled...
To use SQL Server Agent for backing up all databases under one instance there are two approaches, both of
which require some manual work. One approach is to create a SSIS package using the Backup Database Task option from the SSIS toolbar and create a SQL Server Agent job to schedule it.
The other approach is to write a T-SQL script to backup all databases in the SQL Server Agent Job Step dialog.
Create a SQL Server scheduled backup by using SQL Server Maintenance Plans
There are two options to create a scheduled backup task by using SQL Server Maintenance Plans: manually by
creating a new plan and by using the Maintenance Plan Wizard.
To manually create a scheduled backup task:
1. In the Object Explorer pane under the Management node right click Maintenance Plans and select the
2. From the Maintenance Plan Tasks toolbox select Back Up Database Task:
5/26/2016 12:20 PM
8 of 17
http://solutioncenter.apexsql.com/how-to-create-a-sql-server-scheduled...
The Maintenance Plan Wizard also provides the Check database integrity task that can be included in
Maintenance Plan:
5/26/2016 12:20 PM
9 of 17
http://solutioncenter.apexsql.com/how-to-create-a-sql-server-scheduled...
4. To schedule a SQL Server Agent job use the Sub plan scheduling option.
5. When a plan is created click save and this action will create a corresponding job under the SQL Server
Agent Jobs folder.
A method to create a new maintenance plan through the Maintenance Plan Wizard guides the user through the
process, but this option provides fewer options for fine tuning.
To automate and schedule a backup by using the SQL Server Maintenance Plan Wizard:
1. In the Object Explorer pane under the Management node right click Maintenance Plans and select the
Maintenance Plan Wizard option:
2. In the Select Plan Properties window specify a plan name. To schedule a SQL Server Agent job click the
Change button:
5/26/2016 12:20 PM
10 of 17
http://solutioncenter.apexsql.com/how-to-create-a-sql-server-scheduled...
3. In the Select Maintenance Plan Tasks select the Back Up Database option and the Check data integrity
option. The check data integrity tack performs internal consistency check of the data and index pages
within the database :
5/26/2016 12:20 PM
11 of 17
http://solutioncenter.apexsql.com/how-to-create-a-sql-server-scheduled...
4. In the following window configure the maintenance task by specifying a database for backup and the
backup options. In the Define Back Up Database Task window also check the Verify backup integrity option:
5/26/2016 12:20 PM
12 of 17
http://solutioncenter.apexsql.com/how-to-create-a-sql-server-scheduled...
5/26/2016 12:20 PM
13 of 17
http://solutioncenter.apexsql.com/how-to-create-a-sql-server-scheduled...
Maintenance Plans are more suitable for less experienced DBAs because they provide an easy to use GUI, and do
not require manually written maintenance scripts. The downside of Maintenance Plans is that the tasks that
Maintenance Plans provide are basic and dont leave space for customization.
A Maintenance Plan is also atomic and is therefore not able to run multiple tasks. Each type of maintenance task
within a single Maintenance Plan can only be configured to run once within that Plan. For example, if a task that
is made to delete older backup files it will only delete one file type at a time. Because of this multiple Maintenance Plans have to be created just to perform a single task, in some cases, and every Maintenance Plan has to
have a corresponding SQL Server Agent job to be scheduled.
that en-
ables automating and scheduling SQL Server backup jobs in one task while preserving the backup chain for easy
point-in-time restoration (database rollback).ApexSQL Backup is also able to run multiple tasks at the same time
and provides an out of the box solution for scheduling a database backup for one or all databases in just a few
clicks.
To create a SQL Server scheduled backup in ApexSQL Backup:
1. In the Home tab of the main menu select the Backup option:
2. In the Backup wizard specify a server name, a database name, and a backup type. ApexSQL Backup sup-
ports all backup types and provides an option to select all databases:
5/26/2016 12:20 PM
14 of 17
http://solutioncenter.apexsql.com/how-to-create-a-sql-server-scheduled...
3. In the Type and output window specify a destination folder and an output name:
5/26/2016 12:20 PM
15 of 17
http://solutioncenter.apexsql.com/how-to-create-a-sql-server-scheduled...
4. In the Options window specify backup options such as backup verification, compression, encryption etc.
ApexSQL Backup offers options to include both the Verify backup step when finished, and the Perform
checksum step before writing to media option during the process of creating a backup task without the
need for writing a separate script:
5/26/2016 12:20 PM
16 of 17
http://solutioncenter.apexsql.com/how-to-create-a-sql-server-scheduled...
5. In the following window select the Schedule option and specify the occurring frequency. ApexSQL
Backup allows scheduling a backup task during the process of creating a task:
5/26/2016 12:20 PM
17 of 17
http://solutioncenter.apexsql.com/how-to-create-a-sql-server-scheduled...
SQL Server
Maintenance
ApexSQL
Agent
Plans
Backup
Yes
No
No
No
Yes
Yes
Yes
No
Yes
No
No
Yes
5/26/2016 12:20 PM