In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to use the FORFILES command to delete the batch of SQLServer backup". In the daily operation, I believe many people have doubts about how to use the FORFILES command to delete the batch of SQLServer backup. The editor consulted all kinds of data and sorted out a simple and easy-to-use method of operation. I hope it will be helpful to answer the doubt of "how to use the FORFILES command to delete the batch of SQLServer backup". Next, please follow the editor to study!
Although there are many ways to solve this problem, we can use T-SQL code to handle the file deletion process. I use the xp_cmdshell command and the FORFILES command to handle procedures similar to the ones you listed. You can get reliable information about FORFILES from Microsoft TechNet, but in this article, I will cover a large number of structures and uses of FORFILES to achieve your goals.
The FORFILES command selects a subset of the file and executes a command against that subset. This command requires the following parameters and accepts the following variables.
Parameters.
Parameter name description / p path / m search mask (default is *. *) / s if this parameter is included, the subdirectory will be retrieved recursively. / c execute the command for each file in the result set, and the command must be enclosed in double quotation marks. By default, "cmd c / echo @ file" / d regards the latest change date as the file standard for the date range selected by the file. When the / d parameter is in MM/DD/YYYY format, files that meet the specified + /-date criteria are also included. When the file format is smallint (- 32768-32768) file + /-file with a change date + / -, the number of times from the current date to that date will be included in the file result set.
Variabl
Variable name description @ FILE file name @ FNAME unextended file name @ EXT file extension @ PATH file absolute path @ relative path of RELPATH file @ ISDIR if the file type is a directory, then determine whether it is the latest change date postmark on the TRUE@FSIZE file size (in bytes) @ FTIME file postmark @ FTIME file
Using these parameters, you can construct the following example to solve the problem of deleting backup script files. You can create scripts based on changing the time / date or backup type. You can even construct scripts that can refer to both standards at the same time.
We will take a closer look at these possible scripts. Remember, you will execute this process from within the T-SQL code, so you need to summarize these statements in EXEC xp_cmdshell 'FORFILES COMMAND' format in an xp_cmdshell access. Note that in all cases I use the / Q and / F tags as delete commands. This means that the command will use quiet mode (/ Q) or even delete read-only files (/ F).
Exampl
Delete all .sql files in the C:Backup directory and its subdirectories when the file change date is later than 10 C:Backup 18.
EXEC xp_cmdshell 'FORFILES / p c:BACKUP / s / m *. Sql / d 10 take 18max 2008 / c "CMD / C del / Q / F @ FILE"'
Delete .sql files in all C:Backup directories and its subdirectories when the file change date is more than 30 days.
EXEC xp_cmdshell 'FORFILES / p c:BACKUP / s / m * .sql / d-30 / c "CMD / C del / Q / F @ FILE"'
When the file change date is more than 30 days and the file name starts with "F _", delete all .sql files in the C:Backup directory and its subdirectories.
EXEC xp_cmdshell 'FORFILES / p c:BACKUP / s / m F_*.sql / d-30 / c "CMD / C del / Q / F @ FILE"'
At this point, the study on "how to use the FORFILES command to delete batches of SQLServer backups" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.