| Walk-through 6 : Using command line to run a job 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 <JOB NAME> <BACKUP TYPE> [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 :
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 Files\SQL Server Backup 7\cmdrun.exe "db1_backup" 0 2 This walk-through will show you: 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:\backup.bat : @echo off C:\Program Files\SQL Server Backup\cmdrun.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: |