What is a simple command line program or script to backup SQL server databases?

Frank Krueger picture Frank Krueger · Sep 23, 2008 · Viewed 236.2k times · Source

I've been too lax with performing DB backups on our internal servers.

Is there a simple command line program that I can use to backup certain databases in SQL Server 2005? Or is there a simple VBScript?

Answer

Craig Trader picture Craig Trader · Sep 23, 2008

To backup a single database from the command line, use osql or sqlcmd.

"C:\Program Files\Microsoft SQL Server\90\Tools\Binn\osql.exe" 
    -E -Q "BACKUP DATABASE mydatabase TO DISK='C:\tmp\db.bak' WITH FORMAT"

You'll also want to read the documentation on BACKUP and RESTORE and general procedures.