jn025
jn025

Reputation: 2895

Automatically execute mssql query?

I'm trying to make a way to do automatic backups. Since I'm using SQL Server 2008 Express I (apparently) can't use the agent. So I've found a sql script to do the backup. I'm using a bat file linked with windows task scheduler to launch the script every day. Here's the bat:

"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" -S (local)\SQLExpress -i C:\DBbackups\SQLExpressBackups.sql

sql:

BACKUP DATABASE MuOnline TO  DISK = N'C:\DBbackups\Online' 
WITH NOFORMAT, INIT,  NAME = N'Online Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10

BACKUP DATABASE Ranking TO  DISK = N'C:\DBbackups\Ranking.bak' 
WITH NOFORMAT, INIT,  NAME = N'Ranking Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10

BACKUP DATABASE MU2003_EVENT_DATA TO  DISK = N'C:\DBbackups\2003_EVENT_DATA.bak' 
WITH NOFORMAT, INIT,  NAME = N'2003_EVENT_DATA', SKIP, NOREWIND, NOUNLOAD,  STATS = 10

BACKUP DATABASE SCFMuTeam TO  DISK = N'C:\DBbackups\SCF.bak' 
WITH NOFORMAT, INIT,  NAME = N'SCF Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10

GO

The sql works fine and creates the backups but I have to execute it manually - so when the task scheduler runs the bat file it doesn't execute the sql - is this an error with the bat file or do i need to add to the sql?

Upvotes: 1

Views: 329

Answers (1)

vasin1987
vasin1987

Reputation: 2012

Your screen is not correct. Put SQLCMD.EXE into program to run and -S (local)\SQLExpress -i C:\DBbackups\SQLExpressBackups.sql as argument

http://technet.microsoft.com/en-us/library/ms162773.aspx

Upvotes: 1

Related Questions