Solved

DOS Batch File to backup a SQL Database

Posted on 2012-12-31
3
614 Views
Last Modified: 2013-01-01
Is there a way to run a DOS batch file that backups a single SQL database?

I can easily run a db backup in SQL Management Studio Express:

BACKUP DATABASE [LivingTreasures] TO  DISK = N'C:\Data\SQL\Backup\lt.bak' WITH  COPY_ONLY, NOFORMAT, INIT,  NAME = N'LivingTreasures-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO

But, now I want to have a batch file (backup.cmd) that can do this. Of course, it needs to connect to the db engine (SOTASERVER\SQL2008), supply password (sa/pw) and the db name (LivingTreasures).

Help!

High points for a speedy solution that will work. :-)
0
Comment
Question by:SOTA
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
Steve Wales earned 500 total points
Comment Utility
Found a post here that claims it works:

http://www.howtogeek.com/50299/batch-script-to-backup-all-your-sql-server-databases/

You can pass username and password by:

sqlcmd -U sa -P pwd

If you don't like the inline command as per the example you could use an input file:

sqlcmd -U sa -P pwd -i c:\backups\my_backup_script.sql -o c:\backups\output_of_commands.txt

Other parameters:

-S parameter passes server name
-d parameter passes DB name

Would highly recommend against putting the sa password in a script like that though for security purposes.

Have not tested this myself though.

As an aside, why do you want it in a script like this ?  If for automatic scheduling, why not use a maintenance plan / SQL Serve Agent ?
0
 

Author Comment

by:SOTA
Comment Utility
Thanks, I will try to get this to work.

The reason why I am not using a maintenance plan is because I need to export the dB to a web server to drive a website.

The person doing the export has no knowledge of SQL. Nor do I want her in there behind-the-scenes. Too dangerous!

So, if I can have her click a CMD file and have the export be done for her - that will help immensely.
0
 

Author Closing Comment

by:SOTA
Comment Utility
Awesome, got it to work perfectly. I then used 7 ZIP to compress it!!!

Life is good again. :-)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

9 Experts available now in Live!

Get 1:1 Help Now