The Core Technologies Blog

Professional Software for Windows Services / 24×7 Operation


A Windows Service is Spoiling my Backup. Help!

Windows Service Error

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 “lock” 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 — an application can lock a file and prevent the backup software from capturing it. And what good is a backup if it doesn’t capture all your important data?

So it’s always best to have a “quiet” system when performing a backup. Close all non-essential applications in advance. But what about Windows Services? Unlike regular desktop programs, those shouldn’t be stopped indefinitely.

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.

The obvious solution is to have a much smaller downtime window for the windows service — only for the duration of the backup. Here is how to do so in an automated fashion, with a couple of well-timed scheduled tasks that leverage the useful NET command.

Part 1: Create a Scheduled Task to Stop your Windows Service before the Backup Starts

  1. Start the Windows Task Scheduler by running taskschd.msc from a command prompt. (You can also find it in Control Panel by searching for “Schedule tasks”).

  2. In the window that comes up, click Create Basic Task… on the right to launch the Create Basic Task Wizard:

    Create Basic Task

  3. Enter a name for your new task. Something like Stop service before backup starts should work nicely. Click Next > when you are done.

    Specify Task Name

  4. In the next couple of steps, we’ll specify when to stop the windows service. Since our backup occurs every Saturday at 10 PM, we’ll setup the task to shut down the service a minute before, at 9:59 PM:

    Stop Windows Service Weekly



    Stop Windows Service Every Saturday Night

    Click Next > to proceed.

  5. On the subsequent screen, select Start a program and click Next >:

    Start a Program

  6. Here is where we must specify the program to shut down the service. We’ll use the NET STOP command.

    1. Enter NET.EXE in the Program/Script line.
    2. And in the arguments field, enter

      STOP <Service-Name>

      where <Service-Name> is the name of the service. We have used “Spooler” 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!

    Click Next > to continue.

    Use NET STOP to shut down the service

  7. We’re almost done! You should see a screen confirming your settings. Click Finish to record this new scheduled task.

    Stop Service Task - Summary

Part 2: Create a Scheduled Task to Restart your Windows Service after the Backup Completes

Basically, repeat Part 1 but with the following changes:

  • When naming the task in Step 3, call it something like Restart service after the backup is done instead.

  • In Step 4, set the time so that the task will run AFTER the backup completes.

  • In Step 6, run the NET START command instead. That is, set the arguments field to

    START <Service-Name>

  • Here is what the ending summary screen should look like once you are done:

    Restart Service Task - Summary

And that’s it. Since implementing this tactic a few weeks ago, our customer’s backups have been problem-free. We’re confident that the same solution will work for you!

Posted in Support | Tagged , , | Leave a comment

Leave a Reply

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