Script fails silently if admin access is removed for token

Issue #36 resolved
Denis Dokleja created an issue

I’m using confluence-backup.sh and jira-backup.sh to backup our cloud instances. Scripts were working fine but then admin privileges were accidentally removed from the user which tokens are used. Scripts do not catch this scenario and do not output any kind of errors, they run as usual, but no backup file is created.

The reason for this is that you are catching curl output and looking for “error” string in the output, but in this case curl produces no output and only gets 403 response code, and this is not recognized by the scripts.

Comments (4)

  1. Dario B

    Hi @Denis Dokleja ,

    Even if one of the pre-requisites is to make sure to be site-admin before running the scripts, I will try to see if I can take also this scenario into account (check the returned status codes). However, this will take some time and I cannot really provide any ETA for this.

    Cheers,
    Dario

  2. Dario B

    Hi @Denis Dokleja ,

    I am thinking to use something like below code, even if I haven’t tested yet:

    ## The $BKPMSG variable is used to save and print the response
    BKPMSG=$(curl -s -u ${EMAIL}:${API_TOKEN} --write-out '%{http_code}' -H "Accept: application/json" -H "Content-Type: application/json" --data-binary "{\"cbAttachments\":\"$INCLUDE_ATTACHMENTS\", \"exportToCloud\":\"$EXPORT_TO_CLOUD\"}" -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 '}200')" -e 0 ]; then
        if [ "$(echo "$BKPMSG" | grep -ic '}403')" -e 0 ]; then
            echo "403 (FORBIDDEN) You must be site-admin in order to run this script"
            exit
        fi  
        ERROR=$(echo "$BKPMSG" | sed -n 's/.*"error"[ ]*:[ ]*"\([^"]*\).*/\1/p')
        echo "BACKUP FAILED!! Message returned: $ERROR"
        exit
    fi
     [....]
    

    However, I can also see that the work to start implementing automatic backups in Cloud is starting. If interested, you may want to ask for access to:

    Click the link, click request access, and we should get you in within 24 hours to review our strategy and provide feedback as we go.

  3. Log in to comment