目前,我试图找出整理甲骨文恢复是由cron创建日志文件的方法...
目前,我们的Oracle备用恢复过程是由cron调用每15分钟使用以下命令:
0,15,30,45 * * * * /data/tier2/scripts/recover_standby.sh SID >> /data/tier2/scripts/logs/recover_standby_SID_`date +\%d\%m\%y`.log 2>&1
这将创建一个看起来像文件:
$ ls -l /data/tier2/scripts/logs/
total 0
-rw-r--r-- 1 oracle oinstall 0 Feb 1 23:45 recover_standby_SID_010213.log
-rw-r--r-- 1 oracle oinstall 0 Feb 2 23:45 recover_standby_SID_020213.log
-rw-r--r-- 1 oracle oinstall 0 Feb 3 23:45 recover_standby_SID_030213.log
-rw-r--r-- 1 oracle oinstall 0 Feb 4 23:45 recover_standby_SID_040213.log
-rw-r--r-- 1 oracle oinstall 0 Feb 5 23:45 recover_standby_SID_050213.log
-rw-r--r-- 1 oracle oinstall 0 Feb 6 23:45 recover_standby_SID_060213.log
-rw-r--r-- 1 oracle oinstall 0 Feb 7 23:45 recover_standby_SID_070213.log
-rw-r--r-- 1 oracle oinstall 0 Feb 8 23:45 recover_standby_SID_080213.log
-rw-r--r-- 1 oracle oinstall 0 Feb 9 23:45 recover_standby_SID_090213.log
-rw-r--r-- 1 oracle oinstall 0 Feb 10 23:45 recover_standby_SID_100213.log
-rw-r--r-- 1 oracle oinstall 0 Feb 11 23:45 recover_standby_SID_110213.log
-rw-r--r-- 1 oracle oinstall 0 Feb 12 23:45 recover_standby_SID_120213.log
基本上,我想删除掉x天老,我认为logrotate的将是完美的旧文件...
我已经配置logrotate的有以下配置文件:
/data/tier2/scripts/logs/recover_standby_*.log {
daily
dateext
dateformat %d%m%Y
maxage 7
missingok
}
是否有什么我失踪得到想要的结果?
我想我可以删除的crontab的日志文件中的日期,然后有logrotate的旋转该文件,但此后在日志文件中的日期不会反映生成日志的一天......在010313即回收率将与文件的020313到期日logrotate的射击020313和旋转文件...
任何其他的想法? 与答谢提前任何响应。
问候
加文
Answer 1:
logrotate的按顺序轮换日志文件名的词汇排序列表,也可以通过文件年龄删除文件(使用文件的最后修改时间)
旋转是滚动的文件最大数量,你可能会发现。 如果有较多的滚动日志文件,他们的名字是词法排序,词法最小的被删除。
最大生存周期定义用于去除旋转的日志文件另一个标准。 任何旋转的日志文件,是年龄大于天的给定数目被删除。 请注意,日期是从最后修改时间的文件检测,而不是从文件名。
日期格式允许日期轮换文件特定的格式。 手册页的笔记,该格式将导致在词法上正确排序 。
dateyesterday允许使用日志文件名称日期1天回来。
为了保持在每天轮换文件的天数给予(如7),你必须设置rotate
至7的价值和你可能会忽略maxage
,如果创建您的文件,每天真的旋转。
如果日志创建不会发生了几天,股份公司14天的滚动日志文件的数量将仍然是相同的(7)。
maxage
将改善的情况“不生产日志”通过在拆除太旧文件的情况。 经过7天无日志生产会有目前还没有旋转的日志文件。
您不能使用dateformat
为OP表演,因为它不是词法排序。 与搞乱dateformat
可能会导致删除其他滚动日志文件比你真正想要的。
提示 :从命令行运行logrotate的-d
选项执行试运行:你会看到什么logrotate的会做,但实际上并没有做任何事情。 然后,使用进行手动运行-v
(详细),这样就可以确认是什么做的是你想要的。
解决方案:由cron创建清洁日志
这个概念是:
让cron来创建和更新日志文件,但做小的修改,以创建文件,以下使用缺省时logrotate的标准文件名dateext
/data/tier2/scripts/logs/recover_standby_SID.log-`date +\%Y\%m\%d`.log
使用日志轮播只去除太旧的日志文件
- 针对不存在的日志文件
/data/tier2/scripts/logs/recover_standby_SID.log
- 使用
missingok
让logrotate的清理发生 - 集
rotate
足够高,覆盖的日志文件数量,以保持(至少7,是否会有一个“旋转”日志文件中的一天,但你可以放心地将其设置非常高:9999) - 集
maxage
为7这将删除其中有最后修改时间超过7天以上的文件。 -
dateext
是只是用来保证,对于较旧的文件看起来像旋转的logrotate的搜索。
logrotate的配置文件将如下所示:
data/tier2/scripts/logs/recover_standby_SID.log {
daily
missingok
rotate 9999
maxage 7
dateext
}
解决方案:日志轮播,每天一次直接旋转
我不知道,源恢复待机文件是如何创建的,但我会承担,Oracle或你的一些脚本是定期或不断地追加到一个文件/data/tier2/scripts/logs/recover_standby_SID.log
这个概念是:
- 旋转每天一次通过文件
logrotate
- 直接用含日志文件恢复数据的工作
/data/tier2/scripts/logs/recover_standby_SID.log
-
daily
将造成每天一次旋转(在如何条款cron
理解daily
) -
rotate
必须被设置为7(或任何更高的数)。 -
maxage
设置为7(天) -
dateext
使用默认的日志轮播日期后缀 -
dateyesterday
用来使日期后缀的轮换文件是1天回来。 -
missingok
清理旧文件,即使没有新的内容,以旋转存在。
logrotate设置将如下所示:
data/tier2/scripts/logs/recover_standby_SID.log {
daily
missingok
rotate 7
maxage 7
dateext
dateyesterday
}
请注意,您可能需要玩了一下copytruncate
和其他类似的选项,这些选项都涉及到如何通过外部进程,以及如何反应旋转的行为产生的源日志文件。
Answer 2:
您可以使用find
命令来容易做任务! 它会删除所有7 Days
的旧文件。 把它放在crontab
和夜间运行的基础:
$ cd /data/tier2/scripts/logs/
$ /usr/bin/find . -mtime +7 -name "*.log" -print -delete
或者更好的办法
$ /usr/bin/find /data/tier2/scripts/logs/ -mtime +7 -name "*.log" -print -delete;
Answer 3:
(更新)的选项有:
- 作为萨蒂什回答,放弃logrotate的,把一个发现脚本在cron
- 你甚至可以使用日志轮播,把一个发现脚本在postrotate命令
起初,我以为,改变日期格式,以配合您的日志可能会奏效,但作为里德Nabinger指出的日期格式是不兼容logrotate的反正。 最近,我试图配置相同的事情,但对于Java的旋转,我想logrotate的删除日志。 我想下面的配置,但它一直试图删除所有日志
/opt/jboss/log/server.log.* {
missingok
rotate 0
daily
maxage 30
}
最后我只是执行什么萨蒂什南比亚建议 - 一个简单的找到在cron RM脚本。
Answer 4:
(无法评论,因为没有足够的声誉)
我有一个类似的问题。 从各方面来看logrotate的是无用的文件名上使用内置的日戳。
如果所有这些都不是平等的,我可能会跟去find
在cron作业。
对于我自己的原因,我想用日志轮播,并最终找到了一种方法: https://stackoverflow.com/a/23108631
它在本质上是一个logrotate的文件封装cron作业的方式。 也许不是最漂亮的,最有效的,但就像我说的,我有我的理由。
Answer 5:
按照@Jan Vlcinsky,可以让logrotate的添加日期-只需使用dateyesterday
得到正确的日期。
或者,如果你想在日期把你自己,你可以“瞄准”的名称,没有日期,然后用日期的名字将被清理。
不过,我发现是,如果我没有一个日志文件存在,logrotate的没有做的日期文件的清理工作。
但是,如果你准备有一个空的日志文件躺在身边的话,就可以进行工作。
例如,要清理的/ var /日志/ mylogfile。 为yyyymmdd .LOG后7天, touch /var/log/mylogfile.log
,然后配置logrotate的,如下所示:
/var/log/mylogfile.log
{
daily
rotate 7
maxage 7
dateext
dateformat .%Y%m%d
extension .log
ifempty
create
}
该条目,用mylogfile.log的存在相结合,触发logrotate的清理旧文件,好像他们已经被logrotate的创建。
daily
, rotate
加maxage
导致7天后被删除旧的日志文件(或7个旧的日志文件,以先到者为准)。
dateext
, dateformat
加上extension
的原因logrotate的,以配合我们filesnames。
而ifempty
加create
确保有仍然是一个空文件存在,或日志旋转将停止。
用于测试的另一个技巧,准备编辑/var/lib/logrotate.status重置“最后”旋转,日期或logrotate的你不会做任何事情。
Answer 6:
仅供参考我知道这是一个老问题,但为什么它不为你工作的原因是因为你的日期格式不词法排序。 从手册页:
dateformat format_string
Specify the extension for dateext using the notation similar to strftime(3) function. Only
%Y %m %d and %s specifiers are allowed. The default value is -%Y%m%d. Note that also the
character separating log name from the extension is part of the dateformat string. The sys-
tem clock must be set past Sep 9th 2001 for %s to work correctly. Note that the datestamps
generated by this format must be lexically sortable (i.e., first the year, then the month
then the day. e.g., 2001/12/01 is ok, but 01/12/2001 is not, since 01/11/2002 would sort
lower while it is later). This is because when using the rotate option, logrotate sorts all
rotated filenames to find out which logfiles are older and should be removed.
该解决方案是要么改变一个去年 - 月 - 日,或调用外部程序进行清理。
文章来源: Logrotate to clean up date stamped files