ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I have several one .gz file being backed up daily but I would like to first check that all the files are there from over the week which would be 7 if there are 7 there I would then like it to sort them by the time stamp on the file then remove the first one created at the start of the week. and tell my backup line of script
I would like to keep 7 then just before the 8th backup which would be on a Monday I would like it to make sure there are 7 files backed up then delete the first backup created and then write the new backup.
I need to make sure all 7 files are there before I do anything though. I could not see in your line of text a command to delete the first file created from what I understand it deletes all 7. I do have time stamps in the file name of each file created. Thanks for your help.
Basically, find is looking in /destination/ for files (f) called anything (-name '*') modified at least 7 days ago (-mtime +7) then executing the rm -f command on those file found. Does that make sense?
Maybe this would be better?
rm -f `ls -t | sed -e 1,7d`
basically, this lists the files in order of time, ignores entries 1-7 then passes them to rm -f (ie deletes them)
Edit - note that the quote mark I have used is a "`" not a "'" (look under the tilde "~" on US style keyboards)
Last edited by billymayday; 05-25-2007 at 04:30 AM.
Ok that makes much more sense but how can I only delete the first file created and leave the other 6. Then the next day tuesday will be deleted as a new backup will need to be created. So it once Monday comes Mondays backup willbe deleted on Monday and a new backup for Monday will then be created.
The first code deletes file over 7 days old, the second leaves the youngest 7 files and deletes the oldest (if you had 8 files, the first of those 8 created would be deleted). Is that what you want, or do you want to say today in Monday, delete last Monday's backup if it doesn't fit into either of the above?
Try this http://www.topology.org/linux/logrotate.html , a bit old, but written to explain.
Also man logrotate.
As you can see, you can use cmds embedded, or set logrotate to a time that suits you and run your backup separately in cron.