Is it possible to purge attachment history?

We have a situation where our attachment growth is expanding quite rapidly as users are utilising Confluence as a collaboration tool around office documents. Due to this the prior versions quickly build up which turns a file of a few MiB in size to a few hundred MiB.

I'm wondering if there is a third-party plugin or some way you could let me know to periodically purge history? We would ultimately like to be able to purge history within a designated period of time.

Looking at our attachments table shows there is a moderate 3,561 attachment documents, of this there are a total 4,953 when counting prior versions.

I could quite simply use a mechanism in SQL to print and purge content with a query such as:

select attachmentid,
       title,
       pageid,
       creator,
       lastmoddate
  from attachments
 where prevver is not null
   and datediff(curdate(), lastmoddate) > 30;

And then delete the subsequent attachment file, however I would gather there are two problems to this:

  1. Confluence would need to be off-line
  2. Lucene cache would need to be rebuilt (maybe?).

I'd really prefer not using this method unless it's proven to be safe.

If there are no other ways, no plugins etc, I'd be happy to investigate writing such a plugin provided the api's are available from within confluence to delete prior versions. If they are, could you kindly point me in the right direction to get me started on this? My plugin authoring experience has currently been only for themes and macros.

4 answers

1 accepted

This widget could not be displayed.

I have decided to solve this by creating a plugin with a schedule to purge attachments as needed.

Available on github.com you can find the Attachment Tools Plugin. I should be releasing a version later this week.

Hi Brett, Does you plugin still works with Confluence 5.4? Last change was made more than two years ago so I think it makes sense to ask :)

Hi Sorin the plugin should work fine on 5.x and I have tested on an earlier 5.x version previously but have not updated the plugin.

Internally our company has had many issues with many plugins moving to 5.x and are still on 4.x ourselvs. Atlassian really created a nightmare with 5.x that we still aren't happy about.

I hope to start looking at this soon actually and we should have something verified for 5.x releases within a month.

Hi Sorin the plugin should work fine on 5.x and I have tested on an earlier 5.x version previously but have not updated the plugin.

Internally our company has had many issues with many plugins moving to 5.x and are still on 4.x ourselvs. Atlassian really created a nightmare with 5.x that we still aren't happy about.

I hope to start looking at this soon actually and we should have something verified for 5.x releases within a month.

This widget could not be displayed.

I don't know of a better way, but Confluence would not have to be off line to run your purging query. The cache would need to be rebuilt, though.

This widget could not be displayed.

Thanks Matthew, have decided to write a plugin for it. Just need to figure out how to email results and it will be pretty much complete. If you know how to send email from confluence it would be a big help :)

This widget could not be displayed.

I've just finished the plugin, was working fine in report mode, so decided to turn on the deletions.

Little did I know that calls to AttachmentManager.removeAttachmentFromServer(Attachment) remove ALL VERSIONS.

This is a huge setback for me as I now spent three days writing a plugin only to find that the one method I need doesn't behave as I first thought.

Looking at com.atlassian.confluence.pages.persistence.dao.hibernate.NonTransactionalHibernateAttachmentDao reveals the following:

if (!attachment.isLatestVersion())
{
    attachment = (Attachment) attachment.getLatestVersion();
}

Sad face. Really sad face :(

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Jul 30, 2018 in Confluence

How Manon Soubies-Camy uses Confluence + Trello to organize webinar notes and her knitting stash

@Manon Soubies-Camy is an engineer who has been an avid Atlassian user since 2014. She helps companies of all sizes transform the way they work with the Atlassian stack, including Jira and Confl...

847 views 8 13
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you