english francais

Using oSQL to backup and restore your databases

This article describes how you can use oSQL to backup and restore your ENT Server databases.

Article Details

You can use the osql command-line tool to access, query, or run scripts against, your SQL Server or MSDE database.  For example, to backup your ENT Server databases you could run the following from the command line:

osql -S narcisus -E -Q " BACKUP DATABASE mf_enterprise TO DISK = 'C:\Temp\ent_database.bak' "

  • -S narcisus specifies the server name to be "narcisus."  For a database on the local machine, specify either "(local)", or "(local)\[InstanceName]" if you are using a named instance.
  • -E specifies that osql should use a trusted connection.  You could instead specify a username using the -U option.
  • -Q specifies that oSQL should execute the SQL query that follows in double-quotes and then exit
  • BACKUP DATABASE mf_enterprise TO DISK = 'c:\Temp\' this is the actual query that will get exexuted... as you can see this simply backs up the mf_enterprise database to the file C:\Temp\ent_database.bak.

Similary, to restore the above backup you could run the following from the command line:

osql -S narcisus -E -Q " RESTORE DATABASE mf_enterprise FROM DISK = 'C:\Temp\ent_database.bak' "

You can find further information on the RESTORE DATABASE command for MS SQL Server, including various additional parameters that you could use, on the Microsoft Website.