How to delete archived issues

Still need help?

The Atlassian Community is here for you.

Ask the community


Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Purpose

If incase, environment has large number of archived issues and if we are sure, this is not required in future, those can be removed using the steps mentioned in this article. 

Solution

  • Execute the SQL query  from the database that will return all the issue keys and summary of archived issues:

    select ( p.pkey || '-' || ji.issuenum ) as "issue_key" from jiraissue ji
    join project p on p.id = ji.project
    where ji.archived = 'Y';
  • Considering the output mentioned below: 

    issue_key
    -----------
     PROJ-1 
    (1 row)
  • User can export the output as a CSV file and then iterate through those values in your PowerShell.
  • Here is how you can create a bash script that can be execute directly straight from Linux server:

Here are the steps:

  1. Create a .sh file with this content:

    #!/bin/bash
    echo "What's your Jira URL? Provide with the scheme, e.g. https://myjira.com"
    read jiraurl
    echo "What's your Jira username?"
    read username
    echo "What's your password?"
    read password
    
    cat issuelist.csv | while read line
    do
    echo "Restoring issue $line"
    curl -u $username:$password \
    	-H "Content-Type:application/json" \
    	-X PUT \
    	-k $jiraurl/rest/api/2/issue/$line/restore
    sleep 0.1
    echo "Deleting issue $line"
    curl -u $username:$password \
    	-H "Content-Type:application/json" \
    	-X DELETE \
    	-k $jiraurl/rest/api/2/issue/$line
    sleep 0.1
    done
    
    
  2. Obtain a list of all archived issues using the SQL below
    select ( p.pkey || '-' || ji.issuenum ) as "issue_key" from jiraissue ji
    join project p on p.id = ji.project
    where ji.archived = 'Y';
  3. You can customise the query further, for example to query for archived issues in project PROJ the query would be:

    select ( p.pkey || '-' || ji.issuenum ) as "issue_key" from jiraissue ji
    join project p on p.id = ji.project
    where ji.archived = 'Y' and p.pkey = 'PROJ';
  4. Put the output of the query into a file called ‘issuelist.csv’ in the same directory that you created the .sh file, with one issue key per line – the same way that the query will provide you
    • PROJ-10 
      PROJ-16 
      PROJ-15 
      PROJ-14 
      PROJ-17
  5. Run the script and provide your Jira baseurl, your username and password:

    $ sh delete-archived-issues.sh 
    What's your Jira URL? 
    Provide with the scheme, e.g. https://myjira.com https://10.125.91.129 
    What's your Jira username? USERNAME 
    What's your password? mypassword
  6. The script will iterate through each line, restore and then delete the issues. We need to restore the issues first because you can’t delete an archived issue directly:

    $ sh delete-archived-issues.sh 
    What's your Jira URL? 
    Provide with the scheme, e.g. https://myjira.com https://10.125.91.129 
    What's your Jira username? USERNAME 
    What's your password? PASSWORD 
    Restoring issue PROJ-10 
    Deleting issue PROJ-10 
    Restoring issue PROJ-16 
    Deleting issue PROJ-16 
    Restoring issue PROJ-15 
    Deleting issue PROJ-15 
    Restoring issue PROJ-14
    Deleting issue PROJ-14

There's a sleep of 1/10 of a second just to prevent a heavy load towards your Jira server. Please also remember to take a backup first in case any incorrect issues are deleted by mistakenly (e.g wrong SQL query)


Related info

The article How to speed up Jira Data Center project delete by deleting data ahead of time also present alternatives for deleting issue data directly from database. 


Description
ProductJira Software 

Last modified on Dec 9, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.