Add a script to remove old entries from the database, default keeps 2 years of logs

tags/0.1.4
Daniel Berteaud 12 years ago
parent 70be65c741
commit 260359acbb
  1. 15
      root/etc/cron.daily/qpsmtpd-db-cleanup

@ -0,0 +1,15 @@
#!/bin/bash
LOG=$(/sbin/e-smith/db configuration getprop qpsmtpd Log2Sql || echo 'disabled')
if [ "$LOG" != "enabled" ]; then
exit 0
fi
RETENTION=$(/sbin/e-smith/db configuration getprop qpsmtpd Log2SqlRetention || echo 730)
DB=$(/sbin/e-smith/db configuration getprop qpsmtpd DbName || echo smtp_log)
echo "delete from rcpts where mail_id IN (select mail_id from messages where date_day<DATE_SUB(NOW(), INTERVAL $RETENTION DAY));" | mysql $DB
echo "delete from message_body where mail_id IN (select mail_id from messages where date_day<DATE_SUB(NOW(), INTERVAL $RETENTION DAY));" | mysql $DB
echo "delete from messages where date_day<DATE_SUB(NOW(), INTERVAL $RETENTION DAY);" | mysql $DB
Loading…
Cancel
Save