Solution for automated trash purging?
Asked by Daniel Hertrich:

Hi there,

is there some Confluence plugin or another solution (or way) to purge pages from the confluence trash bin after a specific amount of time (trash date + x days)?

Are there \*any\* ways to automate permanent deletion dependent on criteria such as "trashed" date, "created" date etc.?

Thank you!


Answers:
author: Daniel Hertrich
body: I looked into a possible solution using the Archiving Plugin, but that doesn't seem to be an option. Problem: We needed a two-step workflow:

Step 1: User archives a page manually by assigning the "archive" tag OR a page is archived autoimatically by specific filter crieteria (OK, will work).

Step 2: The Archiving Plugin scans its own archive space to permanently delete all pages that are older than 90 days. (that one won't work)

However, Step 2 doesn't seem to be possible, as the Archiving Plugin is not able to use its own Archive spaces as input. Even after making such spaces visible by changing their status from "Archived" to "Current", the Archiving Plugin is not able to assign workflow rules to its own Archive spaces.   
Or did I miss something?

comments: author: Aron Gombas _Midori_
body: *(NB. you should have been added your comment as a reply to my answer in the top, not as a new answer. Now the context is somewhat lost.)*

So, **permanent** deletion is a primary requirement? So must the content go **forever**?

I am asking this, because our add-on is built more with the mindset of "archive this content, so that it becomes invisible, but when it is necessary, it can be searched through, it can be viewed, it can be restored". The motto is: "don't delete, archive instead as you can never know".


author: Daniel Hertrich
body: *Oh sorry. WIll do the next time.*

Yes, permanent deletion is a primary requirement.

Basically, the requirement for now is that if the user deletes a page, it should be recoverable for x days, but not visible to the normal user anymore and not available for standard searches. After those x days, it should be deleted permanently automatically. This has legal reasons is thus a hard requirement.

In my use case, when using your plugin, archiving would be kind of a workaround for the lack of an automated way to purge the trash bin in a way that a page is deleted from the trash "x days after it has been trashed".

I think your plugin could help in that situation, if it could two two more things:

- Apply archiving rules also to already archived pages, i.e. that an "... (Archive)" space would be (optionally) visible to the archiving rules form, even if the space is set to "Status = Archived" (which would be required, too, to avoid search matches from these archives)

- If there was an additional "Archiving strategy", that takes care that content is permanently deleted. Maybe don't call it "archiving" then. ;-) In some companies, there are such (legal) requirements. If you add such features to the plugin, it could be very valuable to such companies, especially since there doesn't seem to be another available solution yet.


author: Aron Gombas _Midori_
body: Thanks for elaborating the use case, Daniel!

Based on your explanation I created 2 public feature requests in our tracker and I encourage you to vote on these:

1. <https://midori.zendesk.com/hc/en-us/articles/115004528194--Permanently-delete-archiving-strategy>
2. <https://midori.zendesk.com/hc/en-us/articles/115004528314-Allow-archiving-even-on-archive-spaces>

In addition to our product vision, user votes significantly affect the product roadmap.

**Final note:** I understand that the law requires you to permanently destroy content and that must go forever. But, those pages will be captured in Confluence backups and your database backups anyway. Is that compatible with the law?


author: Daniel Hertrich
body: Thanks Aron. For ease of implementation, "permanent deletion" could be implemented as another "Archiving strategy", however, my guess is that this is not too intuitive for new users, so it might be better to make this a new area on the archiving rules setup page and not list it as an "Archiving strategy", but rather a new rule what to do with a page.

The issue with backups is addressed already: No backups older than x days are kept at all. ;-)


author: Aron Gombas _Midori_
body: Gotcha!


author: Rafael Franco
body: Hi Daniel,

Using [ScriptRunner for Confluence](https://marketplace.atlassian.com/plugins/com.onresolve.confluence.groovy.groovyrunner/server/overview) as mentioned before you can establish using a Script Job what is the frequency that the check is made, meaning you can say that you want to purge the trash after 30 days of pages being in there.

Let me know if you need help with that.

Cheers,

Rafael


author: Aron Gombas _Midori_
body: How can you flush a **single** page from the trash?

If you cannot, then the trash cannot be used for this use case.

For example, if you put page "A" to the trash on 1 Jan, then page "B" on 5 Jan, and you completely empty the trash on 1 Feb (30 days after "A" was trashed), then "B" will also be flushed although it was 25 day old only -\> PROBLEM!


author: Daniel Hertrich
body: Rafael, Aron is right, I need to scan every single page in the trash and decide, depending on its "trashed" date, if it's going to be deleted permanently or not in the current script run. Is this possible?


author: Rafael Franco
body: Hi Daniel,

We had a similar question before from other customers and unfortunately Atlassian does not provide a timestamp when a page is trashed.

What you can do to make it work is to listen to the PageTrashEvent, add a content property to the page setting the date that was trashed and then use a Script Job to go through all these pages.

Hope it was clear,

Rafael


author: Aron Gombas _Midori_
body: Rafael, it still doesn't give an answer to my question:

*How can you flush a **single** page from the trash?*


author: Rafael Franco
body: DefaultTrashManager has a purge method with the following signature:

```
public boolean purge(String spaceKey, long contentId)
```

ContentId is the id of the page.


author: Daniel Hertrich
body: Rafael, do you mean there is no trashed date provided in an API by Atlassian or is there not even a trashed date stored in the Confluence database?


author: Rafael Franco
body: There isn't even a trashed date stored in the database :(

As I mentioned, you can implement yours, but it's not provided by Confluence. Shocking I know...


author: Aron Gombas _Midori_
body: \> DefaultTrashManager has a purge method with the following signature:

Ah, OK, cool! I didn't know about that.


author: Daniel Hertrich
body: Thanks guys, I'll see and discuss internally how we will proceed.


author: Anderson Hsu
body: Hi all,

How can I use it in confluence 4.2.3 environment? Kindly help give suggestion about how to clean trash automatically? Thanks a lot.

Regards, Hsu Yao Chang


author: LaurieC
body: [@Rafael Franco](/t5/user/viewprofilepage/user-id/781602) Thanks for the info on Scriptrunner for Confluence and the ability to purge specific pages from the trash. I have a few questions:

* If I understand correctly, you would use a listener to identify any deleted pages and then add a content property to capture the date it was deleted and then use the DefaultTrashManager to delete pages by content ID that have a content property older than say 90 days. Is that correct?
* Is the listener a built-in listener? Or can you provide the code to build out the listener that would put the date on the page?
* Is the DefaultTrashManager a built-in script? Will it analyze the content property and be able to evaluate which pages are older and a certain number of days and then return the list of content IDs of pages that should be deleted?
* Would this approach work also for attachments that are in the trash?

Thanks so much! We're evaluating options to delete items in the trash that are older than x days. We love Scriptrunner for Jira, but don't yet have Scriptrunner for Confluence.

Laurie


author: Aron Gombas _Midori_
body: You can empty trash periodically using the ScriptRunner app, as explained [here](https://community.atlassian.com/t5/Confluence-questions/Trash-Purge-all-across-spaces/qaq-p/303048).

As for emptying only certain pages from the trash, I don't think you can do that. It is "nothing or all".

If you need more sophisticated page lifecycle tracking (based on last modification, last view, manual markers, etc.) and automated archival, check out the [Archiving Plugin](https://marketplace.atlassian.com/plugins/com.midori.confluence.plugin.archiving/server/overview).

comments: author: Daniel Hertrich
body: Thank you Aron, I'll have a closer look at the Archiving Plugin. It looks very useful on first glance.