The database backs up files daily, but only seven days of backup is required, writing a batch script file to automatically delete files from seven days ago and set up scheduled tasks
The Forfiles command is required to delete files automatically
Forfiles Parameters:
The path specified by/p
/s includes sub-directories
/M Lookup filename Mask
/d Specifies the date, with an absolute date and a relative date, where-7 refers to the current date 7 days ago
The command line run by/C represents the command executed for each file. The command string should be enclosed in double quotation marks.
The default command is "cmd/c echo @file". The following variables can be used in the command string:
@file-Returns the file name.
@fname-Returns the file name without an extension.
@ext-returns only the extension of the file.
@path-Returns the full path of the file.
@relpath-Returns the relative path of the file.
@isdir-Returns "TRUE" if the file type is a directory, or "FALSE" if it is a file.
@fsize-Returns the file size in bytes.
@fdate-Returns the date the file was last modified.
@ftime-Returns the time the file was last modified.
Create a new Notepad file, enter the following command, and name the file "Delete backup files up to 7 days ago. bat", note the path where the files are to be deleted
@echo off #需要密码forfiles/P "C:\autoscpfile\data"/s/m *.bak/d -7/c "cmd/c del/f @path" forfiles/p "C:\autoscpfile\lo G "/s/m *.txt/d -7/c" cmd/c del/f @path "
Set a timed task after the script file is written.
To open a scheduled task on Windows Server 2003
"Start", "All Programs", "Accessories", "System Tools", "Task Scheduler"
White space Right-click the new scheduled task, name the task delete backup 7 days ago, double-click the task
Select browse, locate the path to the batch file, set the password, and the password is the login password for the user who executed the script
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/9A/B3/wKioL1lZtVyROZKYAAAlWvbhJvY421.png "style=" float : none; "title=" Qq20170703110805.png "alt=" Wkiol1lztvyrozkyaaalwvbhjvy421.png "/>
Set the time the script executes, execute the script 3:00 every day, and then click Apply to determine
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/9A/B3/wKiom1lZtVyhbueZAAAedBgtwTc631.png "style=" float : none; "title=" Qq20170703110849.png "alt=" Wkiom1lztvyhbuezaaaedbgtwtc631.png "/>
To open a scheduled task on Windows Server R2
Start, Administrative tools, Task Scheduler
Right Action bar, click Create Task
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/9A/B4/wKioL1lZulKgpy2fAABzdL4Fcac433.png "title=" Qq20170703111946.png "alt=" Wkiol1lzulkgpy2faabzdl4fcac433.png "/>
Name the task, select the configuration, run with the highest privileges
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/9A/B5/wKioL1lZv5HiZZC_AAAzoD2c05w160.png "style=" float : none; "title=" Qq20170703114609.png "alt=" Wkiol1lzv5hizzc_aaazod2c05w160.png "/>
Select Trigger, New
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/9A/B5/wKioL1lZv5HyN2V2AAAf0k5gwAk552.png "style=" float : none; "title=" Qq20170703114637.png "alt=" Wkiol1lzv5hyn2v2aaaf0k5gwak552.png "/>
Select New trigger, set time for task execution, determine
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9A/B5/wKiom1lZv5LCd89NAAAyKA_Vi-o646.png "style=" float : none; "title=" Qq20170703115148.png "alt=" Wkiom1lzv5lcd89naaayka_vi-o646.png "/>
Select operation, New
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/9A/B5/wKioL1lZv5PQUR2bAAAhoO3a0vI220.png "style=" float : none; "title=" Qq20170703115202.png "alt=" Wkiol1lzv5pqur2baaahoo3a0vi220.png "/>
Click Browse, select the script path to execute, start with the option to fill in the script path, and then determine
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9A/B5/wKiom1lZv5OCZ4O_AAAWviWoS1U234.png "style=" float : none; "title=" Qq20170703115217.png "alt=" Wkiom1lzv5ocz4o_aaawviwos1u234.png "/>
Windows automatically deletes batch scripts for files that are N days ago