Automatically delete SQL Server backup files for a specified date using Task Scheduler

Source: Internet
Author: User

Automatically delete SQL Server backup files for a specified date using Task Scheduler

Command
forfiles [/P pathname] [/M searchmask] [/S]
[/C command] [/d [+ |-] {YYYY-MM-DD | dd}]

Method 1:
Description: You can delete a log file with a suffix of 7 days ago named log. If today is 6.29, then 6.22 will be deleted.
file that was previously created. will not be deleted to the Recycle Bin.
Specifies that the path is the folder path to be deleted, which can be placed under any folder.
forfiles/p d:\aizzw\log/m *.log-d -7/c "cmd/c del/f @path"
Parameter explanation:
Here,/P refers to the path of the backup file to be deleted
/M refers to the character to match, the wildcard character is the * number, and the suffix name can be modified according to the actual situation.
such as Zzw*.log;*.bak;*.txt
-d refers to the date, "-d-7" refers to the current date from the previous date minus 7 days forward.
/C refers to executing commands
@path return file Full path
Method 2:
Description: You can delete a log file with a suffix of 7 days ago named log.
You do not need to specify a path and must be placed under the file where you want to delete the log. Deletes the matching file under the current folder.
forfiles/m *.log-d -7/c "cmd/c del/f @path"
The above batch has been tested on a Windows 2003 virtual machine

The following is the use of this command.
forfiles/p < target directory name >/d < days >/C < commands >
See what the three parameters listed are useful:
/p Specifies the directory in which to look for files, the default is the current working directory.
/d Specifies a date or number of days to compare whether the last modified date of the file meets the criteria.
/C executes the command for each found file.
Example 1. To copy a file in the C packing directory with the last modified date greater than or equal to July 1, 2007 to the D Packing directory:
forfiles/p "c \"/d "2007-7-1"//"cmd/c copy @path d:\"
Example 2. Delete the file that was last modified on the C-disk backup directory 10 days ago:
forfiles/p "C:\Backup"/d-10/c "cmd/c echo deleting @file ... && del/f @path"
First look at the code to delete the file
FORFILES/P contains the full path of the file to be deleted (for example: F:\Logfiles)/M *.log-d -7/c "cmd/c del/f @path"
Explain the relevant parameters and commands
/P <Path>: Specifies the location at which to start searching for files, or defaults to the current directory if not specified.
/M <SearchMask>: Wildcard characters used in file lookups, such as "*.log" in code, are all log files, and of course you can specify all log files that start with manmee such as "Manmee_*.log". If you do not specify this parameter, the default is "*. *".
/d [{+|-}][{<date>|<days>}]: Specifies the last modification time of the file you want to select, with "/d-7" above for all files that are based on the day, 7 days old. Of course, you can also specify a specific time, for example: "/d-08/18/2009" so all files older than August 18, 2009. Note the specified time must be in the format "mm/dd/yyyy".
/C for all files to execute the specified command, the command body must be in double quotation marks ("), the default is" cmd/c echo @file ". The "cmd/c del/f @path" is used above to delete the specified file. (Here the @file and @path are variables and will be explained later.) )
Here are the parameters that are used in the above:
@PATH: Represents the full path of the file.

http://blog.csdn.net/babauyang/article/details/25742797

Automatically delete SQL Server backup files for a specified date using Task Scheduler

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.