Walk-through 6 : Using command line to run a job (for v7)

If you plan to integrate SQL Server Backup to other production batch jobs , you can use command line to start a pre-defined job. If your SQL Server Backup is early than 7.0.6.5012 version , please download a latest one to do that.

The command line format as following:

{installation directory}cmdrun.exe [REPORT LEVEL]

Description :
The cmdrun send a run job command to Backup Agent , just like you do it on GUI. cmdrun.exe will not exit until the job finishes.

Parameters :
JOB NAME : The name of the job , case sensitive and must fully match what you see in GUI. If the it contains spaces , please use double quotation marks (" ") before and after the job name.

BACKUP TYPE : It can be one of following values :

  • -1 : Use the backup type defined in job for backup job. This value is always set to -1 if the job is NOT a backup job.
  • 0 : Force to use full backup for backup job
  • 1 : Force to use differential backup for backup job
  • 2 : Force to use transaction log backup (remove inactive log entries)
  • 3 : Force to use transaction log backup (keep inactive log entries)
  • 4 : Force to back up tail of transaction log , and leave database in restoring state.

REPORT LEVEL : It can be one of following values :

  • 0 : Silence. Report nothing if no error occurs. If you do not specify this parameter , the program uses 0 as default report level.
  • 1 : Simple. Report some messages about the job.
  • 2 : Detail. Report all messages. Like what you see in GUI.

Return Code :

  • 0 if job successes
  • -1 if job fails
  • -2 if command fails


Example :
Suppose a backup job name is "db1_backup" , and plan to force to execute a full backup on database , printf all message , the command line as following:

C:Program FilesSQL Server Backup 7cmdrun.exe "db1_backup" 0 2



This walk-through will show you:

  • How to get job status in command line
  • How to create a simple batch file

In this walkthrough , we suppose you have created a backup job in Backup Manager . We create a simple batch file , this batch file execute a full backup ,then print job result on console screen .
Steps : 1, 2


1) We create a batch file as following , and save as C:ackup.bat :
@echo off
C:Program FilesSQL Server Backupcmdrun.exe "db1_backup" 0 0
if errorlevel 0 goto jobok
if errorlevel -1 goto jobfailed
if errorlevel -2 goto commandfailed

:jobok
echo job ok.
goto end

:jobfailed
echo Job failed , please view job report to get detail informaion.

goto end

:commandfailed
echo **Failed to send command to Backup Agent!

:end


2) Run the backup.bat file in command console , the result as following: