Created
April 5, 2013 05:57
-
-
Save RWJMurphy/5316975 to your computer and use it in GitHub Desktop.
Purges attachments from a trac instance, after a ticket has been closed for more than a given number of days.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash -e | |
| days_before_purge=30 | |
| tracdb="/var/www/trac/db/trac.db" | |
| attachment_dir="/var/www/trac/attachments/ticket" | |
| sqlite3="/usr/bin/sqlite3" | |
| sql_closed="select distinct id from ticket join attachment using (id) where status = \"closed\" and datetime(changetime/1000000, 'unixepoch') <= datetime('now', '-${days_before_purge} days');" | |
| closed_tickets=$(echo ${sql_closed} | ${sqlite3} ${tracdb}) | |
| for id in $closed_tickets; do | |
| delete_sql="delete from attachment where id=\"${id}\";" | |
| ticket_directory="${attachment_dir}/${id}" | |
| if [ "$(ls -A ${ticket_directory})" ]; then | |
| echo "Deleting attachment files for ticket #${id}" | |
| rm -f ${ticket_directory}/* | |
| fi | |
| echo "Deleting attachments from db for ticket #${id}" | |
| echo ${delete_sql} | ${sqlite3} ${tracdb} | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment