3

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?

Josiah
  • 269
  • 1
  • 5
  • 10

2 Answers2

7

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.

K. Brian Kelley
  • 9,034
  • 32
  • 33
3
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.)

Evan Anderson
  • 141,881
  • 20
  • 196
  • 331