简体   繁体   English

我需要找到一种方法来删除SQL Server备份文件夹中第三个.bak文件之后的所有内容

[英]I need to find a way to delete everything after the third .bak file in a SQL Server backup folder

Working on an old SQL Server cluster that has a limited amount of space available. 在具有有限可用空间的旧SQL Server群集上工作。 The cluster uses a SAS (server 2003 database) for data backups: fc_mdt , fc_mdt_trend , fc_adt . 群集使用SAS(服务器2003数据库)进行数据备份: fc_mdtfc_mdt_trendfc_adt Inside those folders are multiple .bak and .trn files. 这些文件夹中有多个.bak.trn文件。

I'm looking for a way to automate deletion of everything after the third .bak file when the folder contents are listed by date modified 我正在寻找一种方法来自动删除第三个.bak文件后的所有内容,当文件夹内容按修改日期列出时

If you are ok with using powershell, then this script will help you 如果你可以使用powershell,那么这个脚本将对你有所帮助

Get-ChildItem "C:\YourDirectory" | where{$_.Extension -eq ".bak"} |
sort -Property LastWriteTime -Descending| Select -Skip 3 | Remove-Item -Include .bak

If you're performing automated backups using a maintenance plan why not configure it to remove files older than a specific age, for example: 如果您使用维护计划执行自动备份,为什么不将其配置为删除早于特定年龄的文件,例如:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM