do while loop - $status never gets any value.

Issue #14 resolved
Joon Kim created an issue

When running the script, it just hangs. So I put it in debug (windows power shell ISE) and notice the do-while loop continues to wait for $status which never gets any value. Help is greatly appreciated. Please note that I added "os_authType=basic" in the url to bypass connection error (shown below the source code).

$account = 'jfshea' $username = 'xxxxx' $password = 'xxxxx' $destination = 'C:\JiraBackup' $attachments = $false

$hostname = "$account.atlassian.net" $today = Get-Date -format yyyyMMdd $credential = New-Object System.Management.Automation.PSCredential($username, (ConvertTo-SecureString $password -AsPlainText -Force))

if ($PSVersionTable.PSVersion.Major -lt 4) { throw "Script requires at least PowerShell version 4. Get it here: https://www.microsoft.com/en-us/download/details.aspx?id=40855" }

Invoke-WebRequest -Method Post -Uri "https://$hostname/login" -SessionVariable session -Body @{username = $username; password = $password} | Out-Null

Invoke-RestMethod -Method Post -Uri "https://$hostname/rest/obm/1.0/runbackup" -WebSession $session -ContentType 'application/json' -Body (@{cbAttachments = $attachments} | ConvertTo-Json -Compress) | Out-Null

do { $status = Invoke-RestMethod -Method Get -Headers @{"Accept"="application/json"} -Uri "https://$hostname/rest/obm/1.0/getprogress?os_authType=basic" -WebSession $session if ($status.alternativePercentage -match "(\d+)") { $percentage = $Matches[1] if ([int]$percentage -gt 100) { $percentage = "100" } Write-Progress -Activity 'Creating backup' -Status $status.alternativePercentage -PercentComplete $percentage } Start-Sleep -Seconds 5 } while($status.alternativePercentage -ne 'Estimated progress: 100 %')

if (bool) { throw $status.failedMessage }

$pathName = $status.fileName if ($pathName -match "ondemandbackupmanager/download/.+/(.)") { $fileName = $Matches[1] Write-Host "Downloading: $fileName to JIRA-backup-$today.zip" $progressPreference = 'Continue' Invoke-WebRequest -Method Get -Headers @{"Accept"="/*"} -WebSession $session -Uri "https://$hostname/$pathName" -OutFile (Join-Path -Path $destination -ChildPath "JIRA-backup-$today.zip") } else { throw "Attempted to download from WEBDAV directory, which is no longer supported" }


Here is the error when I do not use "os_authType=basic". I am hoping the issue above has nothing to do with it. Invoke-RestMethod : 401Client must be authenticated to access this resource. At C:\Users\jobserv\Desktop\Jira_Backup.ps1:24 char:1 + Invoke-RestMethod -Method Post -Uri "https://$hostname/rest/obm/1.0/runbackup" - ...

Comments (2)

  1. Log in to comment