Solved

DOS Batch File to backup a SQL Database

Posted on 2012-12-31
3
620 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

808 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