How to Take SQL Server Database Backup Automatically

Summary: This blog explains how to automate SQL Server database backup using Maintenance Plan Wizard and SQL Server Agent job. If you’re unable to take automatic backup due to corruption in the database, or the backup is corrupted, using the tools available in Stellar Toolkit for MS SQL may help.


How to Take SQL Server Database Backup Automatically

One of the critical responsibilities of a SQL database administrator is to get a database backed up successfully. However, it is crucial to maintain regular database backups to reduce the chances of data loss while restoring the database from backup. You can accomplish this by scheduling automatic backup of a SQL Server database.

Taking SQL Server database backup automatically also saves time and the manual effort required to run database backup. There are different methods you can use to create a scheduled backup of a SQL database automatically.

Methods to Schedule a Backup

Following are the two methods you can use to schedule an automated backup:

Method 1 – Taking Database Backup Automatically Using Maintenance Plan Wizard

The Maintenance Plan Wizard is an easier and convenient method for creating automated backups with limited options.

You can set a schedule to automatically back up a SQL database using the Maintenance Plan Wizard by following these steps:

  • Open SQL Server Management Studio (SSMS), and connect to a server instance.
  • Expand the Management folder from the ‘Object Explorer’ pane, right-click on Maintenance Plans, and choose Maintenance Plan Wizard.
select maintenance plan wizard
  • When the ‘SQL Server Maintenance Plan Wizard’ opens, click Next.
sql server maintenance plan
  • On the ‘Select Plan Properties’ screen, enter name of your maintenance backup plan. In our case, we have specified it as ‘AutomateBackupDatabase’. Next, enter a description for the maintenance plan, and then click Change.
Select Plan Properties
  • On the ‘New Job Schedule’ dialog box, specify the frequency of your database backup, the time you want the backup process to run, and then click OK.
new job schedule
  • Click Next.
continue with backup maintenance plan
  • On the ‘Select one or more maintenance tasks:’ screen, choose the Back Up Database option as you can see in the below screen.
select backup database option
  • To execute full database backup,click Next.
back up full database
  • On ‘Define Back Up Database (Full) Task’ screen, under General sectionspecify all or a specific database for backup, and then click OK.
full backup task
  • Click on the Destination tabfrom the ‘Define Back Up Database (Full) Task’ screen. Next, check options by clicking on the Options tab, and then click Next.
choose destination to save automatic backup plan
  • By default, a report of the maintenance plan actions is written to a text file in the specified location. You may choose to change the default location, and then press Next.
report of the maintenance plan actions
  • Once you’re satisfied with the backup maintenance plan options, click Finish.
the backup maintenance plan options
  • Success status is displayed once the selected actions for the backup maintenance plan are performed successfully. Click Close.
backup maintenance plan are performed successfully

Now, from the ‘Object Explorer’ pane, right-click on SQL Server Agent, and you will see a job created automatically for the backup maintenance plan.

a job created automatically for the backup maintenance plan

While the Maintenance Plan Wizard provides a more effortless and hassle-free way of taking database backup, it fails to provide granular control and configuration options for scheduling automated backups. An alternative is to create an automatic backup job using SQL Server Agent.

Method 2 – Taking Database Backup Automatically Using SQL Server Agent Jobs

Follow these steps to create an automated backup on a scheduled basis using SQL Server Agent job:

  • In SSMS, expand SQL Server Agent in the ‘Object Explorer’ pane, right-click on Jobs and click New job.
create new job
  • When the ‘New Job’ screen opens, you can see several configuration options for the automated backup job. The options allows scheduling backup, setting up alerts for the backup job, adding notifications, etc. On the ‘General’ page, specify a name for the backup job.
specify name for the job
  • Click the Steps tab. On the Steps page, click the New button.
create new backup
  • On the ‘New Job Step’ screen, specify step name, and then enter SQL code to create the new backup step:
USE Test_Database
GO
BACKUP DATABASE [Test_Database]
TO  DISK = N’C:\Program Files\Microsoft SQL Server\MSSQL10_50.STELLAR\MSSQL\Backup\Test_Database.bak’
sql script for backup

Note: You may also add SQL code for creating a differential and transaction log backup.

  • Click OK to create the new backup step. This will take you to the ‘New Job’ screen. On the screen, click the Schedules tab.
schedule automatic backup job
  • On the ‘Schedules’ page, click the New button. In the ‘New Job Schedule’ screen, enter name for the automatic database backup you want to schedule. Next, select the frequency, duration, and the start time when you want the backup job to run automatically. Click OK.
new backup job schedule
  • Click on the ‘Alerts’ tab if you want to setup any alerts for the automated backup job. On the ‘Alerts’ page, click Add.
add alerts for automated backup job
  • Select the database for which you want to setup alerts, and click OK.

Note: You may also choose to set up notifications if the database backup job fails.

  • Click on OK once again after specifying the job properties.

After executing the above steps, expand the Jobs folder. You will see the new ‘Automate DB Backup’ job. Also, you can see the alerts for the backup job that indicates corruption suspected while taking a backup.

automated backup job with alerts

What to do to fix corruption?

If the backup is corrupted, using Stellar Toolkit for MS SQL software can come in handy. The software comes with different tools that help database administrators resolve the most common issues with a SQL database. For example, using the Backup Extractor tool in the toolkit, you can extract all the data from the corrupted backup. Also, you can use the SQL repair tool to fix corruption in a database if required. Download the trial version of the MS SQL toolkit from here to check how it works.

free download

Use the SQL Server Agent job for better control over taking automatic backup of SQL database.

EndNote

This blog discussed the two different methods to take SQL Server database backup automatically. If you need a point-and-click interface to automate backup on a scheduled basis, you can use the Maintenance Plan Wizard to create a backup maintenance plan. Consider using the SQL Server Agent jobs as explained in the blog for more control and configuration options for scheduling automatic backups.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.