Multiple methods for scheduling a SQL Server backup automatically
Multiple methods for scheduling a SQL Server backup automatically
backup automatically
SQL Server backups are an essential part of every good disaster recovery strategy.
That is good. But setting up such backups to run effortlessly, is the goal. In this
article, we’ll review the types of backups, recommended practices and three
different methods for automatically setting up SQL Server backups on a schedule.
Note: these solutions can also be used in combination with one another
SQL Server backups are an essential part of every good disaster recovery strategy.
That is good. But setting up such backups to run effortlessly, is the goal. In this
article, we’ll review the types of backups, recommended practices and three
different methods for automatically setting up SQL Server backups on a schedule.
Note: these solutions can also be used in combination with one another
Without explicit guidance for the file location as to where to store the backups, SQL
Server will use the default database location.
Please note that simply changing the default file location, will have no effect on
previously saved backup files, it will only determine the location where new backups
are stored.
Regular database backups not only are a great insurance policy against accidental
data loss and other disaster type scenarios, they also provide point-in-store
capability (for transaction log backups) and reduced downtime, if you do have to
restore (shorter backup windows > less data loss)
How often should I schedule backups? This depends on your business requirements
and Recovery Point Objectives (RPO), for example, if your standard is no more than
15 minutes of data can be lost, then then backups need to be scheduled every 15
minutes
Note: If your database is in full recovery mode you can use ApexSQL Log to avoid
full restores. ApexSQL Log can isolate and reverse rogue transactions, mitigating the
damaged data without having to do a full restore. It can also replay previous
transaction to restore data that was lost
You can also use ApexSQL Data Diff to compare the current database to the last
database backup (without even restoring it), identifying different/damaged rows and
surgically repairing them with a synchronization script, again, without having to
restore the backup.
Restoring and testing backups
A backup is only good if it can be restored successfully and this must be verified, and
continuously re-verified to ensure your backup and restore strategy can be executed
successfully when needed. Backups must be restored in a test environment and fully
verified to ensure they meet all business requirements and various permutations,
contingencies and contexts of the company recovery strategy
When testing backups many variables existing including environment, data, recovery
time frames and data loss windows, application downtime and maximum acceptable
threshold for data loss
Verifying backups
SQL Server backup verification includes the following checks
Note that verifying a backup doesn’t ensure the integrity or completeness of all of
the data but if the original backup was created with WITH CHECKSUMS, that allows
WITH CHECKSUMS to be used to verify the data, at an aggregate level, to give a
reasonable confidence level that no data was lost. Let’s look at a few backup cases
below to provide some practical examples
with T-SQL:
When we include the CHECKSUM statutement we can later ensure the integrity of
the data, when the backup is complete and written to file. To accomplish this, see
the following example:
2 TO DISK = N'G:\DatabaseBackups\CE.bak'
3 WITH CHECKSUM;
SSMS provides the facility for backup verification using CHECKSUM when creating a
backup task
Two options are available in SSMS to implement this functionality including Verify
backup when finished and Perform checksum before writing to media. These
options are meant to bullet-proof your database backup process and identify any
failures
We’ll demonstrate, in this article, how to automatically create and schedule a SQL
Server backup using SQL Server Agent jobs and a Maintenance plans
3. Click on the New button, under the Steps tab, and create a new backup step
by adding a SQL statement
1 USE CurrencyExchange
2 GO
4 TO DISK = N'G:\DatabaseBackups\CE.bak'
5 WITH CHECKSUM;
1 USE CurrencyExchange
2 GO
4 TO DISK = N'G:\DatabaseBackups\CE.bak'
5 WITH CHECKSUM;
6
9
BACKUP DATABASE [CurrencyExchange]
1
TO DISK = N'G:\DatabaseBackups\CE.bak'
0
WITH DIFFERENTIAL;
1
1 WITH CHECKSUM;
2
GO
2 TO DISK = N'F:\TLogBackups\CE.log';
3 GO
7. Transaction log and differential backups play well together with full database
backups and can be used in tandem. By taking a sophisticated approach to
backups you can achieve a high level of database continuity and
insurance/protection from data loss while minimizing backup file storage
requirements. You can, for example, schedule a full SQL Server backup every
12 hours, but a differential, much more often, say every 4 hours and finally,
back up your transaction log every 15 minutes. The key is finding the sweet
spot between mitigating potential data loss and storage requirements that is
optimal for your organization
8.
The approach is to create a SQL script to backup all databases in the SQL Server
Agent Job Step dialog.
Creating a scheduled SQL Server
backup with SQL Server Maintenance
Plans
You can either use SQL Server Maintenance Plans, manually, to create a scheduled
backup or use the Maintenance Plan Wizard.
1. Click Maintenance Plans, under the Management node in the SSMS Object
explorer, and select New Maintenance Plan.
2. Select Back Up Database Task: from the Maintenance Plan Tasks toolbar
A Check database integrity task option exists, as an option in the
Maintenance Plan Wizard, allowing this functionality to be included in your
maintenance plan.
The Maintenance Plan Wizard is easier and more convenient but provides less
granular control and fewer configuration options
To automatically schedule a SQL Server backup using the SQL Server Maintenance
Plan Wizard see the following steps: