-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfluence-cloud-backup.sh
61 lines (45 loc) · 1.9 KB
/
confluence-cloud-backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
#With Atlassian Cloud rate limits, only can run once every 48 hours.
USERNAME=username
PASSWORD=apikey
INSTANCE=yoursite.atlassian.net
LOCATION="/atlassian-backups/"
# Set this to your Atlassian instance's timezone.
# See this for a list of possible values:
# https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
TIMEZONE=America/New_York
##----START-----###
echo "Starting the script..."
### PLEASE NOTICE THAT THE SESSION IS CREATED BY CALLING THE JIRA SESSION ENDPOINT!!! ######
#### THE SCRIPT DOES NOT WORK IF JIRA IS NOT INSTALLED !!! #######
## The $BKPMSG variable will print the error message, you can use it if you're planning on sending an email
BKPMSG=$(curl -s --user "${USERNAME}:${PASSWORD}" --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" }' )
## Checks if the backup procedure has failed
if [ "$(echo "$BKPMSG" | grep -ic backup)" -ne 0 ]; then
echo "FAILED, IT RETURNED $BKPMSG"
exit
fi
## Checks if the backup exists every 10 seconds, 2000 times. If you have a bigger instance with a larger backup file you'll probably want to increase that.
for (( c=1; c<=2000; c++ ))
do
PROGRESS_JSON=$(curl -s --user "${USERNAME}:${PASSWORD}" https://${INSTANCE}/wiki/rest/obm/1.0/getprogress.json)
FILE_NAME=$(echo "$PROGRESS_JSON" | sed -n 's/.*"fileName"[ ]*:[ ]*"\([^"]*\).*/\1/p')
##ADDED: PRINT BACKUP STATUS INFO ##
echo "$PROGRESS_JSON"
if [[ $PROGRESS_JSON == *"error"* ]]; then
break
fi
if [ ! -z "$FILE_NAME" ]; then
break
fi
sleep 10
done
#If after 2000 attempts it still fails it ends the script.
if [ -z "$FILE_NAME" ];
then
exit
else
## PRINT THE FILE TO DOWNLOAD ##
echo "File to download: $FILE_NAME"
curl -s -L --user "${USERNAME}:${PASSWORD}" "https://${INSTANCE}/wiki/download/$FILE_NAME" -o "$LOCATION/CONF-backup-${TODAY}.zip"
fi