简体   繁体   English

logrotate-备份任何文件

[英]logrotate - backup any file

I have one file. 我只有一个文件。 It's not a log file. 这不是日志文件。 Every day I need to copy it somewhere else adding timestamp to its name. 每天我都需要将其复制到其他位置,以在其名称中添加时间戳。 I need to keep last ten (10) days copies. 我需要保留最近十(10)天的副本。 I am considering using logrotate service (server is running CentOS). 我正在考虑使用logrotate服务(服务器正在运行CentOS)。

My question is if there is some limit on logrotate to rotate only log files or if I can use any other file and location. 我的问题是,是否只对logrotate旋转日志文件有一定限制,或者我可以使用其他文件和位置。 That is may I specify some other location where to put copies with timestamps and to hold only last 10 (days) copies? 那是我可以指定其他位置放置带时间戳的副本并仅保留最近10天的副本吗?

Thanks in advance for your hints. 预先感谢您的提示。

You can rotate any file in any location eg take a look at /etc/logrotate.d/samba (if installed) which rotates log.smbd . 您可以在任何位置旋转任何文件,例如,查看/etc/logrotate.d/samba (如果已安装),该文件将旋转log.smbd Just create a new file in /etc/logrotate.d/ and configure for your file to be rotated. 只需在/etc/logrotate.d/创建一个新文件,并配置要旋转的文件即可。 A nice description is here for centOS not different ( here ). 对于centOS来说, 这里有一个不错的描述( 此处 )。

The problem is the timestamp in the name. 问题是名称中的时间戳。 If you want this it is no longer rotating . 如果需要,它将不再旋转 With logrotate the latest archived file is always number 1 and thus all older once are getting renamed. 使用logrotate ,最新的存档文件始终为1,因此,所有较旧的文件都将被重命名。 But they keep their time of last modification stored in the file system untouched. 但是他们保持其上次修改时间存储在文件系统中。 But this time is not in the name. 但这一次没有名字。

As an alternative you can just create a new cron job by adding a file in one of the \\etc\\cron.*\\ directories. 或者,您可以通过在\\etc\\cron.*\\目录之一中添加文件来创建新的cron作业。 This cron job can move you file adding a timestamp eg by using date +%y%m%d_%H:%M and create a new file using touch . 这项cron作业可以通过添加时间戳(例如,使用date +%y%m%d_%H:%M文件,并使用touch创建一个新文件。 No need for logrotate . 无需logrotate

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

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