Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

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.)

share|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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

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.