Updated pilerpurge to remove data from manticore in case of RT index

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2023-11-01 08:25:56 +01:00
parent 91b3c73b02
commit e2f6a71827

View File

@ -9,7 +9,7 @@ import sys
import syslog import syslog
import time import time
SQL_PURGE_SELECT_QUERY = "SELECT piler_id, size FROM " +\ SQL_PURGE_SELECT_QUERY = "SELECT id, piler_id, size FROM " +\
"metadata WHERE deleted=0 AND retained < UNIX_TIMESTAMP(NOW()) " +\ "metadata WHERE deleted=0 AND retained < UNIX_TIMESTAMP(NOW()) " +\
"AND id NOT IN (SELECT id FROM rcpt WHERE `to` IN " +\ "AND id NOT IN (SELECT id FROM rcpt WHERE `to` IN " +\
"(SELECT email FROM legal_hold)) AND id NOT IN (SELECT " +\ "(SELECT email FROM legal_hold)) AND id NOT IN (SELECT " +\
@ -33,7 +33,9 @@ def read_options(filename="", opts={}):
opts['password'] = config.get('piler', 'mysqlpwd') opts['password'] = config.get('piler', 'mysqlpwd')
opts['database'] = config.get('piler', 'mysqldb') opts['database'] = config.get('piler', 'mysqldb')
opts['storedir'] = config.get('piler', 'queuedir') opts['storedir'] = config.get('piler', 'queuedir')
opts['rtindex'] = config.getint('piler', 'rtindex', fallback=0)
opts['sphxhost'] = config.get('piler', 'sphxhost', fallback='127.0.0.1')
opts['sphxport'] = config.getint('piler', 'sphxport', fallback=9306)
opts['server_id'] = "%02x" % config.getint('piler', 'server_id') opts['server_id'] = "%02x" % config.getint('piler', 'server_id')
@ -184,6 +186,17 @@ def get_attachment_file_path(piler_id='', attachment_id=0, opts={}):
str(attachment_id)]) str(attachment_id)])
def purge_index_data(ids=[], opts={}):
'''
Delete from index data in case of RT index
'''
if opts['rtindex'] == 1 and opts['dry_run'] is False:
cursor = opts['sphx'].cursor()
a = "," . join([str(x) for x in ids])
cursor.execute("DELETE FROM piler WHERE id IN (%s)" % (a))
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-c", "--config", type=str, help="piler.conf path", parser.add_argument("-c", "--config", type=str, help="piler.conf path",
@ -203,6 +216,7 @@ def main():
opts['dry_run'] = args.dry_run opts['dry_run'] = args.dry_run
opts['verbose'] = args.verbose opts['verbose'] = args.verbose
opts['db'] = None opts['db'] = None
opts['sphx'] = None
opts['messages'] = 0 opts['messages'] = 0
opts['files'] = 0 opts['files'] = 0
opts['size'] = 0 opts['size'] = 0
@ -217,6 +231,8 @@ def main():
opts['db'] = dbapi.connect(opts['dbhost'], opts['username'], opts['db'] = dbapi.connect(opts['dbhost'], opts['username'],
opts['password'], opts['database']) opts['password'], opts['database'])
opts['sphx'] = dbapi.connect(host=opts['sphxhost'], port=opts['sphxport'])
if is_purge_enabled(opts) is False: if is_purge_enabled(opts) is False:
syslog.syslog("Purging emails is disabled") syslog.syslog("Purging emails is disabled")
sys.exit(1) sys.exit(1)
@ -229,13 +245,15 @@ def main():
if rows == (): if rows == ():
break break
piler_id = [x[0] for x in rows] id = [x[0] for x in rows]
size = [x[1] for x in rows] piler_id = [x[1] for x in rows]
size = [x[2] for x in rows]
opts['purged_size'] = opts['purged_size'] + sum(size) opts['purged_size'] = opts['purged_size'] + sum(size)
purge_m_files(piler_id, opts) purge_m_files(piler_id, opts)
purge_attachments_by_piler_id(piler_id, opts) purge_attachments_by_piler_id(piler_id, opts)
purge_index_data(id, opts)
# It's possible that there's attachment duplication, thus # It's possible that there's attachment duplication, thus
# refcount > 0, even though after deleting the duplicates # refcount > 0, even though after deleting the duplicates