Hi everybody
I'm trying to get the PowerShell script running again, which doesnt work anymore for a few months. After replacing the URLs of the old Cloud infrastructure with the new ones mentioned here - https://jira.atlassian.com/browse/JRACLOUD-67169?src=confmacro&_ga=2.152189625.1813114333.1508752703-597319643.1507625905 - I get the next error, when requesting the backup, progress status and download: Invoke-RestMethod : Der Remoteserver hat einen Fehler zurückgegeben: (401) Nicht autorisiert.At \Scripts\Jira Cloud Backup - new URLs.ps1:19 char:1+ Invoke-RestMethod -Method Post -Uri "https://$hostname/rest/backup/1/ ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Using these PS commands:
# LoginInvoke-WebRequest -Method Post -Uri "https://$hostname/login" -SessionVariable $session -Body @{username = $username; password = $password} | Out-Null# Request backupInvoke-RestMethod -Method Post -Uri "https://$hostname/rest/backup/1/export/runbackup" -WebSession $session -ContentType 'application/json' -Body (@{cbAttachments = $attachments} | ConvertTo-Json -Compress) | Out-Null
Can anyone help me out?
Hi @CeDeAdmin,
The described behaviour is the same as:
The solution/workaround for both bugs is the same:
Most of the times this happens because of the bruteforce protection mechanism. A way to have this working again is to reset the password for the user in id.atlassian.com by going to:- https://id.atlassian.com/manage/change-passwordIf this is not applicable because you didn't have a password previously set in id.atlassian.com and therefore you cannot use the change-password form. Then do the following:Go to https://id.atlassian.com/login/resetpasswordEnter you email, complete the CAPTCHA and click on SendOnce you receive the password reset email, do not click on the button to Access but on the link below that says "reset password".Fill up the new password and you are done.
Most of the times this happens because of the bruteforce protection mechanism. A way to have this working again is to reset the password for the user in id.atlassian.com by going to:- https://id.atlassian.com/manage/change-password
If this is not applicable because you didn't have a password previously set in id.atlassian.com and therefore you cannot use the change-password form. Then do the following:
Please try the above steps and let me know if this works. If it doesn't either provide more details or open a support request in support.atlassian.com to have this issue addressed.
Cheers,Dario
Hi Dario
I changed the password for the user user in the backup script, but I get the same error back in the event log.I couldnt find the error in the PowerShell script. I posted the two commands before, which log in in a first step and request to start the backup. The login session should be saved in the first step in the variable $session and is used in the backup-request-command. Maybe you see there an error, if you know PowerShell?
I also opened a ticket for this case - JST-336037. But Travis, which is in charge there, sent me URL to the page with the curl commands and new URL of the new infrastructure, but this is not helping me out with the authentication problem. I'm also waiting there for a reply.
Regards, Stefan
And I also tried out the curl commands over GIT Bash, and they seem to work, but I get no result back. Used the commands mentioned in JRACLOUD-67169 (took only the first line of command, second line seems to be the result of the command - Sorry, I'm pretty new to scripting so I rather ask than stay unsure) Maybe it doesnt give me the backup file as result, as I made a manual Cloud Backup today and downloaded it, to have something until the automatic backup works again...
@CeDeAdmin
I checked the support ticket and there is no information in there mentioning the fact that you have issues with the authentication and not with the endpoints or with the script itself. Also, you haven't mentioned this community thread in the support ticket. That's why you have been sent back to here by the assigned engineer.
I left an internal comment saying that your issue is actually with authentication. However, by re-reading your error message it seems that the unauthorised error is coming from the line that is starting the backup and not from the one to start a session and save it in a cookie-jar file.. at this point I am wondering if the problem is not with the way the cookie is stored/used by the script itself...
Have you actually tried to run the rest calls in a shell one by one using curl (and not in a script) and see if it works that way?
This is because, as written in the section named Support Does Not Include of the Atlassian Support Offerings :
Support Does Not IncludeDevelopment questions or requests.For community-based development support, please post these questions on Atlassian Community.Note: If a bug in Atlassian development API is believed to be the root cause, sample code that demonstrates the problem and can be replicated must be provided.
Development questions or requests.
Please try to run the commands from the workaround for JRACLOUD-67169 one after the other from command line to identify where the problem is. Also, provide this information in the support ticket.
Hi Is there an api that will allow me get the details (mediaFileId and filename) of the last backup?
Thanks
Chris
Never mind, I figured out you can check this with the /rest/internal/2/task/progress/ API call
Hi @CeDeAdmin and @Chris Dunne _Raledo_,
Not sure this is still needed, however, I have just tested the below script to backup Confluence Cloud and I can confirm it works fine:
#!/bin/bash##---Fill-up the user account details, instance url and timezone-----USERNAME=USER_NAME_HEREPASSWORD=PASSWORD_HEREINSTANCE=INSTANCE.atlassian.netLOCATION="/path/to/download/folder"# 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_zonesTIMEZONE=Europe/Amsterdam##----START-----###echo "Starting the script..."# Grabs cookies and generates the backup on the UI. ########### PLEASE NOTICE THAT THE SESSION IS CREATED BY CALLING THE JIRA SESSION ENDPOINT!!! ########## THE SCRIPT DOES NOT WORK IF JIRA IS NOT INSTALLED !!! #######TODAY=$(TZ=$TIMEZONE date +%Y%m%d)COOKIE_FILE_LOCATION=jiracookiecurl --silent --cookie-jar $COOKIE_FILE_LOCATION -X POST "https://${INSTANCE}/rest/auth/1/session" -d "{\"username\": \"$USERNAME\", \"password\": \"$PASSWORD\"}" -H 'Content-Type: application/json' --output /dev/null## The $BKPMSG variable will print the error message, you can use it if you're planning on sending an emailBKPMSG=$(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" }' )## Checks if the backup procedure has failedif [ "$(echo "$BKPMSG" | grep -ic backup)" -ne 0 ]; thenrm $COOKIE_FILE_LOCATIONecho "FAILED, IT RETURNED $BKPMSG"exitfi## 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++ ))doPROGRESS_JSON=$(curl -s --cookie $COOKIE_FILE_LOCATION 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"* ]]; thenbreakfiif [ ! -z "$FILE_NAME" ]; thenbreakfisleep 10done#If after 20 attempts it still fails it ends the script.if [ -z "$FILE_NAME" ];thenrm $COOKIE_FILE_LOCATIONexitelse## PRINT THE FILE TO DOWNLOAD ##echo "File to download: $FILE_NAME"curl -s -L --cookie $COOKIE_FILE_LOCATION "https://${INSTANCE}/wiki/download/$FILE_NAME" -o "$LOCATION/CONF-backup-${TODAY}.zip"firm $COOKIE_FILE_LOCATION
Also this one is a Bash shell script but it is very clear and readable and it is exposing the correct endpoints to be called in order to automate Confluence backup.
I hope this helps.
And this is the script for JIRA since some endpoints changed again.
All I did in order to have the backup script working again is:
#!/bin/bashUSERNAME=PASSWORD=INSTANCE=LOCATION="/path/to/download/folder"### Checks for progress 3000 times every 20 seconds ###PROGRESS_CHECKS=3000SLEEP_SECONDS=20# 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_zonesTIMEZONE=Europe/Amsterdam##----START-----###echo "starting the script"# Grabs cookies and generates the backup on the UI. TODAY=$(TZ=$TIMEZONE date +%Y%m%d)COOKIE_FILE_LOCATION=jiracookiecurl --silent --cookie-jar $COOKIE_FILE_LOCATION -X POST "https://${INSTANCE}/rest/auth/1/session" -d "{\"username\": \"$USERNAME\", \"password\": \"$PASSWORD\"}" -H 'Content-Type: application/json' --output /dev/null## The $BKPMSG variable will print the error message, you can use it if you're planning on sending an emailBKPMSG=$(curl -s --cookie $COOKIE_FILE_LOCATION -H "Accept: application/json" -H "Content-Type: application/json" https://${INSTANCE}/rest/backup/1/export/runbackup --data-binary '{"cbAttachments":"true", "exportToCloud":"true"}' )##ADDED##echo "message: $BKPMSG"#Checks if the backup procedure has failedif [ "$(echo "$BKPMSG" | grep -ic error)" -ne 0 ]; thenrm $COOKIE_FILE_LOCATIONecho "FAILED, IT RETURNED: $BKPMSG"exitfiTASK_ID=$(curl -s --cookie $COOKIE_FILE_LOCATION -H "Accept: application/json" -H "Content-Type: application/json" https://${INSTANCE}/rest/backup/1/export/lastTaskId)#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++ ))doPROGRESS_JSON=$(curl -s --cookie $COOKIE_FILE_LOCATION https://${INSTANCE}/rest/backup/1/export/getProgress?taskId=${TASK_ID})FILE_NAME=$(echo "$PROGRESS_JSON" | sed -n 's/.*"result"[ ]*:[ ]*"\([^"]*\).*/\1/p')##ADDED##echo "$PROGRESS_JSON"if [[ $PROGRESS_JSON == *"error"* ]]; thenbreakfiif [ ! -z "$FILE_NAME" ]; thenbreakfisleep 10done#If after 2000 attempts it still fails it ends the script.if [ -z "$FILE_NAME" ];thenrm $COOKIE_FILE_LOCATIONexitelse## PRINT THE FILE TO DOWNLOAD ##echo "File to download: https://${INSTANCE}/plugins/servlet/${FILE_NAME}"curl -s -L --cookie $COOKIE_FILE_LOCATION "https://${INSTANCE}/plugins/servlet/${FILE_NAME}" -o "$LOCATION/JIRA-backup-${TODAY}.zip"firm $COOKIE_FILE_LOCATION
Hi - not sure if you were still looking for a PowerShell script - this ticket has been open in Bitbucket for a while and has some amended versions of the original script including one from this morning to handle the latest amendment to the REST API that Dario mentioned above ..
It looks like you're new here. Sign in or register to get started.