Solved

backup and restore from dos prompt

Posted on 2002-06-29
4
248 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 150 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
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…

623 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