Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create backup job on sql server. And i want to execute batch file in job. I just wonder the part of executing batch file from sql job. Do you have any idea?

Any help would appreciated.

use MyDb

BACKUP DATABASE MyDb TO DISK = 'C:\BackUps\MyDb.bak' WITH differential 

-- Call my batch file (which will zip MyDb.bak file)
share|improve this question

migrated from May 25 '10 at 12:48

This question came from our site for computer enthusiasts and power users.

Belongs on – Shevek May 25 '10 at 12:40

If you do this is as a SQL Server Agent job (from SSMS) it makes calling batch files a lot easier. Just add a step of type "Operating System (CmdExec)" and point it to your .bat file.

share|improve this answer

If you're using besides sql server 2008 enterprise (or above) then xp_cmdshell is the way to do it, although you'll have to enable it first with sp_configure.

If you are lucky enough to be on mssql 2008 enterprise then the backup compression feature is what you should be using.

You may want to do something a bit more advanced then calling a static.bat file. Here are some useful samples:
Sample sql script to zip and transfer database backup file
How to take SQL database backup in .zip format

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.