Solved

Backup and Restore DB using DOS Batch command

Posted on 2008-10-14
2
1,608 Views
Last Modified: 2012-05-05
Hi Everyone:

How could I stop the DB service, backup DB and restart the SQL Server 2005 in Batch command? My intention is to automate the process of backup of a DB to a remote location. Is there any better way to accomplish this task?

Thank in advance.

Regards,
LS
0
Comment
Question by:IVISMY
2 Comments
 
LVL 9

Accepted Solution

by:
Sander Stad earned 250 total points
ID: 22718346
I wouldn't stop de SQL Server service because than you wouldn't be able to execute any queries against it. You can use the following code to create a backup.
The osql.exe is replaced with "sqlcmd" in SQL Server 2005
The only reason why you should stop the SQL Service is when you just want to make a copy backup using the "COPY" or "XCOPY" command in de command line.
More information on the command:
"{sqlserverinstall}\80\Tools\Binn\osql.exe" -E -Q "BACKUP DATABASE {databasename} TO DISK='{location to copy to}' WITH FORMAT"

Open in new window

0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now