-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from mattock/fix_jira_backup
Fix JIRA backups
- Loading branch information
Showing
2 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/bin/bash | ||
|
||
|
||
###--- CONFIGURATION SECTION STARTS HERE ---### | ||
# MAKE SURE ALL THE VALUES IN THIS SECTION ARE CORRECT BEFORE RUNNIG THE SCRIPT | ||
|
||
CONFIG="$HOME/.backup.sh.vars" | ||
|
||
if [ -r "$CONFIG" ]; then | ||
. $CONFIG | ||
else | ||
echo "Usable to load $CONFIG! Please create one based on backup.sh.vars.example" | ||
exit 1 | ||
fi | ||
|
||
|
||
####- START SCRIPT -##### | ||
|
||
TODAY=$(TZ=$TIMEZONE date +%d-%m-%Y) | ||
echo "starting the script: $TODAY" | ||
|
||
|
||
## The $BKPMSG variable is used to save and print the response | ||
BKPMSG=$(curl -s -u ${EMAIL}:${API_TOKEN} -H "Accept: application/json" -H "Content-Type: application/json" --data-binary '{"cbAttachments":"true", "exportToCloud":"true"}' -X POST https://${HOSTNAME}/rest/backup/1/export/runbackup ) | ||
|
||
## Uncomment below line to print the response message also in case of no errors ## | ||
# echo "Response: $BKPMSG" | ||
|
||
# If the backup did not start print the error messaget returned and exits the script | ||
if [ "$(echo "$BKPMSG" | grep -ic error)" -ne 0 ]; then | ||
echo "BACKUP FAILED!! Message returned: $BKPMSG" | ||
exit | ||
fi | ||
|
||
# If the backup started correctly it extracts the taskId value from the response | ||
# As an alternative you can call the endpoint /rest/backup/1/export/lastTaskId to get the last task-id | ||
TASK_ID=$(echo "$BKPMSG" | sed -n 's/.*"taskId"[ ]*:[ ]*"\([^"]*\).*/\1/p') | ||
|
||
|
||
# Checks if the backup process completed for the number of times specified in PROGRESS_CHECKS variable | ||
for (( c=1; c<=${PROGRESS_CHECKS}; c++ )) | ||
do | ||
PROGRESS_JSON=$(curl -s -u ${EMAIL}:${API_TOKEN} -X GET https://${HOSTNAME}/rest/backup/1/export/getProgress?taskId=${TASK_ID}) | ||
FILE_NAME=$(echo "$PROGRESS_JSON" | sed -n 's/.*"result"[ ]*:[ ]*"\([^"]*\).*/\1/p') | ||
|
||
# Print progress message | ||
echo "$PROGRESS_JSON" | ||
|
||
if [[ $PROGRESS_JSON == *"error"* ]]; then | ||
break | ||
fi | ||
|
||
if [ ! -z "$FILE_NAME" ]; then | ||
break | ||
fi | ||
|
||
# Waits for the amount of seconds specified in SLEEP_SECONDS variable between a check and the other | ||
sleep ${SLEEP_SECONDS} | ||
done | ||
|
||
# If the backup is not ready after the configured amount of PROGRESS_CHECKS, it ends the script. | ||
if [ -z "$FILE_NAME" ]; | ||
then | ||
exit | ||
else | ||
|
||
|
||
## PRINT THE FILE TO DOWNLOAD ## | ||
echo "File to download: https://${HOSTNAME}/plugins/servlet/${FILE_NAME}" | ||
|
||
#Check if we should overwrite the previous backup or append a timestamp to | ||
#prevent just that. The former is useful when an external backup program handles | ||
#backup rotation. | ||
if [ $TIMESTAMP = "true" ]; then | ||
OUTFILE="${DOWNLOAD_FOLDER}/JIRA-backup-${TODAY}.zip" | ||
elif [ $TIMESTAMP = "false" ]; then | ||
OUTFILE="${DOWNLOAD_FOLDER}/JIRA-backup.zip" | ||
else | ||
echo "ERROR: invalid value for TIMESTAMP: should be either \"true\" or \"false\"" | ||
exit 1 | ||
fi | ||
|
||
curl -s -L -u ${EMAIL}:${API_TOKEN} -X GET "https://${HOSTNAME}/plugins/servlet/${FILE_NAME}" -o "$OUTFILE" | ||
|
||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters