[TriLUG] Some script help

Aaron Morrison via TriLUG trilug at trilug.org
Fri May 8 11:27:29 EDT 2015


That should be -mtime, not -time. DYAC. 

--am


> On May 8, 2015, at 11:23, Aaron Morrison via TriLUG <trilug at trilug.org> wrote:
> 
> Bash is fine for this, but the key is to not try to compare dates. Bash doesn't do that well at all. 
> 
> My suggestion is to let "find" do the purge work for you and then copy/sync what's left. 
> 
> find /dir/path -type f -name 'backup*' -time +7 -delete
> 
> That will delete all files in /dir/path starting with "backup" that is older than 7 days. 
> 
> Simple is better (and easier to maintain). 
> 
> --am
> 
> 
>> On May 8, 2015, at 11:07, Igor Partola via TriLUG <trilug at trilug.org> wrote:
>> 
>> +1 for not doing this in bash. While it's of course possible, Python would
>> be my choice. There you can compare dates as dates, not as sorted strings.
>> 
>> Another approach: use logrotate to do this. I have seen this used
>> successfully to take backups from MySQL and keeping X number of days' worth
>> of backups.
>> 
>> Third approach: forget copying "today's file" and copy the latest file. Use
>> `ls backup_*.tgz | sort | tail -n 1` to get the latest file.
>> 
>> Fourth approach: use rsync and copy everything. Combine with third approach
>> to first delete the local backups that are older than 7 days.
>> 
>> Igor
>> -- 
>> This message was sent to: Aaron Morrison <ae4ko1 at gmail.com>
>> To unsubscribe, send a blank message to trilug-leave at trilug.org from that address.
>> TriLUG mailing list : http://www.trilug.org/mailman/listinfo/trilug
>> Unsubscribe or edit options on the web    : http://www.trilug.org/mailman/options/trilug/ae4ko1%40gmail.com
>> Welcome to TriLUG: http://trilug.org/welcome
> -- 
> This message was sent to: Aaron Morrison <ae4ko1 at gmail.com>
> To unsubscribe, send a blank message to trilug-leave at trilug.org from that address.
> TriLUG mailing list : http://www.trilug.org/mailman/listinfo/trilug
> Unsubscribe or edit options on the web    : http://www.trilug.org/mailman/options/trilug/ae4ko1%40gmail.com
> Welcome to TriLUG: http://trilug.org/welcome


More information about the TriLUG mailing list