Groups | Blog | Home
all groups > sql server (alternate) > february 2005 >

sql server (alternate) : Will OSQL Produce SQL Backup?


john_20_28_2000 NO[at]SPAM yahoo.com
2/21/2005 1:01:44 PM
Will osql product an SQL backup? By this I mean a text file with the
transact-sql in it so I can use it to recreate the database elsewhere?
Thank you.
Simon Hayes
2/21/2005 10:20:01 PM

[quoted text, click to view]

No - if you want to generate .sql scripts to recreate a database and its
objects, you need to use Enterprise Manager or Query Analyzer, or write your
own code to use the SQLDMO API. But if you just want to backup the database
to a backup file, so you can restore it later, then yes:

osql -S MyServer -E -Q"backup database MyDB to disk = 'c:\temp\mydb.bak'"

Then copy mydb.bak to the target server and restore it:

osql -S MyServer -E -Q"restore database MyDB from disk = 'c:\temp\mydb.bak'"

You might find these links helpful (I'm guessing you have MSDE since you
want to use osql.exe specifically):

http://support.microsoft.com/default.aspx?scid=kb;en-us;314546
http://www.aspfaq.com/show.asp?id=2442

Simon

AddThis Social Bookmark Button