Run a backup or restore from a script (agent command line)
This page is intended for administrators who wish to drive the BeBackup agent from a script, a task scheduler or a monitoring tool. It covers the general syntax, the most useful commands and the exit codes. The complete reference is the agent's built-in help, displayed by the -Help command. This page applies to the BeBackup 7 agent for Windows.
What you will achieve
By the end of this page, you will know how to:
- list the profiles on a machine;
- start the backup of a profile and wait for it to finish;
- restore files to a folder;
- interpret the exit code in your script.
Prerequisites
- The BeBackup agent is installed and its Windows service
BeBackup Backup Agent(technical namebbAgent) is running. Backup commands go through this service. - You run the commands from the agent's installation folder. An elevated command prompt is only required for commands that act without going through the service (
-HyperV…,-ListVssWriters,-DriveSync…): without elevation, they stop with exit code740. A user who is not an administrator only sees their own profiles. - You know the profile name as it appears in the agent's interface.
General syntax
Every command starts with -CommandLine, which must be the first argument:
bbAgent.exe -CommandLine <commande> [paramètres]
Without -CommandLine in first position, bbAgent.exe opens the agent's graphical console: the command is not run, and nothing is written to the output. Only -Help, -h, -? and --help respond without this prefix.
A profile is designated with -Profile=<profil>. The agent first looks for a section with that name (for example Profile_12, as displayed by -GetProfileList), then for a profile bearing that name in the interface. The section is the only way to designate a profile that has no name. If the name contains spaces, enclose the whole parameter in quotation marks: "-Profile=Serveur comptable".
To display the full help, with an example for each command:
bbAgent.exe -CommandLine -Help
Steps
1. List the profiles
bbAgent.exe -CommandLine -GetProfileList
The command displays a two-column table, under the header Section ProfileName: the profile's section (for example Profile_12) and its name. For a profile with no name, the name column is empty: in that case, designate it by its section.
2. Test a profile's connection
bbAgent.exe -CommandLine -TestConnection -Profile=MonProfil
The command tests the connection to the server and completes the profile with the information returned by the server.
3. Start a backup and wait for it to finish
bbAgent.exe -CommandLine -StartJob -Profile=MonProfil
The command asks the service to start the profile, then waits until the backup has finished. If that profile is already running, it is not started again: the command waits for the current run to finish.
-Profile= on its own, without -StartJob, starts nothing: the command is rejected with exit code 1 and the following message:
Incomplete command: -Profile= alone does not say what to do with that profile.
To start a backup: bbAgent.exe -CommandLine -StartJob -Profile=<name>
For a MASTER-VM profile, which drives a group of virtual machines, -StartJob returns without waiting for the group to finish.
To follow progress from another window:
bbAgent.exe -CommandLine -GetProfileProgressInfo -Profile=MonProfil
Empty output means the profile is idle. It does not tell you whether the last backup succeeded.
4. Restore files
bbAgent.exe -CommandLine -Restore -Profile=MonProfil "-Item=C:\Donnees\Contrat.docx" "-Dest=C:\Restauration"
-Itemdesignates a file or a folder. You can repeat-Itemas many times as necessary.-Destdesignates the destination folder. Without-Dest, each item is returned to its original location.-BackupID=<id>selects a specific backup. Without this parameter, the latest backup is used.
Restoring whole disks, partitions and VMware ESXi virtual machines is also available from the command line (-RestoreDisks, -RestoreToVm). Their syntax is described in the -Help output.
Exit codes
| Code | Meaning |
|---|---|
0 | The command completed successfully. |
1 | No command was recognised, or the command is incomplete (for example -Profile= without -StartJob). |
2 | The command failed. The reason is on the last line of the output. An error from the command itself (profile not found, etc.) is also written to bbAgent-console.log; the failure of a job handed over to the service is written to bbAgent-service.log. |
740 | The command must be run from an elevated command prompt. |
For a backup, code
0means that the backup ran to completion. It does not tell you whether it finished with errors or warnings. To find out, consult the backup report.
Standard output and error output
At the start of each command, the agent writes a version line, for example BeBackup agent … (x64). This line goes to the error output, not to standard output. You can therefore redirect standard output to a file or to another program without it containing this line:
bbAgent.exe -CommandLine -GetProfileList > profils.txt
The file then contains the table of profiles, including its header line.
Waiting for the command to finish in an interactive prompt
bbAgent.exe is a graphical program. In an interactive cmd prompt, control returns without waiting for the command to finish, and %ERRORLEVEL% does not contain the correct code. To wait for the command and read its exit code:
- in
cmd, run it withstart /b /wait bbAgent.exe -CommandLine …; - in PowerShell, use
Start-Process -Wait; - in a
.batfile, a direct call waits for the command to finish.
Common error messages
| Message | Meaning |
|---|---|
Unknown command. | The command does not exist. Exit code 1. (If -CommandLine is not the first argument, no message is written: the graphical console opens.) |
Incomplete command: -Profile= alone does not say what to do with that profile. | -Profile= was given without a command. To run a backup, add -StartJob. Exit code 1. |
Error: No profile named "…" was found. | The profile name does not match any profile. Check it with -GetProfileList. |
Error: The command to start profile "…" was not accepted by the agent (is it actually running?). | The bbAgent service is stopped or not responding. |
Error: Profile "…" did not start within the allotted time (60s). | The service accepted the request, but the backup did not start within 60 seconds. Consult bbAgent-service.log. |
The backup of profile "…" failed: … | The backup failed as soon as it started (licence refused, etc.). The command stops immediately with code 2. |
Check that it worked
- Check the exit code in your script, for example with
%ERRORLEVEL%in a.batfile (in an interactive prompt, see above). - For a backup, open the backup report in the agent or in the web interface.
- For a restore, check that the files are present in the destination folder.
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.