Carbonite Support > How to Use Batch Scripts with ...

How to Use Batch Scripts with CSSB

  • This article is for Windows only

Summary:

Carbonite Safe Server Backup has the ability to run batch scripts before or after any backup or restore operation. Certain requirements must be met in order for the batch script to run.

Solution:

The sections below are collapsed. Please click the section title to open / close a particular section.

Basic Usage

Basic tasks are easy to accomplish via script. It is simple to move files, create directories, or perform small tasks.

To use a batch script before or after a backup, navigate to the Advanced Backup Settings tab and click the Edit button. Browse for your script in the Run Before Backup or Run After Backup fields.

To use a batch script before or after a restore, expand the Review your restore settings panel at the bottom. Browse for your script in the Run script before restore or Run script after restore fields.

Batch Script Requirements

A few requirements must be met in order for any script to work successfully with CSSB:

  • All scripts must be batch files with the .bat file extension.
    • Powershell scripts are not supported directly, but can be launched indirectly. Refer to the Advanced Usage section below.
  • All scripts are run as the amandabackup / CarboniteUser user. This user must have the proper permissions to run all commands in the script.
  • The script cannot require any user interaction whatsoever.
    • This includes, but is not limited to:
      • UAC prompts
      • Requests to enter a password
      • Prompts to press any key to continue or similar
  • The script must exit when complete.
  • The script must NOT contain a robocopy command targeting the local backup.

If the batch script requirements are not met, backups and restores will stay in-progress until all scripts are completed or fail. If the script never exits, which most often occurs when the script is waiting for user input, then the backup or restore job will never finish.

If the script itself fails to run or returns an error, CSSB will fail the backup or restore run. The Details column on the Monitor or Report page will indicate that the script failed.

Advanced Usage

Batch scripting is very powerful, and scripts can be very complex. CSSB can run any batch script, no matter what it does or how complex it is, as long as it meets the basic requirements set above.

The runas command

There is a batch script command called runas that forces a task to run as a different user. Although CSSB will launch all batch scripts as amandabackup / CarboniteUser, the runas command allows users to specify commands within the script to be run as another user. This can be useful to run programs or commands that amandabackup / CarboniteUser cannot access.

This article describes the runas command in detail.

However, runas has one key flaw: it prompts for the user's password, which violates one of the requirements for batch scripts run by CSSB.

There is a workaround. The /savecred flag, when appended to a runas command, tells Windows to save the password entered for a particular command. Simply run the script from the command prompt with /savecred. The script will never ask for the password again, and the script can now be run with CSSB.

Powershell Scripts

Carbonite Safe Server Backup cannot run Powershell scripts natively. It can only run batch scripts. If a Powershell script is entered into CSSB as a pre-script or post-script, the backup or restore will never finish (just as if the script were waiting for user input).

However, it is possible to launch a Powershell script with a batch script. There are several ways to do so.

For example, it is possible to create a Scheduled Task to run a Powershell script. The Scheduled Task can be launched with a batch script, and this script can be run by CSSB before or after a backup or restore.

Keep in mind that CSSB will begin the backup or restore immediately when the batch script exits. CSSB doesn't know about the Powershell script that was launched via the Scheduled Task. It only knows about the the batch script itself.

Depending on what the Powershell script does, it may not have time to work before the backup or restore begins. Therefore, it is a very good idea to add a delay in the batch script to allow time for the Powershell task to complete, or to add code into the batch script that refrains from exiting until the intended goal(s) of the Powershell task(s) are accomplished.

Feedback