Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Use ScriptRunner to purge trash over X days old

Is it possible to create a Confluence ScriptRunner script/job to purge items in space trash that have been there over X amount of days? Looking for an automated way to clean up spaces every 90 days or so to reduce storage. Thanks

1 answer

Hi Doug,

We do have a built-in script 'Bulk Purge Trash' which purges the trash of a specific space, or all spaces. Built-in scripts require manually running, however.

To run custom scripts on a schedule, we have the Script Job feature, which you can read more about in the documentation:

This involves defining a CRON expression which specifies how often the script should run. Additionally, there are example expressions within the Script Job page on the app itself.

I hope this is useful to you, please let me know if you have any further questions!

Kind regards,

Is that "Bulk Purge Trash" removed in latest plugin version as I cannot find it ? 


Managed to create automated script which is running regularly. 

@Renni Verho 

It would be great, if you could post your script. I've searched the whole internet ;) and cannot find a solution or a script.

Could you?

Script to clean trash from confluence space(s)
script is modified version of script in

package com.onresolve.confluence.scripts
import com.atlassian.confluence.pages.TrashManager
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.confluence.spaces.SpacesQuery
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal
import com.atlassian.spring.container.ContainerManager
import org.apache.log4j.Level
import org.apache.log4j.Logger

def logging = Logger.getLogger("com.onresolve.confluence.scripting.EmptyTrashSpaces")

def trashManager = ContainerManager.getComponent("trashManager") as TrashManager
def spaceManager = ContainerManager.getComponent("spaceManager") as SpaceManager
def spacesQuery = SpacesQuery.newQuery().forUser(AuthenticatedUserThreadLocal.get()).build()
def Spaces = []

// clean all spaces :
Spaces = spaceManager.getAllSpaces(spacesQuery)"spaces found : ${Spaces}")

//Way to clean just selected spaces :
Spaces = []
Spaces << spaceManager.getSpace("DEMO")

logging.warn("Spaces trash to be cleaned: ${Spaces}")

Spaces.each {space ->
logging.warn("Empty trash from space: ${}")

"Emptied trash from ${Spaces.size()} spaces. List of spaces: ${Spaces} "

Like Hamza Koca likes this

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

205 views 1 6
Read article

Atlassian Community Events