How to archive attachments of archived projects

Still need help?

The Atlassian Community is here for you.

Ask the community

The information on this page relates to customizations in Jira Applications via a third-party app. Consequently, Atlassian Support cannot guarantee the provision of any support for the steps described on this page as customizations and third-party apps are not covered under Atlassian Support Offerings. Please be aware that this material is provided for your information only and that you use it at your own risk.


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

    

Summary

When a Jira project is archived, the attachments associated to the project are kept in place. 

As these attachments won't be used often, admins may choose to move them to another disk location. 

Environment

This article has two different solutions:

  1. Groovy code, so only applies to Jira installations on Linux systems with the ScriptRunner app
  2. Manual solution. You will need some OS command line & DB experience.

Solution 1

The idea here is to create a ScriptRunner job that runs at specific intervals and executes Groovy code to move the attachments to a different location.

The Groovy code below executes system calls, please test properly before deploying.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.util.JiraHome

def issueManager = ComponentAccessor.getIssueManager()
def attachmentManager = ComponentAccessor.getAttachmentManager()
def projectManager = ComponentAccessor.getProjectManager()

def jiraHome = ComponentAccessor.getComponentOfType(JiraHome.class).getHome()
def jiraArchiveLocation = "/path/to/jira-attachments-archive/"

projectManager.getArchivedProjects().each {project ->
    def projectKey = project.getKey()
    log.warn("Archiving attachments for " +  projectKey)
    def command = "mv " + jiraHome + "/data/attachments/" + projectKey + "/ " + jiraArchiveLocation
    command.execute()
}

Another alternative

If you need the attachments to still be accessible to issues but move them to another disk, you may create a symbolic link to the new location after moving them: 

    def command = "mv " + jiraHome + "/data/attachments/" + projectKey + "/ " + jiraArchiveLocation
    command.execute()
    def command = "ln -s " + jiraArchiveLocation + "projectKey"  + " " + jiraHome + "/data/attachments/" + projectKey
    command.execute()


Solution 2

You can manually achieve the same result, but you will need some skills on the OS command line and DB. 

(warning) Before continuing, please back up your data first. Please proceed by using the native database backup tools and backing up the data directory.


  • List all the atthacments of the Archived projects or Issues (individually archived) by using the following SQL queries:
-- Return all attachments for archived Issues, when they were archived independently.
select jp.pkey, ji.issuenum , fa.filename, fa.filesize 
from project jp, jiraissue ji, fileattachment fa
where jp.id = ji.project
and ji.archived='Y' 
and ji.id = fa.issueid 
order by jp.pkey, ji.issuenum;

-- Return all attachments for all Issues in Archived Projects.
select pe.property_key, jp.pkey, ji.issuenum, fa.filename, fa.filesize 
from propertyentry pe, project jp, fileattachment fa, jiraissue ji
where jp.id = pe.entity_id 
and property_key = 'jira.archiving.projects'
and jp.id = ji.project
and ji.id = fa.issueid;


  • Move the attachments individually or by project and create the symbolic links as follows:

Linux:

  1. Create a new disk volume to store attachments from all those archived Projects/Issues.
  2. Move the attachments from the archived Projects folder: <jira-home>\data\attachments\<project-key>.
    1. Example: Let's say that your project AA is archived, then you'll move the folder <jira-home>/data/attachments/AA to the new disk volume (/New Disk Vol Path/AA).
  3. Create a symbolic link in <jira-home>/data/attachments for folder AA
    ln -s /New Disk Vol Path/AA <jira-home>/data/attachments/AA

Windows:

  1. Create a new disk volume to store attachments from all those archived Projects.
  2. Move the attachments from the archived Projects folder: <jira-home>\data\attachments\<project-key>.
    1. Example: Let's say that your project AA is archived, then you'll move the folder <jira-home>\data\attachments\AA to the new disk volume (\New Disk Vol Path\AA).
  3. Create a symbolic link in <jira-home>\data\attachments for folder AA. You can follow the mklink documentation to do it. Example:
    mklink /d <jira-home>\data\attachments\AANDP  \New Disk Vol Path\AANDP



Last modified on Aug 22, 2022

Was this helpful?

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