Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Use ScriptRunner to purge trash over X days old

Doug January 7, 2019

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

Suggest an answer

Log in or Sign up to answer
0 votes
Tony Gough _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 24, 2019

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:

https://scriptrunner.adaptavist.com/latest/confluence/ScriptJobs.html

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,
Tony

Renni Verho October 7, 2019

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

chrome_9unVv5Hk2V.png

Renni Verho November 4, 2019

Managed to create automated script which is running regularly. 

Danny Prill
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 16, 2021

@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?

Renni Verho August 16, 2021

/*
Script to clean trash from confluence space(s)
script is modified version of script in https://jira.atlassian.com/browse/CONFSERVER-30043
*/

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")
logging.setLevel(Level.DEBUG)

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)
logging.info("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: ${space.name}")
trashManager.emptyTrash(space)
}

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

Like # people like this
TAGS
AUG Leaders

Atlassian Community Events