I need to create a scheduled task that will backup a database within a SQL Server 2005 instance.

Is there a command line argument that I can use to achieve this?

link|improve this question

75% accept rate
feedback

2 Answers

up vote 3 down vote accepted
OSQL -E -Q "BACKUP DATABASE database_name TO DISK = 'path and filename'"

As in:

OSQL -E -Q "BACKUP DATABASE master TO DISK = 'C:\master.bak'"

Be sure you're running that as a user who has rights to backup that database (or, alternatively, use the "-U" and "-P" arguments to supply a username/password on the command line... not a good idea, thought.)

link|improve this answer
Thanks a lot, this worked for me. – Josiah Jul 17 '09 at 4:14
Also assumes the default instance other wise you have to add the server as well. – SpaceManSpiff Jul 17 '09 at 14:44
dont forget WITH INIT to overwrite the master.bak file, otherwise you'll end up with a massive .bak file with full backups appended to it – Nick Kavadias Jul 19 '09 at 14:40
feedback

Actually better here is to use SQLCMD instead of OSQL. OSQL is considered deprecated as of SQL Server 2005, though it's still around in SQL Server 2008.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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