At one of the customers sites we are using JIRA OnDemand (A.K.A JIRA Cloud now) to track our BSM tasks and cost estimates, which we provide for a planned piece of work and these exist in JIRA as Excel files attached to tasks.
As the end of financial year is coming close here in Australia I was asked by my manger to send him these cost estimates for the last financial year. Trying to do it manually one by one from the Web UI for a couple of them made me think that there must be a better way to accomplish that. Google search did bring a few results but they were relevant to on premisses hosted JIRA solution where you had access to the command line. These didn’t suit me. So after playing around a little I came up with the solution described below. If you have a Linux machine (and a know how) you could probably achieve that in a couple of lines but I only had access to my Windows machine at that time . In addition to a Windows machine you will need Notepad++.
Export JIRA backup
- In the JIRA OnDemand interface navigate to JIRA Administration > System
- Under the Import and Export click Backup manager
- On the Backup manager page verify that Back up attachments is checked and click Create Backup
- Once the backup is done a link to download the backup archive will be visible.
- Download the file and unzip it to a temporary folder (I’ve used C:\Temp).
Extracting attachments’ file names
- Open the C:\Temp\JIRA-backup-20140605\entities.xml with Notepad++
- Search the file for all the lines that have following text: FileAttachment
- The result will be shown in the “Find result” pane
- Open a new file in Notepad++ and copy all the content from “Find result” pane
- Run the following replace:
ren \1 \2
- As a result you will have somthing simmilar to the below:
- Remove all the lines that don’t start with “ren”
Copy files from all subfolders to a single folder
- The attachments are located in the <BACKUP_ARCHIVE_FILE>\data\attachments folder (in our case it’s C:\temp\JIRA-backup-20140605\data\attachments)
- Open a command prompt:
- Change current directory to the attachments one
Note: if you are interested only in attachments from a specific project then type cd C:\temp\JIRA-backup-20140605\data\attachments\<PROJECT_NAME> instead of the above.
- Create an output folder (if you are interested only in attachments from a specific project
- Copy files form all the projects into the output folder
for /R %b in (.) do @copy %b\*.* c:\temp\JIraAttachments\
- Change the current directory to the output directory
- Rename the files (just copy and paste the content of the text file from Notepad++
ren 10601 “Cost Estimation 1.xlsx”
ren 10303 “ALM Cost Calculator.xlsx”
ren 10304 “App Instrumentation – BPE.pptx”
ren 10604 “BPE Approval.msg”
- The result is that you have all the attachments in one folder. By the way the attributes (like Date Modified) are kept