[Cialug] mysql 'purge'
David Champion
dave at dchamp.net
Tue Aug 16 16:56:32 CDT 2011
On 8/16/2011 2:09 PM, L. V. Lammert wrote:
> Question - is anyone aware of a simple way to purge records from a mysql
> [by aging a timestamp] in a cron job? Writing a program is too
> complicated, ..
>
>> I could write SQL code to delete records over, say, seven days, ..
>> The more complicated part is that each of those records includes a
> filename that also must be deleted. My first thought would be to do a
> select and dump to a temporary file, then run xargs [?] on that file to
> delete the system files, but wanted to check if I missed something.
>
> Lee
> _______________________________________________
>
This is something that would be best to handle in the application logic
of your program. Ideally you'd have a flag or timestamp on the records
that need to be deleted. You also need to account for any child records
that need to be deleted, which could be painful with your dump / xargs
method.
You can have a cron job that calls a script in your favorite scripting
language that fires off the sql cleanup. I've written php cli scripts
that would do that sort of thing. Some people like to put wget calls in
cron jobs to call web pages.
-dc
More information about the Cialug
mailing list