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!