Batch processing to automatically back up and clear database files every day
Description
Use the task schedule to execute batch files at a specified time every day
1. Realize automatic Copy database backup files to another host
2. Automatically delete backup files for a specified number of days
1. Batch file code CopyDB2Lan (factory). Bat
* the beginning of the code *
@ echo off
Color 0e
Cls
Title Copy DB to the mirror host (by XX@163.com).
Set desthost=\\ 172.32.4.252\ SfisBackup
Set lc=y:
Set work_path=D:\ SfisBackup
Set stg_name=D:\ SfisBackup\ stg_123456.txt
Set pskip=4
Net use lc% desthost% "P@ssword" / user:administrator
For / r work_path% I in (sfis*.bak) do echo I > > stg_name%
For / f "skip=%pskip%" I in (% stg_name%) do set cpfilename=%%i
Copy cpfilename% lc% / y
If exist stg_name% del / Q stg_name%
Net use lc% / del
* end of code *
2. Batch file code CleanOldDB.bat
* end of code *
@ echo off
Lolor @ e
Cls
Title deletes files from N days ago (by XX@163.com).
Set work_path=D:\ SfisBackup
Set stg_name=D:\ SfisBackup\ stg_123456.txt
Set dd=10
Forfiles / p "% work_path%" / s / m *. * / d -% dd% / c "cmd / c del / Q @ path"
Pause
* end of code *