通过几个步骤修剪旧备份
我正在寻找一种方法来精简旧备份。备份每天运行,我想随着备份变旧而增加间隔。
几天后,我想删除每日备份,只留下“周日”备份。几周后,仅应删除一个月中可用的第一个备份。
由于我正在处理历史备份,因此我不能只更改命名方案。
我尝试使用“查找”来查找,但找不到正确的选项。
有人有什么可以帮忙的吗?
I am looking for a way to thin out old backups. The backups are run on a daily basis, and I want to increase the interval as the backups become older.
After a couple of days I'd like to remove the daily backups, leaving only the "Sunday" backup. After a couple of weeks, only the first backup of a month that is available should be removed.
Since I am dealing with historic backups, I cannot just change the naming scheme.
I tried to use 'find' for it, but couldn't find the right options.
Anyone got anything that might help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这是历史数据,但您可能更喜欢提出一个命名方案来解决这个问题。通过两遍解决这个问题可能要容易得多:首先,根据日期重命名目录,然后选择将来要保留的目录。
如果
ls -l
输出中的所有目录日期看起来足够好,您可以进行快速近似:查看
/tmp/runme
,如果它看起来不错,您可以使用sh /tmp/runme
运行它。您可能希望修剪条目或类似的内容,这取决于您。如果所有备份都存储在名为例如:的目录中,
那么您的问题将减少为计算要保留和删除的名称。这个问题比搜索所有文件并尝试根据文件的创建时间选择保留和删除哪些文件要容易得多。 (请参阅
date "+%Y-%m-%d"
输出,了解生成此类名称的快速方法。)方便地命名后,您可以使用以下命令保留每个月的第一个备份:像这样的脚本:
保存其输出,检查它:),然后运行输出,类似于重命名脚本。
一旦您控制了过去的备份,您就可以从
date --date="Last Year" "+%Y"
生成2010
以及其他改进因此它会处理当月的“每周一次”,并永远保持下去。I know it is historical data, but you might prefer coming up with a naming scheme to assist this problem. It might be far easier to tackle this problem in two passes: first, renaming the directories based on the date, then selecting the directories to keep in the future.
You could make a quick approximation, if all the directory dates in
ls -l
output look good enough:Look at
/tmp/runme
, and if it looks good, you can run it withsh /tmp/runme
. You might wish to prune the entries or something like that, up to you.If all the backups are stored in directories named, e.g:
then your problem would be reduced to computing the names to keep and delete. This problem is much easier to solve than searching through all your files and trying to select which ones to keep and delete based on when they were made. (See
date "+%Y-%m-%d"
output for a quick way to generate this sort of name.)Once they are named conveniently, you can keep the first backup of every month with a script like this:
Save its output, inspect it :) and then run the output, similar to the rename script.
Once you've got the past backups under control, then you can generate the
2010
fromdate --date="Last Year" "+%Y"
, and other improvements so it handles "one a week" for the current month and maintains itself forever going forward.我在 @ajreal 的起点上为我的类似需求开发了一个解决方案。我的备份命名为“backup-2015-06-01T01:00:01”(使用
日期“+%Y-%m-%dT%H:%M:%S”
)。两个简单的步骤:触摸文件以在每个月的第一天继续使用 shell glob 模式,并使用
find
和xargs
删除超过 30 天的任何内容。I've developed a solution for my similar needs on top of @ajreal's starting point. My backups are named like "backup-2015-06-01T01:00:01" (using
date "+%Y-%m-%dT%H:%M:%S"
).Two simple steps: touch the files to keep using a shell glob pattern for first-of-each-month, and use
find
andxargs
to delete anything more than 30 days old.是的,例如
详细信息 -
http://www.gnu.org/software/findutils /manual/html_mono/find.html#年龄范围
yup, for example
details -
http://www.gnu.org/software/findutils/manual/html_mono/find.html#Age-Ranges