Batch Processing simple backup SQL Server database

Source: Internet
Author: User
Tags mssqlserver
Recently I encountered a very common problem: the computer on the client side is always poisoned, which leads to database loss. So today I spent a little time doing a simple backup tool!

1. Set the followingCodeCopy to notepad;
2. Set two parameters:Db_documentIndicates the directory where the original database file is located,Db_doc_bakIndicates the directory to which the database needs to be backed up.;
3. Save it as a filename. bat batch file;

========================================================== ====================
@ Echo off
Color F2
Echo.
: Set the directory where the SQL Server database is stored.
Set Db_document = F: \ database_1 \*.*
: Set the folder directory for SQL Server database backup
Set Db_doc_bak = F: \ db_bak \
Echo...
Echo --- stop SQL Server Service
Net stop MSSQLServer
Echo --- copy database files to the backup directory
Xcopy % db_document % db_doc_bak %/S/e/y
Echo...
Echo --- start the SQL Server service
Net start MSSQLServer
Exit
========================================================== ====================

4. Operating Mechanism:
A. Manually run the batch processing file to back up database files;
B. If you need automatic backup, such as backup or scheduled backup when the computer is started, you can add a task to implement the following:
Control Panel-> Task Plan-> Add Task Plan-> select the batch file-> set the execution time-> OK!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.