mirror of
				https://bitbucket.org/jsuto/piler.git
				synced 2025-10-31 09:52:26 +01:00 
			
		
		
		
	util: pilerpurge.py fixes
Change-Id: Ic2d533b06bee4dfe95b51e7d64c7a2766c0cd6c9 Signed-off-by: SJ <sj@acts.hu>
This commit is contained in:
		| @@ -10,16 +10,6 @@ import sys | |||||||
| import syslog | import syslog | ||||||
| import time | import time | ||||||
|  |  | ||||||
| # Purging of emails works as follows: |  | ||||||
| # |  | ||||||
| # 1. Find from metadata table which piler IDs we should remove |  | ||||||
| # |  | ||||||
| # 2. Remove the .m files, and set deleted=1 for for those piler IDs |  | ||||||
| #    in metadata table |  | ||||||
| # |  | ||||||
| # 3. Find non-referenced attachments, and remove them from filesystem |  | ||||||
| #    then remove them from attachment table |  | ||||||
|  |  | ||||||
| SQL_PURGE_SELECT_QUERY = "SELECT piler_id, size FROM " +\ | SQL_PURGE_SELECT_QUERY = "SELECT 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 " +\ | ||||||
| @@ -49,7 +39,7 @@ def purge_m_files(ids=[], opts={}): | |||||||
|         remove_m_files(ids, opts) |         remove_m_files(ids, opts) | ||||||
|  |  | ||||||
|         if opts['dry_run'] is False: |         if opts['dry_run'] is False: | ||||||
|             # Set deleted=1 for remove metadata entries |             # Set deleted=1 for aged metadata entries | ||||||
|  |  | ||||||
|             cursor = opts['db'].cursor() |             cursor = opts['db'].cursor() | ||||||
|             format = ", ".join(['%s'] * len(ids)) |             format = ", ".join(['%s'] * len(ids)) | ||||||
| @@ -85,8 +75,8 @@ def purge_attachments(ids=[], opts={}): | |||||||
|  |  | ||||||
|         # Delete these IDs from attachment table |         # Delete these IDs from attachment table | ||||||
|         if opts['dry_run'] is False: |         if opts['dry_run'] is False: | ||||||
|             format = ", ".join(['%d'] * len(remove_ids)) |             format = ", ".join(['%s'] * len(remove_ids)) | ||||||
|             cursor.execute("DELETE FROM attachment WHERE piler_id IN (%s)" % |             cursor.execute("DELETE FROM attachment WHERE id IN (%s)" % | ||||||
|                            (format), remove_ids) |                            (format), remove_ids) | ||||||
|             opts['db'].commit() |             opts['db'].commit() | ||||||
|         else: |         else: | ||||||
| @@ -169,6 +159,14 @@ def main(): | |||||||
|  |  | ||||||
|             purge_attachments(piler_id, opts) |             purge_attachments(piler_id, opts) | ||||||
|  |  | ||||||
|  |         # Update the counter table | ||||||
|  |         if opts['dry_run'] is False: | ||||||
|  |             cursor.execute("UPDATE counter SET rcvd=rcvd-%s, size=size-%s, " + | ||||||
|  |                            "stored_size=stored_size-%s", | ||||||
|  |                            (str(opts['count']), str(opts['purged_size']), | ||||||
|  |                             str(opts['purged_stored_size']))) | ||||||
|  |             opts['db'].commit() | ||||||
|  |  | ||||||
|     except dbapi.DatabaseError, e: |     except dbapi.DatabaseError, e: | ||||||
|         print "Error %s" % e |         print "Error %s" % e | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user