-
-
Save aka99/eaba91841609351a7673a51fd706472a to your computer and use it in GitHub Desktop.
Backup Atlassian Jira and Confluence from the command line.
This file contains hidden or 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
#!/bin/bash | |
USERNAME=<username> | |
PASSWORD=<password> | |
INSTANCE="<company>.atlassian.net" | |
LOCATION="./Backups/" | |
mkdir "Backups" | |
# Grabs cookies and generates the backup on the UI. | |
TODAY=`date +%Y%m%d` | |
COOKIE_FILE_LOCATION=confluencecookie | |
echo "Getting cookie and triggering backup." | |
curl -u $USERNAME:$PASSWORD --cookie-jar $COOKIE_FILE_LOCATION https://${INSTANCE}/Dashboard.jspa --output /dev/null | |
BKPMSG=`curl -s --cookie $COOKIE_FILE_LOCATION --header "X-Atlassian-Token: no-check" -H "X-Requested-With: XMLHttpRequest" -H "Content-Type: application/json" -X POST https://${INSTANCE}/wiki/rest/obm/1.0/runbackup -d '{"cbAttachments":"true" }' ` | |
echo "Result: ${BKPMSG}" | |
rm $COOKIE_FILE_LOCATION | |
#Checks if the backup procedure has failed | |
echo "Checking if operation failed..." | |
if [ `echo $BKPMSG | grep -i backup | wc -l` -ne 0 ]; then | |
echo "Failed to trigger backup. Trying to get file." | |
#The $BKPMSG variable will print the error message, you can use it if you're planning on sending an email | |
fi | |
echo "Backup successfully triggered. Waiting for file on server..." | |
#Checks if the backup exists in WebDAV every 10 seconds, 20 times. If you have a bigger instance with a larger backup file you'll probably want to increase that. | |
for (( c=1; c<=20; c++ )) | |
do | |
wget --user=$USERNAME --password=$PASSWORD --spider https://${INSTANCE}/webdav/backupmanager/Confluence-backup-${TODAY}.zip >/dev/null 2>/dev/null | |
OK=$? | |
if [ $OK -eq 0 ]; then | |
echo "Backup found on server." | |
break | |
fi | |
sleep 10 | |
done | |
#If after 20 attempts it still fails it ends the script. | |
if [ $OK -ne 0 ]; | |
then | |
echo "Could not find backup on server." | |
exit | |
else | |
#If it's confirmed that the backup exists on WebDAV the file get's copied to the $LOCATION directory. | |
echo "Saving backup to ${LOCATION}." | |
wget --user=$USERNAME --password=$PASSWORD -t 0 --retry-connrefused https://${INSTANCE}/webdav/backupmanager/Confluence-backup-${TODAY}.zip -P $LOCATION | |
fi |
This file contains hidden or 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
#!/bin/bash | |
USERNAME=<username> | |
PASSWORD=<password> | |
INSTANCE="<company>.atlassian.net" | |
LOCATION="./Backups/" | |
mkdir "Backups" | |
# Grabs cookies and generates the backup on the UI. | |
TODAY=`date +%Y%m%d` | |
COOKIE_FILE_LOCATION=jiracookie | |
echo "Getting cookie and triggering backup." | |
curl -u $USERNAME:$PASSWORD --cookie-jar $COOKIE_FILE_LOCATION https://${INSTANCE}/Dashboard.jspa --output /dev/null | |
BKPMSG=`curl -s --cookie $COOKIE_FILE_LOCATION --header "X-Atlassian-Token: no-check" -H "X-Requested-With: XMLHttpRequest" -H "Content-Type: application/json" -X POST https://${INSTANCE}/rest/obm/1.0/runbackup -d '{"cbAttachments":"true" }' ` | |
echo "Result: ${BKPMSG}" | |
rm $COOKIE_FILE_LOCATION | |
#Checks if the backup procedure has failed | |
echo "Checking if operation failed..." | |
if [ `echo $BKPMSG | grep -i backup | wc -l` -ne 0 ]; then | |
echo "Failed to trigger backup. Trying to get file." | |
#The $BKPMSG variable will print the error message, you can use it if you're planning on sending an email | |
fi | |
echo "Backup successfully triggered. Waiting for file on server..." | |
#Checks if the backup exists in WebDAV every 10 seconds, 20 times. If you have a bigger instance with a larger backup file you'll probably want to increase that. | |
for (( c=1; c<=20; c++ )) | |
do | |
wget --user=$USERNAME --password=$PASSWORD --spider https://${INSTANCE}/webdav/backupmanager/JIRA-backup-${TODAY}.zip >/dev/null 2>/dev/null | |
OK=$? | |
if [ $OK -eq 0 ]; then | |
echo "Backup found on server." | |
break | |
fi | |
sleep 10 | |
done | |
#If after 20 attempts it still fails it ends the script. | |
if [ $OK -ne 0 ]; | |
then | |
echo "Could not find backup on server." | |
exit | |
else | |
#If it's confirmed that the backup exists on WebDAV the file get's copied to the $LOCATION directory. | |
echo "Saving backup to ${LOCATION}." | |
wget --user=$USERNAME --password=$PASSWORD -t 0 --retry-connrefused https://${INSTANCE}/webdav/backupmanager/JIRA-backup-${TODAY}.zip -P $LOCATION | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment