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

Can someone tell me why I can't backup my database with the script below? I can run the script but it didn't create the backup.
I"m using SQL Server 2008

SET @pathName = 'C:\Backup\MyBackup.bak'


EXEC sp_add_jobstep
@command = 'BACKUP DATABASE MyBackup TO DISK = @pathName WITH INIT',
share|improve this question

Have you looked at

It looks like you are trying to insert a local variable into a SQL Server Agent job.

Based on this section:

[ @command= ] 'command'

The commands to be executed by SQLServerAgent service through subsystem. 

command is nvarchar(max), with a default of NULL. SQL Server Agent provides token substitution that gives you the same flexibility that variables provide when you write software programs.

You may want to try using tokens instead of local variables. This article may be a good starting point for you:

As it points out, your solution will look something like:

@command = 'BACKUP DATABASE MyBackup TO DISK = $(ESCAPE_SQUOTE (@pathName)) WITH INIT'
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.