Delete attachments older than 5 years

Hello,

i want to delete all attachments older than 5 years. I know there is a plugin for attachments in rt-shredder, but how can i limit it to the attachments that are 5y or older ?

thanks in advance

David

I am doing this only with tickets but you can try it with attachments also :slight_smile: My query is:

 /opt/rt4/sbin/rt-shredder --force --plugin "Tickets=query,(Status = 'deleted') AND (Updated < '-5 years');limit,50000"

Adapt it for your purpose. But be sure you have the indexes present or you will wait endlessly.

I think the problem is that query is not an option for the Attachments plugin, so you can’t inject a bit of SQL to filter the attachments. As far as I can see that’s not possible, as the only filtering options for the Attachments plugin is by file name, file size and if the attachment is a file or not (some attachments might be mail message parts rather than files).

After sending the above reply I thought, “why shouldn’t attachments be searchable by a query?”. So I made a copy of /opt/rt4/lib/RT/Shredder/Plugin/Attachments.pm into our local directory structure (aka /opt/rt4/local/lib/RT/Shredder/Plugin/Attachments.pm) and hacked in support for a query option like Tickets has. Here’s the context diff patch:

# diff -c /opt/rt4/local/lib/RT/Shredder/Plugin/Attachments.pm /opt/rt4/lib/RT/Shredder/Plugin/Attachments.pm 
*** /opt/rt4/local/lib/RT/Shredder/Plugin/Attachments.pm	2020-02-18 10:32:25.474936424 +0000
--- /opt/rt4/lib/RT/Shredder/Plugin/Attachments.pm	2019-03-18 10:38:50.491299711 +0000
***************
*** 76,82 ****
  
  =cut
  
! sub SupportArgs { return $_[0]->SUPER::SupportArgs, qw(files_only file longer query) }
  
  sub TestArgs
  {
--- 76,82 ----
  
  =cut
  
! sub SupportArgs { return $_[0]->SUPER::SupportArgs, qw(files_only file longer) }
  
  sub TestArgs
  {
***************
*** 118,127 ****
          push @conditions, "( LENGTH(Content) > ? )";
          push @values, $size;
      }
-     if( $self->{'opt'}{'query'} ) {
- 	my $query = $self->{'opt'}{'query'};
-         push @conditions, "( $query )";
-     }
      return (0, "At least one condition should be provided" ) unless @conditions;
      my $query = "SELECT id FROM Attachments WHERE ". join ' AND ', @conditions;
      if( $self->{'opt'}{'limit'} ) {
--- 118,123 ----

So now I can do something like:

/opt/rt4/sbin/rt-shredder --plugin "Attachments=query,Created < '2015-02-18';limit,10"

1 Like