Baruwa Experts,
I need your help in reducing mysql database size in ‘messages’ table. I
found one script ( dbclean.py) which is supposed to do the job but somehow
it is throwing following errors
File "dbclean.py", line 22, in ?
from django.db import connection
File "/usr/lib/python2.4/site-packages/django/db/__init__.py", line 14,
in ?
if not settings.DATABASES:
File "/usr/lib/python2.4/site-packages/django/utils/functional.py", line
276, in __getattr__
self._setup()
File "/usr/lib/python2.4/site-packages/django/conf/__init__.py", line 40,
in _setup
raise ImportError("Settings cannot be imported, because environment
variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable
DJANGO_SETTINGS_MODULE is undefined.
*& script look like this from
/usr/lib/python2.4/site-packages/baruwa/messages/management/commands*
from django.conf import settings
from django.db import connection
from django.core.management.base import NoArgsCommand
from django.utils.translation import ugettext as _
class Command(NoArgsCommand):
"Archive messages and delete from messages table"
help = _("Deletes records older than QUARANTINE_DAYS_TO_KEEP"
" days from the messages table")
def handle_noargs(self, **options):
#import datetime
#from baruwa.messages.models import Message
#interval = datetime.timedelta(days=60)
#last_date = datetime.datetime.now() - interval
#Message.objects.filter(timestamp__lt=last_date).delete()
days = getattr(settings, 'QUARANTINE_DAYS_TO_KEEP', 10)
conn = connection.cursor()
conn.execute(
"""DELETE FROM messages WHERE id in
(SELECT id FROM archive WHERE timestamp <
DATE_SUB(CURDATE(), INTERVAL %s DAY))
""" % str(days)
)
conn.execute(
"""INSERT LOW_PRIORITY INTO archive
SELECT * FROM messages WHERE timestamp <
DATE_SUB(CURDATE(), INTERVAL %s DAY)
""" % str(days)
)
conn.execute(
"""DELETE LOW_PRIORITY FROM messages
WHERE timestamp < DATE_SUB(CURDATE(),
INTERVAL %s DAY)
""" % str(days)
)
conn.execute('OPTIMIZE TABLE messages')
conn.execute('OPTIMIZE TABLE archive')
I changed only from ‘60’ to ‘10’ so that old entries can be removed from
database
Baruwa Version - 1.1.1
Mailscanner Version - 4.84.3
CentOS - 5.7 32 bit
Thanks in advance,
Pinemail.
_______________________________________________
Keep Baruwa FREE - http://pledgie.com/campaigns/12056