04 66 72 51 22

Stopping a service or running a script before the backup

This page is intended for administrators who need to prepare a Windows workstation or server before backing it up: stopping a service that holds files open, closing an application, or running a script (database export, volume mount). It describes the @Service, @Program and @RunProgram directives, when they run, and the messages they produce in the report.

What you will have at the end

A backup profile that, on every run:

  • stops the specified services or closes the specified programs before reading the files;
  • runs your scripts before and after the backup;
  • restarts the services it stopped;
  • reports any action that failed.

Prerequisites

  • A BeBackup 7 agent for Windows. On macOS and Linux, @Service and @Program do nothing: the report flags this with a warning. @RunProgram does work, with no time limit; a .sh script is run once only, at the start, without arguments.
  • A profile whose Windows owner is an administrator of the machine. Otherwise, no @ line is executed and the report carries the error Les commandes de la source (lignes @) sont réservées aux administrateurs, et le propriétaire du profil n'en est pas un : elles ne sont pas exécutées.
  • The exact names of the services, programs and scripts concerned.
  • Access to the agent configuration in the web interface.

Where to enter the directives

In the web interface, open the configuration of the medium's agent. In the Autres commandes block, click Ajouter une commande, enter one directive per line, then save.

Steps

1. Stopping services

@Service ServiceName1,ServiceName2

Separate the names with a comma, with no space after the comma. The services are stopped before the files are read, then restarted.

When they are restarted depends on VSS (Volume Shadow Copy Service):

  • if the backup uses VSS, the services restart as soon as the snapshot has been taken. They are therefore only stopped for a few moments;
  • otherwise, they restart at the end of the backup.

To force the restart to take place at the end of the backup even when VSS is used, write @!Service instead of @Service.

2. Closing programs

@Program program1.exe,program2.exe

Give the name of the executable file, without a path. The agent first asks the program to close. If it is still running after 30 seconds, it is forcibly terminated. Programs that have been closed are not restarted after the backup.

A forcibly terminated program loses any unsaved data. Reserve this directive for programs that save their work continuously.

3. Running a script

@RunProgram "C:\Scripts\before backup.cmd"

The behaviour depends on the file type:

  • a .bat or .cmd file is run twice. At the start, with the argument begin. At the end, with the argument end, at the same point as the service restart described above. Your script must test this argument;
  • any other program is run once only, at the start.

The agent waits for the command to finish before continuing. To make a .cmd script run only once, add -ExecOnce=begin or -ExecOnce=end.

As with services, write @!RunProgram instead of @RunProgram so that the end call takes place at the end of the backup, even when VSS is used.

4. Controlling how long a command runs

You can add options after the command. If the path contains spaces, enclose it in quotation marks, then place the options after the closing quotation mark. Durations are expressed in seconds.

OptionEffect
-BeginBck_WarnIfDurationLT=Error in the report if the start command runs for less than this.
-BeginBck_WarnIfDurationGT=Error in the report if the start command runs for longer than this.
-BeginBck_KillIfDurationGT=Forced termination of the start command beyond this duration.
-EndVssOrBck_WarnIfDurationLT=Same for the end command.
-EndVssOrBck_WarnIfDurationGT=Same for the end command.
-EndVssOrBck_KillIfDurationGT=Same for the end command.

Example:

@RunProgram "C:\Scripts\database export.cmd" -BeginBck_KillIfDurationGT=1800 -EndVssOrBck_WarnIfDurationLT=0

By default, a command that runs for less than 5 seconds produces an error in the report. This check detects a script that fails immediately. If your command is normally fast, disable it with -BeginBck_WarnIfDurationLT=-1 and -EndVssOrBck_WarnIfDurationLT=-1.

Checking that it worked

Run a backup, then read its report. None of the following lines should appear:

  • Arrêt du service "…" impossible.
  • Démarrage du service "…" impossible.
  • Arrêt du programme "…" impossible.
  • L'exécution de la commande "…" a duré moins de …
  • L'exécution de la commande "…" a duré plus de …
  • L'exécution de la commande "…" a duré plus de … et son arrêt a été forcé.
  • Commande … invalide.

The last message indicates a misspelt directive: the directive name is quoted without the @. A line that starts with @ but contains no space is ignored without any message: check that a space does separate the directive from its parameters.

If a service could not be restarted, restart it manually and check its exact name.

BeBackup is backup built for IT service providers

Backup and restore of workstations, servers, virtual machines and Microsoft 365, encrypted at source with a key we do not hold, on the hosting of your choice.