Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

backup and restore from dos prompt

Posted on 2002-06-29
4
Medium Priority
?
249 Views
Last Modified: 2012-05-04
I am looking for dos command to take backup and restore complete database of sql server 7.0 so that i can write script to automate backups and restore whenever required.
0
Comment
Question by:sanjaykattimani
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
miron earned 600 total points
ID: 7119012
did you try

osql -S<server_name> [ -U<user_name> -P<password> | -E ] -Q"BACKUp DATABASE <database_name> to disk = 'C:\back' WITH INIT"

or

osql -S<server_name> [ -U<user_name> -P<password> | -E ] -i <command_file_path>

in the file located at <command_file_path> save command
BACKUp DATABASE <database_name> to disk = 'C:\back' WITH INIT


this file may contain entire sql script where you can concatenate backup file name using getdate() or any other sql server function, so that a unique file name created each time. Also, it can delete existing backups older then certain time using xp_cmdshell extended stored procedure. It can also follow a set of rules what type of backup to create - full backup, differential backup, log backup, or even more advanced backup operations.

sql server enterprise manager offers a pretty cool gui based wizard that will walk you through a set of questions to create a scheduled maintenance plan that will set off backup process on its own, I would yield that it offers less control over the backup process then a transact sql script, but it is worthy feature to learn and most of the time it is more then enough to have a good backup process in place.
0
 
LVL 3

Author Comment

by:sanjaykattimani
ID: 7121465
Great! osql works and i am able to take the backup. Now how to restore the same?
when i used the following command

C:\WINDOWS\Desktop>osql -Ssql_domain -Usa -P -Q"restore database master from dis
k='c:\masterdb'

It generated following command
Msg 3108, Level 16, State 1, Server SQL_DOMAIN, Procedure , Line 1
[Microsoft][ODBC SQL Server Driver][SQL Server]RESTORE DATABASE must be used in
single user mode when trying to restore the master database.
Msg 3013, Level 16, State 1, Server SQL_DOMAIN, Procedure , Line 1
[Microsoft][ODBC SQL Server Driver][SQL Server]Backup or restore operation
terminating abnormally.
 
0
 
LVL 3

Author Comment

by:sanjaykattimani
ID: 7121483
Let me know how do i restore the db.
0
 
LVL 9

Expert Comment

by:miron
ID: 7124000
osql -S<server_name> [ -U<user_name> -P<password> | -E ] -i
<command_file_path>
in the command file copy/paste following script

---
use master

ALTER DATABASE <database_name> SET SINGLE_USER WITH ROLLBACK IMMEDIATE

restore database <database_name> from disk = '<file_path>' [ with replace]"

ALTER DATABASE <database_name> SET MULTI_USER

-- with replace will force restore over existing database.
---

Cheers
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question