Hello everyone,
I would like to ask about any suggestions regarding the handling of attachments stored in the file system itself.
My core issue is that I want to keep tickets but remove attachments after X period of time in order to optimize storage.
Currently I am running a shell script that sends a query which maps all attachments that belong to department X older than the given time period, and then I rm them. The script itself is simple but I feel like getting the actual data is a bit convoluted.
Query snippet
SELECT
f.id AS file_id,
f.key AS file_key,
f.name AS original_name,
f.type AS mime_type,
f.size,
f.created AS file_created,
'H' AS attachment_type,
t.ticket_id,
t.number AS ticket_number,
t.closed AS ticket_closed
FROM ost_file f
JOIN ost_attachment a ON a.file_id = f.id
JOIN ost_thread_entry e ON e.id = a.object_id
JOIN ost_thread th ON th.id = e.thread_id
JOIN ost_ticket t ON t.ticket_id = th.object_id
WHERE
a.type = 'H'
AND th.object_type = 'T'
AND f.bk = 'F'
AND t.dept_id = 14
AND f.created < NOW() - INTERVAL 6 MONTH
Is there a better way to approach this ?
TYIA for any suggestions.