Solved

DOS Batch File to backup a SQL Database

Posted on 2012-12-31
3
627 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 eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Suggested Solutions

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

679 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