windows server automatic backup task of batch

  • 2020-05-09 19:37:13
  • OfStack

Integration command listing 1
Function: automatically backup database and create backup folder by date.

 
@echo off 
echo  Perform backup tasks  
echo  Stopping database...  
echo  Stopping the website database...  
net stop MySQL 
echo  Perform a backup database  
xcopy "D:\MySQL\data\*.*" D:\mysqlbak\webbak%date:~0,10%\ /e /y /c 
net start MySQL 
echo  Starting web database...  
echo  Exit the backup task  
echo . 
exit 

Apart:
Stop database command
 
net stop MySQL 

Copy database files
D:\MySQL\data\ store directories for databases
D:\mysqlbak\webbak is the database backup directory
%date:~0,10% create a directory for the current backup date
 
xcopy "D:\MySQL\data\*.*" D:\mysqlbak\webbak%date:~0,10%\ /e /y /c 

Start database
 
net start MySQL 

Listing 2 is the integration command
Features: automatic database backup and date rar encrypted package (password 123456).
 
@echo off 
echo  Perform backup tasks  
echo  Stopping database...  
echo  Stopping the website database...  
net stop MySQL 
echo  Perform a backup database  
xcopy "D:\host\mysql\data\*.*" E:\wwwroot\Default\webmysql\ /e /y /c 
net start MySQL 
echo  Starting web database...  
echo  Packing the website database...  
"C:\Program Files\WinRAR\WinRAR.exe" a -r -ibck -p123456 -y E:\wwwroot\Default\%date:~0,10%-WEBDATA.rar E:\wwwroot\Default\webmysql\*.* 
echo  exit RAR packaging  
echo  Delete replication database  
del /s /q E:\wwwroot\Default\webmysql\* 
echo  Exit the backup task  
echo . 
exit 

Apart:
The above repeat command is not repeated
Package and encrypt
C:\Program Files\WinRAR\ WinRAR.exe install directory for winrar compressor
123456 is the compressed packet encryption password
E:\wwwroot\Default\ is the packed directory
%date:~0,10% -WEBDATA. rar is the compressed file name, for example, today is 2012-12-27, the name is 2012-12-27-WEBDATA. rar
 
"C:\Program Files\WinRAR\WinRAR.exe" a -r -ibck -p123456 -y E:\wwwroot\Default\%date:~0,10%-WEBDATA.rar E:\wwwroot\Default\webmysql\*.* 

Delete copied data
E:\wwwroot\Default\webmysql\* is the backup directory, to facilitate the next backup 1 must be deleted. It's easy to repeat.
 
del /s /q E:\wwwroot\Default\webmysql\* 


Backup task download
Description:
Download the command from the web site to the specified directory
 
wget http:// Backup file WEB address /MySQLDATA-%date:~0,10%.rar -P E:\ The data backup \%date:~0,10% 

Download address: wget http: / / pan baidu. com/share/link? shareid = 4576 & uk = 956587458
On C: \ Windows \ System32
Note: you can use other tools for downloading, but this method is not recommended for large files. Not bad for small files.

Adding automated tasks
Open the task panel - > Task plan
Double-click add task plan
The next step is to browse to the CMD you created.
Customize the name of the task, if it is a database, it is recommended to backup once a day. You can set it up for 1 week if you have a website file.
The next step is to set the time. It is recommended to set it around 2-3 o 'clock.
The next step is to complete the task creation by entering the managed account and password.


Related articles: