{"id":25266,"date":"2018-10-09T20:35:13","date_gmt":"2018-10-09T16:35:13","guid":{"rendered":"https:\/\/www.msp360.com\/resources\/?p=25266"},"modified":"2024-02-14T15:49:50","modified_gmt":"2024-02-14T11:49:50","slug":"sql-server-backup-automation","status":"publish","type":"post","link":"https:\/\/www.msp360.com\/resources\/blog\/sql-server-backup-automation\/","title":{"rendered":"Microsoft SQL Server Backup Automation"},"content":{"rendered":"<p>The backup routine for MS SQL Server includes various repetitive tasks that require a lot of time and attention. Fortunately, there are built-in Microsoft SQL Server tools that can automate many of these steps and simplify your daily routine. This article discusses those built-in tools, while also showing how to use MSP360 software for MS SQL Server automatic backup.<\/p>\n<p><!--more--><\/p>\n<h2>Using Built-In Tools<\/h2>\n<h3>SQL Server Backup Automation<\/h3>\n<p>One option is to use SQL Server Agent to create a backup script and configure a schedule for SQL Server automatic backup.<\/p>\n<p>You can use SQL Server Agent for backup jobs scheduling if you are running any of the SQL Server commercial editions. A free SQL Express does not have Agent feature.<\/p>\n<p>For this article, we will use T-SQL scripts as examples. You can test them using Query Analyzer in SQL Server Management Studio, or use them as a backup step in SQL Server Agent. You will also need to enable SQL Server Agent, since it is disabled by default. You can enable it by opening the navigation tree for SQL Server Management Studio, right-clicking and choosing Start.<\/p>\n<p>We suggest creating virtual \u201cbackup devices\u201d in SQL Server Agent, which allow you to distribute the data from several tasks into files. SQL uses a \u201cdevices\u201d concept for any backup job, and you can use the files on a disk drive, tape drives, etc. as a \u201cdevice.\u201d If you are using a disk drive, you can create a separate logical device for any file, and this file can include multiple backups.<\/p>\n<div class=\"call-to-action\">\n<div class=\"call-to-action__left\">\n<div class=\"call-to-action__tag\">FREE WHITEPAPER<\/div>\n<div class=\"call-to-action__title\">SQL Server Backup and Recovery<\/div>\n<div class=\"call-to-action__text\">Check out the ultimate guide with best practices for MSPs:<\/div>\n<!--HubSpot Call-to-Action Code --><span class=\"hs-cta-wrapper hs-cta-deferred\" id=\"hs-cta-wrapper-9ed03d9c-f81b-4305-917a-03488ba39bf3\" data-portal=\"5442029\" data-id=\"9ed03d9c-f81b-4305-917a-03488ba39bf3\"><span class=\"hs-cta-node hs-cta-9ed03d9c-f81b-4305-917a-03488ba39bf3\" id=\"hs-cta-9ed03d9c-f81b-4305-917a-03488ba39bf3\"><!--[if lte IE 8]><div id=\"hs-cta-ie-element\"><\/div><![endif]--><a href=\"https:\/\/cta-redirect.hubspot.com\/cta\/redirect\/5442029\/9ed03d9c-f81b-4305-917a-03488ba39bf3\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"hs-cta-img\" id=\"hs-cta-img-9ed03d9c-f81b-4305-917a-03488ba39bf3\" style=\"border-width:0px;\" src=\"https:\/\/no-cache.hubspot.com\/cta\/default\/5442029\/9ed03d9c-f81b-4305-917a-03488ba39bf3.png\" alt=\"CTA\"><\/a><\/span><\/span><!-- end HubSpot Call-to-Action Code -->\n<\/div>\n<div class=\"call-to-action__right\"><img decoding=\"async\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2019\/07\/The-Ultimate-MSP-Guide-to-MS-SQL-Server-Backup-and-Recovery.png;\" alt=\"WP icon\" \/><\/div>\n<\/div>\n<p>The first step in the SQL Server backup automation process is to create the logical device \"full_backups,\" which will represent target file \u201cC:\\BackupRepository\\sql_full.bak.\u201d You can do that using these commands:<\/p>\n<pre>USE TestDB ;  \r\nGO  \r\nEXEC sp_addumpdevice 'disk', 'full_backups', 'C:\\BackupRepository\\sql_full.bak' ;  \r\nGO\r\n<\/pre>\n<p>Replace \u201cTestDB\u201d in the example above with the name you want to use for your database. Create at least one backup device per every backup schedule (e.g. daily, weekly, monthly, etc.).<\/p>\n<p>You can also set up backup devices from the GUI by navigating in the menu to Server Objects - Backup Devices.<\/p>\n<p>Now we are ready to create a backup. Choose the desired database in SQL Server Management Studio, right-click, and select Tasks - Back Up:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25267 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image1.png\" alt=\"Creating automatic SQL Server backup in SQL Server Management Studio\" width=\"1241\" height=\"660\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image1.png 1241w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image1-300x160.png 300w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image1-768x408.png 768w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image1-1024x545.png 1024w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image1-624x332.png 624w\" sizes=\"auto, (max-width: 1241px) 100vw, 1241px\" \/><\/p>\n<p>Next, in the backup job settings window, click Script Action to Job in the Script drop-down menu in order to automatically generate the script for SQL Server Agent:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25269 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image3.png\" alt=\"Click Script Action to Job in the Script drop-down menu in order to automatically generate the script for SQL Server Agent\" width=\"907\" height=\"326\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image3.png 907w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image3-300x108.png 300w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image3-768x276.png 768w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image3-624x224.png 624w\" sizes=\"auto, (max-width: 907px) 100vw, 907px\" \/><\/p>\n<p>Type necessary job name and go to the Steps tab. You will find generated script here.<\/p>\n<p>Click Edit to review the script:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25268 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image2.png\" alt=\"Generated script for automatic SQL Server backup\" width=\"690\" height=\"624\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image2.png 690w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image2-300x271.png 300w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image2-624x564.png 624w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><\/p>\n<p>Modify the script if necessary - here is a quick description of the options:<\/p>\n<ul>\n<li>\"TestDB\" - target database name.<\/li>\n<li>\"diff_backups\"\u00a0- replace with one or more previously created devices. If one of them is full or unavailable, SQL will use the others.<\/li>\n<li>WITH - contains one or more of these options:\n<ul>\n<li>COMPRESSION | NO_COMPRESSION - specify whether SQL should use compression.<\/li>\n<li>ENCRYPTION - you can instruct SQL to encrypt the data using ALGORITHM and SERVER CERTIFICATE.<\/li>\n<li>DESCRIPTION - small user note for the particular backup.<\/li>\n<li>DIFFERENTIAL - allows you to create a differential database backup that contains only the data changed since the last full backup run.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>You can set additional options and error-handling rules by going to the Advanced tab:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25271 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image5.png\" alt=\"Setting additional options and error-handling rules for SQL Server automatic backup in the Advanced tab\" width=\"690\" height=\"625\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image5.png 690w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image5-300x272.png 300w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image5-624x565.png 624w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><\/p>\n<p>Once you are done configuring the above settings, return to the job settings and click the Schedules tab to create a recurring task. Choose the running occurrence, select desired days, and type the desired schedule plan name.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25270 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image4.png\" alt=\"Scheduling automatic SQL Server backup\" width=\"982\" height=\"579\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image4.png 982w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image4-300x177.png 300w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image4-768x453.png 768w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image4-624x368.png 624w\" sizes=\"auto, (max-width: 982px) 100vw, 982px\" \/><\/p>\n<p>Finally, confirm the changes you made and configure notifications on the corresponding tab, if necessary.<\/p>\n<p>Your backup job is now created. You can test it by clicking Start Job at Step in the context menu of the target backup job.<\/p>\n<h3>SQL Server Backup Verification<\/h3>\n<p>Simply creating a database backup is not enough. You should also ensure that you can recover the backup data in case of a disaster. Unfortunately, system administrators often face backup corruption or another problem with backed-up data; if that happens, the backups are of no use. Many external factors can prevent you from being able to perform data recovery, so we suggest automating the process of checking that you can actually recover your data from backups.<\/p>\n<p>SQL Server allows you to verify a backup by using the RESTORE VERIFYONLY option as one of the job steps in SQL Server Agent:<\/p>\n<pre>RESTORE VERIFYONLY FROM diff_backups\r\nGO\r\n<\/pre>\n<p>You can do the same using SQL Server Management Studio: Check the Verify backup when finished flag in BackUp Database properties.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25273 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image7.png\" alt=\"Configuring MS SQL Server backup verification\" width=\"910\" height=\"669\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image7.png 910w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image7-300x221.png 300w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image7-768x565.png 768w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image7-624x459.png 624w\" sizes=\"auto, (max-width: 910px) 100vw, 910px\" \/><\/p>\n<p>Remember that backup verification only applies to the most recent backup in the backup file or device. Therefore, if you prefer T-SQL script, you need to run a verification command as a regular step after each job run.<\/p>\n<p>In order to test that it is actually possible to restore the data and that MS SQL Server works as desired after the data recovery, you can use a sandbox environment.<\/p>\n<h2>Automatic SQL Server Backup with MSP360<\/h2>\n<p>Now, let\u2019s see how to configure automatic SQL Server backup with MSP360 Backup software.<\/p>\n<p>You need <a href=\"https:\/\/www.msp360.com\/backup\/\">MSP360 Backup for MS SQL Server<\/a> or <a href=\"https:\/\/www.msp360.com\/backup\/\">MSP360 Backup Ultimate<\/a> editions to be able to back up SQL databases. At the time of this article's publication, MSP360 Backup supports Microsoft SQL Server 2000-2017.<\/p>\n<p>Follow these steps to set up MSP360 Backup for automatic MS SQL Server backup:<\/p>\n<p>1. Start the backup wizard in MSP360 Backup by clicking the MS SQL Server button on the Home tab.<\/p>\n<p>2. Select either Local or Cloud Backup or Hybrid Backup (we will use the first option in this example) and choose target storage account or create a new one.<\/p>\n<p>3. Provide the name for this backup plan and proceed. At this point, you need to connect MSP360 Backup to the target SQL Server instance. MSP360 Backup will also verify the necessary permissions for you. If you have created a separate backup account in SQL Server, use the Authentication menu to specify its credentials.<\/p>\n<p>4. Select the databases you want to back up. We chose TestDB in this example.<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25276 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image9.png\" alt=\"Selecting databases to back up\" width=\"644\" height=\"503\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image9.png 644w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image9-300x234.png 300w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image9-624x487.png 624w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/><\/p>\n<p>5. Specify a Retention policy for your backup to save only the necessary number of copies. This helps to prevent you from running out of space or paying more than necessary when using cloud storage. <img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25274 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image8.png\" alt=\"Specifying retention policy for your automatic SQL Server backup\" width=\"643\" height=\"502\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image8.png 643w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image8-300x234.png 300w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image8-624x487.png 624w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/p>\n<p>6. The scheduling step allows you to create a \u201crun once\u201d job or configure one of the available schedule templates. In most cases, we suggest using the Recurring (predefined templates) schedule, which includes a set of full, differential, and <a href=\"https:\/\/www.msp360.com\/resources\/blog\/sql-server-transaction-log-backup\/\">transaction log backups<\/a>, which you can modify depending on your needs.<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25278 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image11.png\" alt=\"Scheduling automatic SQL Server backup\" width=\"644\" height=\"502\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image11.png 644w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image11-300x234.png 300w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image11-624x486.png 624w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/><br \/>\nIf that schedule is not what you are looking for - check Recurring (advanced schedule) and create your own template.<\/p>\n<p>7. Specify recurrence details from a set of templates on the next step. In the example below you will have a backup every hour, with daily differentials and weekly fulls.<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25277 size-full\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image10.png\" alt=\"Specifying simple recurring schedule for automatic SQL Server backup\" width=\"643\" height=\"501\" srcset=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image10.png 643w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image10-300x234.png 300w, https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2018\/10\/image10-624x486.png 624w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/p>\n<p>8. Set any other advanced options you wish to configure, such as pre\/post actions and notifications settings, and complete the backup plan creation.<\/p>\n<h2>Conclusion<\/h2>\n<p>MS SQL Server allows you to automate most data protection tasks, such as backup, verification, and retention. It is possible to write scripts to perform any action you want to include in the backup plan using T-SQL scripts.<\/p>\n<p>However, if you don\u2019t want to have to write scripts manually or learn T-SQL, check <a href=\"https:\/\/www.msp360.com\/backup\/\">MSP360 Backup for MS SQL Server<\/a>. MSP360 Backup provides automatic SQL Server backup to local or cloud storage of your choice, <a href=\"https:\/\/www.msp360.com\/resources\/blog\/image-backup-and-recovery\/\">system image backup<\/a>, <a href=\"https:\/\/www.msp360.com\/resources\/blog\/bare-metal-recovery\/\">bare-metal recovery<\/a> and more, without requiring scripting or extensive customization.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The backup routine for MS SQL Server includes various repetitive tasks that require a lot of time and attention. Fortunately, there are built-in Microsoft SQL Server tools that can automate many of these steps and simplify your daily routine. This article discusses those built-in tools, while also showing how to use MSP360 software for MS [&hellip;]<\/p>\n","protected":false},"author":46,"featured_media":29125,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[877,894,882],"tags":[],"class_list":["post-25266","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-articles","category-msp360-backup","category-msp360-news"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/posts\/25266","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/users\/46"}],"replies":[{"embeddable":true,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/comments?post=25266"}],"version-history":[{"count":1,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/posts\/25266\/revisions"}],"predecessor-version":[{"id":57617,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/posts\/25266\/revisions\/57617"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/media\/29125"}],"wp:attachment":[{"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/media?parent=25266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/categories?post=25266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/tags?post=25266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}