mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-07 19:31:59 +01:00
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:
parent
91b3c73b02
commit
e2f6a71827
@ -9,7 +9,7 @@ import sys
|
||||
import syslog
|
||||
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()) " +\
|
||||
"AND id NOT IN (SELECT id FROM rcpt WHERE `to` IN " +\
|
||||
"(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['database'] = config.get('piler', 'mysqldb')
|
||||
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')
|
||||
|
||||
|
||||
@ -184,6 +186,17 @@ def get_attachment_file_path(piler_id='', attachment_id=0, opts={}):
|
||||
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():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-c", "--config", type=str, help="piler.conf path",
|
||||
@ -203,6 +216,7 @@ def main():
|
||||
opts['dry_run'] = args.dry_run
|
||||
opts['verbose'] = args.verbose
|
||||
opts['db'] = None
|
||||
opts['sphx'] = None
|
||||
opts['messages'] = 0
|
||||
opts['files'] = 0
|
||||
opts['size'] = 0
|
||||
@ -217,6 +231,8 @@ def main():
|
||||
opts['db'] = dbapi.connect(opts['dbhost'], opts['username'],
|
||||
opts['password'], opts['database'])
|
||||
|
||||
opts['sphx'] = dbapi.connect(host=opts['sphxhost'], port=opts['sphxport'])
|
||||
|
||||
if is_purge_enabled(opts) is False:
|
||||
syslog.syslog("Purging emails is disabled")
|
||||
sys.exit(1)
|
||||
@ -229,13 +245,15 @@ def main():
|
||||
if rows == ():
|
||||
break
|
||||
|
||||
piler_id = [x[0] for x in rows]
|
||||
size = [x[1] for x in rows]
|
||||
id = [x[0] 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)
|
||||
|
||||
purge_m_files(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
|
||||
# refcount > 0, even though after deleting the duplicates
|
||||
|
Loading…
Reference in New Issue
Block a user