Shrink my FogBugz database by removing old email attachments? - FogBugz Knowledge Exchange most recent 30 from http://fogbugz.stackexchange.com 2012-02-09T13:10:45Z http://fogbugz.stackexchange.com/feeds/question/1038 http://www.creativecommons.org/licenses/by-nc/2.5/rdf http://fogbugz.stackexchange.com/questions/1038/shrink-my-fogbugz-database-by-removing-old-email-attachments Shrink my FogBugz database by removing old email attachments? FogBugz FAQ 2009-12-15T16:54:58Z 2011-09-12T16:23:52Z <p>I have a bunch of old customer emails and attachments that I want to get rid of. How can I get rid of large email attachments that are older than 6 months old?</p> http://fogbugz.stackexchange.com/questions/1038/shrink-my-fogbugz-database-by-removing-old-email-attachments/1043#1043 Answer by db for Shrink my FogBugz database by removing old email attachments? db 2009-12-15T20:57:04Z 2011-09-12T16:23:52Z <p>First, make sure to back up your database prior to running the following script. :)</p> <p>The following query should delete any email attachments that are more than 6 months old.</p> <pre><code>DELETE FROM Attachment WHERE ixAttachment IN (SELECT Attachment.ixAttachment FROM Attachment INNER JOIN BugEvent ON Attachment.ixBugEvent = BugEvent.ixBugEvent WHERE DATEDIFF(mm, dt, GetDate()) &gt; 6 AND fEmail = 1 ) </code></pre> <p>Or for MySQL</p> <pre><code>DELETE FROM Attachment WHERE ixAttachment IN (SELECT Attachment.ixAttachment FROM Attachment INNER JOIN BugEvent ON Attachment.ixBugEvent = BugEvent.ixBugEvent WHERE dt &lt; DATE_SUB(NOW(), INTERVAL 6 MONTH) &gt; 6 AND fEmail = 1 ) </code></pre> <p>If at some point you need to retrieve the deleted attachments for a specific bug, you should be able to do so by running the following query and then re-visiting that case (replace CASE_ID with the id of the bug whose attachments you're trying to recover):</p> <pre><code>UPDATE BugEvent SET fHTML = 0 WHERE ixBug = CASE_ID </code></pre> <p>If you really want to completely delete the attachment, you will need to clear out the email event as well. Only do this if you don't need the attachment or the body of the email it's in: <a href="http://fogbugz.stackexchange.com/questions/1728/moving-to-ms-sql-server-express-need-to-reduce-database-size-by-deleting-email-a/1752#1752" rel="nofollow">http://fogbugz.stackexchange.com/questions/1728/moving-to-ms-sql-server-express-need-to-reduce-database-size-by-deleting-email-a/1752#1752</a></p> <p><strong>See also</strong> <a href="http://fogbugz.stackexchange.com/questions/5901/purge-old-attachments-from-fogbugz-database" rel="nofollow">Deleting old non-email attachments</a>, and <a href="http://fogbugz.stackexchange.com/questions/16/how-do-i-delete-cases" rel="nofollow">deleting cases</a>.</p> http://fogbugz.stackexchange.com/questions/1038/shrink-my-fogbugz-database-by-removing-old-email-attachments/5586#5586 Answer by Karsten for Shrink my FogBugz database by removing old email attachments? Karsten 2010-10-27T09:42:56Z 2010-10-27T09:42:56Z <p>Hi! I'm a little bit confused. I'm using FogBugz Version 6.1.44 (DB 632, Build 369) with a MSSQL 2005 Express. Will the script work with this setup and delete old Mail-Attachments? I only wan't to delete, recovering is not so important.</p>