Solved

DOS Batch File to backup a SQL Database

Posted on 2012-12-31
3
625 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
ID: 38733949
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
ID: 38734902
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
ID: 38735022
Awesome, got it to work perfectly. I then used 7 ZIP to compress it!!!

Life is good again. :-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Alter a column in sql 34 30
Query to return total 6 21
Present Absent from working date rage 11 36
SQL Server 2008 R2, need a pivot/cross tab query... 4 26
     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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