using cron to backup logs in unusual circumstances
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
using cron to backup logs in unusual circumstances
I don't know much about linux to be honest, I am just learning because I have a server running on one. What i am doing is looking for a way to automatically backup the log files, compress them, and put them somewhere else. Here is the thing, the server creates a new log file every time it is restarted with the date and time of the restart in the file name. So if it is not restarted for days, the log file will indicate a day several days ago, because that is when it was originally created. Next problem, if that log file disappears, the server doesn't create another one, it just stops logging.
So, basically I need to find a way to make a command for Cron to "Backup and delete all but the most recent log file." And I have no idea where to begin.
Just to clarify in case I am not totally clear. We will say today's date is well, today. 4-28. I have the following log files:
4-18.log
4-22.log
4-23.log
4-27.log
I need to backup and delete 4-18, 4-22, and 4-23. But I need to leave 4-27 alone.
Now, keep in mind that the most recent log file is not necessarily for yesterday. In the above example 4-23.log contains information from the 23rd, 24th, 25th, 26th and part of the 27th. The only reason 4-27 was created was because the server was restarted on the 27th, and thus because today is the 28th 4-27 will contain log information frm the rest of the 27th and the 28th.
I was thinking (if it is even possible) to create a cron entry that will do this for files that had there last access date yesterday. But again, I have NO idea how to do any of this.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.