{"id":2097,"date":"2016-04-01T09:00:00","date_gmt":"2016-04-01T16:00:00","guid":{"rendered":"http:\/\/www.coretechnologies.com\/blog\/?p=2097"},"modified":"2022-04-19T21:40:18","modified_gmt":"2022-04-20T04:40:18","slug":"windows-service-spoiling-backup","status":"publish","type":"post","link":"https:\/\/www.coretechnologies.com\/blog\/support\/windows-service-spoiling-backup\/","title":{"rendered":"A Windows Service is Spoiling my Backup. Help!"},"content":{"rendered":"<div align=\"center\"><img loading=\"lazy\" decoding=\"async\" class=\"no-lazy-load image-padding\" src=\"\/blog\/images\/windows-service-error.webp\" width=\"520\" height=\"330\" border=\"0\" title=\"Windows Service Error\" alt=\"Windows Service Error\" \/><\/div>\n<p><\/p>\n<p>Backups are an essential part of any professional system. Schedule them regularly or risk losing valuable data (and precious time) when a component fails.<\/p>\n<p>But backing up a live system can often be tricky. The backup software must &#8220;lock&#8221; each file to capture a consistent snapshot, and that exclusive access, though temporary, can cause another application to panic and throw up its hands in failure. Or the reverse can happen &#8212; an application can lock a file and prevent the backup software from capturing it. And what good is a backup if it doesn&#8217;t capture all your important data?<\/p>\n<p>So it&#8217;s always best to have a &#8220;quiet&#8221; system when performing a backup. Close all non-essential applications in advance. But what about Windows Services? Unlike regular desktop programs, those shouldn&#8217;t be stopped indefinitely.<\/p>\n<p>This is the dilemma faced by one of our customers. Backups run every weekend constantly fail because his windows service prevents the backup from accessing key files. He tried stopping the service before he left work on Friday evening and restarting it on Monday morning, but users complained loudly about the extended downtime.<\/p>\n<p>The obvious solution is to have a much smaller downtime window for the windows service &#8212; only for the duration of the backup. Here is how to do so in an automated fashion, with a couple of well-timed <a href=\"https:\/\/en.wikipedia.org\/wiki\/Windows_Task_Scheduler\" target=\"_blank\" rel=\"noopener noreferrer\">scheduled tasks<\/a> that leverage the <a href=\"\/blog\/windows-services\/essential-tools-for-windows-services-net-command\/\">useful NET command<\/a>.<\/p>\n<h2><b>Part 1: Create a Scheduled Task to Stop your Windows Service before the Backup Starts<\/b><\/h2>\n<ol>\n<li>\n<p>Start the Windows Task Scheduler by running <b>taskschd.msc<\/b> from a command prompt. (You can also find it in Control Panel by searching for &#8220;Schedule tasks&#8221;).<\/p>\n<\/li>\n<li>\n<p>In the window that comes up, click <b>Create Basic Task&#8230;<\/b> on the right to launch the <b>Create Basic Task Wizard<\/b>:<br \/>\n<a href=\"\/blog\/images\/task-scheduler-create-basic-task.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Create Basic Task\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/task-scheduler-create-basic-task.png\" border=\"0\" title=\"Create Basic Task (click to enlarge)\" alt=\"Create Basic Task\" width=\"520\" \/><\/a>\n<\/p>\n<\/li>\n<li>\n<p><a name=\"step-3\"><\/a>Enter a name for your new task. Something like <b>Stop service before backup starts<\/b> should work nicely. Click <b>Next &gt;<\/b> when you are done.<br \/>\n<a href=\"\/blog\/images\/basic-task-stop-service-name.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Specify Task Name\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/basic-task-stop-service-name.png\" border=\"0\" title=\"Specify Task Name (click to enlarge)\" alt=\"Specify Task Name\" width=\"520\" \/><\/a>\n<\/p>\n<\/li>\n<li>\n<p>In the next couple of steps, we&#8217;ll specify when to stop the windows service. Since our backup occurs every Saturday at 10 PM, we&#8217;ll setup the task to shut down the service a minute before, at 9:59 PM:<br \/>\n<a href=\"\/blog\/images\/basic-task-stop-service-weekly.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Stop Windows Service Weekly\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/basic-task-stop-service-weekly.png\" border=\"0\" title=\"Stop Windows Service Weekly (click to enlarge)\" alt=\"Stop Windows Service Weekly\" width=\"520\" \/><\/a><br \/>\n<a name=\"step-4\"><\/a><br \/>\n<a href=\"\/blog\/images\/basic-task-stop-service-every-saturday.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Stop Windows Service Every Saturday Night\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/basic-task-stop-service-every-saturday.png\" border=\"0\" title=\"Stop Windows Service Every Saturday Night (click to enlarge)\" alt=\"Stop Windows Service Every Saturday Night\" width=\"520\" \/><\/a>\n<\/p>\n<p><p>Click <b>Next &gt;<\/b> to proceed.<\/p>\n<\/li>\n<li>\n<p>On the subsequent screen, select <b>Start a program<\/b> and click <b>Next &gt;<\/b>:<br \/>\n<a href=\"\/blog\/images\/basic-task-start-a-program.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Start a Program\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/basic-task-start-a-program.png\" border=\"0\" title=\"Start a Program (click to enlarge)\" alt=\"Start a Program\" width=\"520\" \/><\/a>\n<\/p>\n<\/li>\n<li>\n<p><a name=\"step-6\"><\/a>Here is where we must specify the program to shut down the service. We&#8217;ll use the NET STOP command.<\/p>\n<ol type=\"a\">\n<li>Enter <b>NET.EXE<\/b> in the <b>Program\/Script<\/b> line.<\/li>\n<li>And in the arguments field, enter<br \/>\n<blockquote><p><b>STOP &lt;Service-Name&gt;<\/b><\/p><\/blockquote>\n<p> where &lt;Service-Name&gt; is the <a href=\"\/WindowsServices\/FAQ.html#FindServiceName\" target=\"_blank\" rel=\"noopener noreferrer\">name of the service<\/a>. We have used &#8220;Spooler&#8221; in this tutorial but you will obviously use your own service instead. Be sure to enclose that name in quotes if it contains a space!<\/li>\n<\/ol>\n<p>Click <b>Next &gt;<\/b> to continue.<br \/>\n<a href=\"\/blog\/images\/basic-task-net-stop-service.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Use NET STOP to shut down the service\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/basic-task-net-stop-service.png\" border=\"0\" title=\"Use NET STOP to shut down the service (click to enlarge)\" alt=\"Use NET STOP to shut down the service\" width=\"520\" \/><\/a>\n<\/p>\n<\/li>\n<li>\n<p>We&#8217;re almost done! You should see a screen confirming your settings. Click <b>Finish<\/b> to record this new scheduled task.<br \/>\n<a href=\"\/blog\/images\/basic-task-stop-service-summary.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Stop Service Task - Summary\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/basic-task-stop-service-summary.png\" border=\"0\" title=\"Stop Service Task - Summary (click to enlarge)\" alt=\"Stop Service Task - Summary\" width=\"520\" \/><\/a>\n<\/p>\n<\/li>\n<\/ol>\n<h2><b>Part 2: Create a Scheduled Task to Restart your Windows Service after the Backup Completes<\/b><\/h2>\n<p>Basically, repeat Part 1 but with the following changes:<\/p>\n<ul>\n<li>\n<p>When naming the task in <a href=\"#step-3\">Step 3<\/a>, call it something like <b>Restart service after the backup is done<\/b> instead.<\/p>\n<\/li>\n<li>\n<p>In <a href=\"#step-4\">Step 4<\/a>, set the time so that the task will run AFTER the backup completes.<\/p>\n<\/li>\n<li>\n<p>In <a href=\"#step-6\">Step 6<\/a>, run the NET START command instead. That is, set the arguments field to <\/p>\n<blockquote><p><b>START &lt;Service-Name&gt;<\/b><\/p><\/blockquote>\n<\/li>\n<li>\n<p>Here is what the ending summary screen should look like once you are done:<br \/>\n<a href=\"\/blog\/images\/basic-task-restart-service-summary.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Restart Service Task - Summary\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/basic-task-restart-service-summary.png\" border=\"0\" title=\"Restart Service Task - Summary (click to enlarge)\" alt=\"Restart Service Task - Summary\" width=\"520\" \/><\/a>\n<\/p>\n<\/li>\n<\/ul>\n<p style=\"margin-top:30px;\">And that&#8217;s it. Since implementing this tactic a few weeks ago, our customer&#8217;s backups have been problem-free. We&#8217;re confident that the same solution will work for you!<\/p>\n<!-- relpost-thumb-wrapper --><div class=\"relpost-thumb-wrapper\"><!-- filter-class --><div class=\"relpost-thumb-container\"><style>.relpost-block-single-image, .relpost-post-image { margin-bottom: 10px; }<\/style><h3>You may also like...<\/h3><div style=\"clear: both\"><\/div><div style=\"clear: both\"><\/div><!-- relpost-block-container --><div class=\"relpost-block-container relpost-block-column-layout\" style=\"--relposth-columns: 3;--relposth-columns_t: 2; --relposth-columns_m: 2\"><a href=\"https:\/\/www.coretechnologies.com\/blog\/windows-services\/event-viewer-troubleshoot-windows-services\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"How to use the Event Viewer to troubleshoot problems with a Windows Service\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/event-viewer-150x150.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">How to use the Event Viewer to troubleshoot problems with a Windows Service<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/windows-services\/windows-service-vs-web-service\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Q&amp;A: What&#039;s the difference between a Windows Service and a Web Service?\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/windows-service-vs-web-service-150x150-1.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Q&amp;A: What&#039;s the difference between a Windows Service and a Web Service?<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/windows-services\/profsvc\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Essential Windows Services: User Profile Service \/ ProfSvc\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/user-profile-service-150x150-1.webp\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Essential Windows Services: User Profile Service \/ ProfSvc<\/h2><\/div><\/div><\/a><\/div><!-- close relpost-block-container --><div style=\"clear: both\"><\/div><\/div><!-- close filter class --><\/div><!-- close relpost-thumb-wrapper -->","protected":false},"excerpt":{"rendered":"<p>Backups are an essential part of any professional system. Schedule them regularly or risk losing valuable data (and precious time) when a component fails. But backing up a live system can often be tricky. The backup software must &#8220;lock&#8221; each &hellip; <a href=\"https:\/\/www.coretechnologies.com\/blog\/support\/windows-service-spoiling-backup\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":2271,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[108,164,196],"class_list":["post-2097","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-support","tag-net-exe","tag-task-scheduler","tag-windows-services-2"],"_links":{"self":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/2097","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=2097"}],"version-history":[{"count":3,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/2097\/revisions"}],"predecessor-version":[{"id":11222,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/2097\/revisions\/11222"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media\/2271"}],"wp:attachment":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=2097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=2097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=2097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}