[rt-users] Delete large attachment

Stephen Turner sturner at MIT.EDU
Thu Jun 14 13:08:09 EDT 2007

At Thursday 6/14/2007 07:42 AM, Tim Hill wrote:
>I have a member of staff who has decided to attach docuements to his 
>tickets in bitmap format, unfortunately these bitmap images are 
>between 4 and 8 MB in size and they have taken up more space in a 
>day of doing this than the rest of the RT system has taken up in 
>almost a year of operation.
>I don't mind if the tickets have to be deleted, they can be 
>recreated easily enough. How can I get rid of these attachments from 
>the RT database? Where are the attachments stored and what are my 
>options for getting rid of them?
>I am using the following:
>RT version 3.4.4 from an ubuntu package.
>Server version of dapper drake 6.06 LTS (webmin shows this as 6.06.1)
>Webmin version 1.320
>PostgreSQL version 7.4.12 (With schemas)
>Please let me know if you require any other information.
>Thanks in advance,


As always I'd recommend using a Perl script rather than monkey with 
the database - you can delete a transaction through the RT API:

Here's the script I use. It needs RT_HOME set as an environment 
variable, and RT_HOME/lib directory should be on Perl's search path.

# Deletes a transaction from the database.
use lib $ENV{RT_HOME}."/etc";

use RT::Interface::CLI qw (CleanEnv GetCurrentUser);
use RT::User;
use RT::Ticket;

die "Usage: $0 ticket_number transaction_number" if scalar (@ARGV) != 2;
my $tktno = shift @ARGV;
my $transno = shift @ARGV;


my $CurrentUser = GetCurrentUser();

my $Ticket = new RT::Ticket($CurrentUser);

die "Unknown ticket $tktno" if ! $Ticket->id;

my $Transaction = new RT::Transaction($CurrentUser);

die "No such transaction $transno" if ! $Transaction->id;

die "Wrong ticket number" unless $Transaction->ObjectType eq 
'RT::Ticket' && $Transaction->ObjectId == $tktno;

print "Transaction Found:\n";
print "  ID: ".$Transaction->Id."\n";
print "  Type: ".$Transaction->Type."\n";
print "  Created: ".$Transaction->Created."\n";

print "Do you really want to delete the transaction? [N] ";
$| = 1;
$_ = <STDIN>;


if ($_ && uc($_) eq 'Y') {
     print "Transaction Deleted\n";
} else {
     print "OK - Not Deleting\n";

More information about the rt-users mailing list