diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c6fb16..ce2a7d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,20 @@ All notable changes to the [Alteryx deploy](https://github.com/Akaizoku/alteryx- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.1.2](https://github.com/Akaizoku/alteryx-deploy/releases/1.1.2) - 2021-12-13 + +UX improvements + +### Changed + +- Automatically update environment variables during restore (installation path, Gallery URL, etc.) + +### Fixed + +- Fixed an issue when the license email was not specified ([#4](https://github.com/Akaizoku/alteryx-deploy/issues/4)) +- Fixed an issue when the license email was not specified and the Active Directory server was unreachable ([#5](https://github.com/Akaizoku/alteryx-deploy/issues/5)) +- Fixed an issue preventing the restoration on a different machine ([#8](https://github.com/Akaizoku/alteryx-deploy/issues/8)) + ## [1.1.1](https://github.com/Akaizoku/alteryx-deploy/releases/1.1.1) - 2021-11-23 ### Changed @@ -17,6 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.1.0](https://github.com/Akaizoku/alteryx-deploy/releases/1.1.0) - 2021-11-21 +2021.4 hotfix + ### Added - `Invoke-StartAlteryx` now checks for release version to ensure compatibility diff --git a/README.md b/README.md index 6b80252..f9f0aa4 100644 --- a/README.md +++ b/README.md @@ -301,11 +301,12 @@ Below are the steps to restore the Alteryx application database. 2. Check backup path; - If backup file is an archive (.ZIP), extract files from archive. - If backup path is a directory, select most recent backup file (using [last write time](https://docs.microsoft.com/en-us/dotnet/api/system.io.filesysteminfo.lastwritetime)). -3. Restore MongoDB database; -4. Restore application configuration files; +3. Restore application configuration files; +4. Update configuration to match new environment; 5. Restore controller token; 6. Reset storage keys; -7. Restart Alteryx Service (if it was running previously). +7. Restore MongoDB database; +8. Restart Alteryx Service (if it was running previously). ### Start @@ -388,6 +389,7 @@ Only the first version supported is listed. Later releases should also be compat | [1.0.0] | [2021.3] | 5.0 | 1.2.4 | 1.0.0 | | [1.1.0] | [2021.3] | 5.0 | 1.2.5 | 1.0.1 | | [1.1.1] | [2021.3] | 5.0 | 1.2.5 | 1.0.1 | +| [1.1.2] | [2021.3] | 5.0 | 1.2.5 | 1.0.1 | ## Known issues @@ -409,4 +411,5 @@ It can be prevented by configuring a temporary directory (`TempDirectory`) that [1.0.0]:https://github.com/Akaizoku/alteryx-deploy/releases/1.0.0 [1.1.0]:https://github.com/Akaizoku/alteryx-deploy/releases/1.1.0 [1.1.1]:https://github.com/Akaizoku/alteryx-deploy/releases/1.1.1 +[1.1.2]:https://github.com/Akaizoku/alteryx-deploy/releases/1.1.2 [2021.3]:https://help.alteryx.com/release-notes/server/server-20213-release-notes diff --git a/conf/custom.ini b/conf/custom.ini new file mode 100644 index 0000000..1ad3910 --- /dev/null +++ b/conf/custom.ini @@ -0,0 +1,4 @@ +# ------------------------------------------------------------------------------ +# Add your custom configuration here +# e.g. TempDirectory = D:\Temp +# ------------------------------------------------------------------------------ diff --git a/conf/default.ini b/conf/default.ini index 7eff010..ee86e39 100644 --- a/conf/default.ini +++ b/conf/default.ini @@ -40,6 +40,10 @@ Version = 2021.3.3.63061 EnableSSL = false # InstallAware log InstallAwareLog = false +# Activate Alteryx during installation +ActivateOnInstall = true +# Activate Alteryx during upgrade +ActivateOnUpgrade = true [License] # Licensing system URL diff --git a/powershell/Install-Alteryx.ps1 b/powershell/Install-Alteryx.ps1 index 382f6d5..677cfd7 100644 --- a/powershell/Install-Alteryx.ps1 +++ b/powershell/Install-Alteryx.ps1 @@ -16,7 +16,7 @@ function Install-Alteryx { File name: Install-Alteryx.ps1 Author: Florian Carrier Creation date: 2021-07-05 - Last modified: 2021-11-20 + Last modified: 2021-12-08 .LINK https://www.powershellgallery.com/packages/PSAYX @@ -87,9 +87,17 @@ function Install-Alteryx { if (Test-Path -Path $ServerPath) { if ($Properties.InstallAwareLog -eq $true) { $InstallAwareLog = Join-Path -Path $Properties.LogDirectory -ChildPath "${ISOTimeStamp}_${ServerFileName}.log" - $ServerInstall = Install-AlteryxServer -Path $ServerPath -InstallDirectory $Properties.InstallationPath -Log $InstallAwareLog -Serial $Properties.LicenseEmail -Language $Properties.Language -AllUsers -Unattended:$Unattended + if ($null -eq $Properties.LicenseEmail -Or $Properties.LicenseEmail -eq "") { + $ServerInstall = Install-AlteryxServer -Path $ServerPath -InstallDirectory $Properties.InstallationPath -Log $InstallAwareLog -Language $Properties.Language -AllUsers -Unattended:$Unattended + } else { + $ServerInstall = Install-AlteryxServer -Path $ServerPath -InstallDirectory $Properties.InstallationPath -Log $InstallAwareLog -Serial $Properties.LicenseEmail -Language $Properties.Language -AllUsers -Unattended:$Unattended + } } else { - $ServerInstall = Install-AlteryxServer -Path $ServerPath -InstallDirectory $Properties.InstallationPath -Serial $Properties.LicenseEmail -Language $Properties.Language -AllUsers -Unattended:$Unattended + if ($null -eq $Properties.LicenseEmail -Or $Properties.LicenseEmail -eq "") { + $ServerInstall = Install-AlteryxServer -Path $ServerPath -InstallDirectory $Properties.InstallationPath -Language $Properties.Language -AllUsers -Unattended:$Unattended + } else { + $ServerInstall = Install-AlteryxServer -Path $ServerPath -InstallDirectory $Properties.InstallationPath -Serial $Properties.LicenseEmail -Language $Properties.Language -AllUsers -Unattended:$Unattended + } } Write-Log -Type "DEBUG" -Message $ServerInstall if ($ServerInstall.ExitCode -eq 0) { @@ -99,7 +107,8 @@ function Install-Alteryx { } } else { Write-Log -Type "ERROR" -Message "Path not found $ServerPath" - Write-Log -Type "ERROR" -Message "Alteryx $($InstallationProperties.Product) installation file could not be located" -ExitCode 1 + Write-Log -Type "ERROR" -Message "Alteryx $($InstallationProperties.Product) installation file could not be located" + Write-Log -Type "WARN" -Message "Alteryx installation failed" -ExitCode 1 } } # Configuration @@ -139,7 +148,8 @@ function Install-Alteryx { } } else { Write-Log -Type "ERROR" -Message "Path not found $RPath" - Write-Log -Type "ERROR" -Message "Predictive Tools installation file could not be located" -ExitCode 1 + Write-Log -Type "ERROR" -Message "Predictive Tools installation file could not be located" + Write-Log -Type "WARN" -Message "Predictive Tools installation failed" -ExitCode 1 } } } @@ -164,7 +174,8 @@ function Install-Alteryx { } } else { Write-Log -Type "ERROR" -Message "Path not found $AISPath" - Write-Log -Type "ERROR" -Message "Alteryx Intelligence Suite installation file could not be located" -ExitCode 1 + Write-Log -Type "ERROR" -Message "Intelligence Suite installation file could not be located" + Write-Log -Type "WARN" -Message "Intelligence Suite installation failed" -ExitCode 1 } } } @@ -179,7 +190,8 @@ function Install-Alteryx { $DataPackageLog = Join-Path -Path $Properties.LogDirectory -ChildPath "${ISOTimeStamp}_${DataPackage}.log" if (-Not (Test-Path -Path $DataPackagePath)) { Write-Log -Type "ERROR" -Message "Path not found $DataPackagePath" - Write-Log -Type "ERROR" -Message "Data package could not be located" -ExitCode 1 + Write-Log -Type "ERROR" -Message "Data package could not be located" + Write-Log -Type "WARN" -Message "Data package installation failed" -ExitCode 1 } # Unzip data package $Destination = $DataPackagePath.Replace('.7z', '') @@ -195,7 +207,8 @@ function Install-Alteryx { } } else { Write-Log -Type "ERROR" -Message "Path not found $($Properties.'7zipPath')" - Write-Log -Type "ERROR" -Message "7zip could not be located" -ExitCode 1 + Write-Log -Type "ERROR" -Message "7zip could not be located" + Write-Log -Type "WARN" -Message "Data package installation failed" -ExitCode 1 } # ! TODO check unzip Write-Log -Type "DEBUG" -Message $Unzip @@ -209,7 +222,8 @@ function Install-Alteryx { } } else { Write-Log -Type "ERROR" -Message "Path not found $Destination" - Write-Log -Type "ERROR" -Message "Data package unzipping failed" -ExitCode 1 + Write-Log -Type "ERROR" -Message "Data package unzipping failed" + Write-Log -Type "WARN" -Message "Data package installation failed" -ExitCode 1 } } else { Write-Log -Type "DEBUG" -Message "No data package specified" @@ -218,7 +232,11 @@ function Install-Alteryx { # ------------------------------------------------------------------------------ # Licensing # ------------------------------------------------------------------------------ - Invoke-ActivateAlteryx -Properties $Properties -Unattended:$Unattended + if ($Properties.ActivateOnInstall -eq $true) { + Invoke-ActivateAlteryx -Properties $Properties -Unattended:$Unattended + } else { + Write-Log -Type "WARN" -Message "Skipping license activation" + } } End { Write-Log -Type "CHECK" -Message "Alteryx $($InstallationProperties.Product) $($Properties.Version) installed successfully" diff --git a/powershell/Invoke-ActivateAlteryx.ps1 b/powershell/Invoke-ActivateAlteryx.ps1 index 836ffd2..ef657f1 100644 --- a/powershell/Invoke-ActivateAlteryx.ps1 +++ b/powershell/Invoke-ActivateAlteryx.ps1 @@ -16,7 +16,7 @@ function Invoke-ActivateAlteryx { File name: Invoke-ActivateAlteryx.ps1 Author: Florian Carrier Creation date: 2021-07-05 - Last modified: 2021-11-21 + Last modified: 2021-12-09 .LINK https://www.powershellgallery.com/packages/PSAYX @@ -56,9 +56,15 @@ function Invoke-ActivateAlteryx { if ((Test-HTTPStatus -URI $Properties.LicensingURL) -eq $true) { # Check license key(s) if (-Not (Find-Key -Hashtable $Properties -Key "LicenseKey")) { + # Check license file + if ($null -eq $Properties.LicenseFile -Or $Properties.LicenseFile -eq "") { + Write-Log -Type "ERROR" -Message "No license key or file have been specified" + Write-Log -Type "WARN" -Message "Alteryx product activation failed" -ExitCode 1 + } # Read keys from license file if (Test-Object -Path $Properties.LicenseFile -NotFound) { - Write-Log -Type "ERROR" -Message "License file path not found $($Properties.LicenseFile)" -ExitCode 1 + Write-Log -Type "ERROR" -Message "License file path not found $($Properties.LicenseFile)" + Write-Log -Type "WARN" -Message "Alteryx product activation failed" -ExitCode 1 } $Properties.LicenseKey = @(Get-Content -Path $Properties.LicenseFile) } @@ -66,20 +72,28 @@ function Invoke-ActivateAlteryx { if ($Properties.LicenseKey.Count -gt 1) { $Success = "$($Properties.LicenseKey.Count) licenses were successfully activated" $Failure = "Licenses could not be activated" + $Grammar = "licenses" $Properties.LicenseKey = $Properties.LicenseKey -join " " } elseif ($Properties.LicenseKey.Count -eq 1) { $Success = "$($Properties.LicenseKey.Count) license was successfully activated" $Failure = "License could not be activated" + $Grammar = "license" } else { - Write-Log -Type "ERROR" -Message "No license key was provided" -ExitCode 1 + Write-Log -Type "ERROR" -Message "No license key was provided" + Write-Log -Type "WARN" -Message "Alteryx product activation failed" -ExitCode 1 } # Check email address - if ($null -eq $Properties.LicenseEmail) { + if ($null -eq $Properties.LicenseEmail -Or $Properties.LicenseEmail -eq "") { if ($Unattended) { Write-Log -Type "ERROR" -Message "No email address provided for license activation" Write-Log -Type "WARN" -Message "Retrieving email address associated with current session through Windows Active Directory" - $Email = Get-ADUser -Identity $env:UserName -Properties "mail" | Select-Object -ExpandProperty "mail" - Write-Log -Type "DEBUG" -Message $Email + try { + $Email = Get-ADUser -Identity $env:UserName -Properties "mail" | Select-Object -ExpandProperty "mail" + Write-Log -Type "DEBUG" -Message $Email + } catch { + Write-Log -Type "ERROR" -Message $Error[0].Exception + $Email = $null + } } else { # Prompt for email address and validate format do { @@ -89,19 +103,26 @@ function Invoke-ActivateAlteryx { } else { $Email = $Properties.LicenseEmail } - # Call license utility - $Activation = Add-AlteryxLicense -Path $LicenseUtility -Key $Properties.LicenseKey -Email $Email - # Check activation status - if (Select-String -InputObject $Activation -Pattern "License(s) successfully activated." -SimpleMatch -Quiet) { - Write-Log -Type "CHECK" -Message $Success + # TODO check email format + if ($Email -as [System.Net.Mail.MailAddress]) { + # Call license utility + Write-Log -Type "INFO" -Message "Activating $Grammar" + $Activation = Add-AlteryxLicense -Path $LicenseUtility -Key $Properties.LicenseKey -Email $Email + # Check activation status + if (Select-String -InputObject $Activation -Pattern "License(s) successfully activated." -SimpleMatch -Quiet) { + Write-Log -Type "CHECK" -Message $Success + } else { + # Output error and stop script + Write-Log -Type "ERROR" -Message $Activation + Write-Log -Type "ERROR" -Message $Failure -ExitCode 1 + } } else { - # Output error and stop script - Write-Log -Type "ERROR" -Message $Activation - Write-Log -Type "ERROR" -Message $Failure -ExitCode 1 + Write-Log -Type "ERROR" -Message "Email address is missing or invalid" + Write-Log -Type "WARN" -Message "Skipping product activation" } } else { Write-Log -Type "ERROR" -Message "Unable to reach licensing system" - Write-Log -Type "WARN" -Message "Skipping license activation" + Write-Log -Type "WARN" -Message "Skipping product activation" } } } diff --git a/powershell/Invoke-DeactivateAlteryx.ps1 b/powershell/Invoke-DeactivateAlteryx.ps1 index fcd51a1..5f88d7c 100644 --- a/powershell/Invoke-DeactivateAlteryx.ps1 +++ b/powershell/Invoke-DeactivateAlteryx.ps1 @@ -16,7 +16,7 @@ function Invoke-DeactivateAlteryx { File name: Invoke-DeactivateAlteryx.ps1 Author: Florian Carrier Creation date: 2021-11-20 - Last modified: 2021-11-21 + Last modified: 2021-12-08 .LINK https://www.powershellgallery.com/packages/PSAYX @@ -73,14 +73,21 @@ function Invoke-DeactivateAlteryx { } else { # Check license key(s) if (-Not (Find-Key -Hashtable $Properties -Key "LicenseKey")) { + # Check license file + if ($null -eq $Properties.LicenseFile -Or $Properties.LicenseFile -eq "") { + Write-Log -Type "ERROR" -Message "No license key or file have been specified" + Write-Log -Type "WARN" -Message "Alteryx product deactivation failed" -ExitCode 1 + } # Read keys from license file if (Test-Object -Path $Properties.LicenseFile -NotFound) { - Write-Log -Type "ERROR" -Message "License file path not found $($Properties.LicenseFile)" -ExitCode 1 + Write-Log -Type "ERROR" -Message "License file path not found $($Properties.LicenseFile)" + Write-Log -Type "WARN" -Message "Alteryx product deactivation failed" -ExitCode 1 } $Properties.LicenseKey = @(Get-Content -Path $Properties.LicenseFile) } if ($Properties.LicenseKey.Count -eq 0) { - Write-Log -Type "ERROR" -Message "No license key was provided" -ExitCode 1 + Write-Log -Type "ERROR" -Message "No license key was provided" + Write-Log -Type "WARN" -Message "Alteryx product deactivation failed" -ExitCode 1 } # Deactivate each key $Count = 0 diff --git a/powershell/Invoke-RestoreAlteryx.ps1 b/powershell/Invoke-RestoreAlteryx.ps1 index 9b5fe13..a7a1094 100644 --- a/powershell/Invoke-RestoreAlteryx.ps1 +++ b/powershell/Invoke-RestoreAlteryx.ps1 @@ -10,7 +10,7 @@ function Invoke-RestoreAlteryx { File name: Invoke-RestoreAlteryx.ps1 Author: Florian Carrier Creation date: 2021-08-26 - Last modified: 2021-11-21 + Last modified: 2021-12-10 Comment: User configuration files are out of scope of this procedure: - %APPDATA%\Alteryx\Engine\UserConnections.xml - %APPDATA%\Alteryx\Engine\UserAlias.xml @@ -41,7 +41,6 @@ function Invoke-RestoreAlteryx { Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState # Variables $ServicePath = Join-Path -Path $Properties.InstallationPath -ChildPath "bin\AlteryxService.exe" - $TargetPath = Join-Path -Path $Properties.InstallationPath -ChildPath "Service\Persistence\MongoDB" $Staging = $false # Restore options $Restore = [Ordered]@{ @@ -120,21 +119,6 @@ function Invoke-RestoreAlteryx { } } # ---------------------------------------------------------------------------- - # Restore database - if ($Restore.Database -eq $true) { - Write-Log -Type "INFO" -Message "Restore MongoDB database from backup" - if ($PSCmdlet.ShouldProcess("MongoDB", "Restore")) { - $MongoDBPath = Join-Path -Path $BackupPath -ChildPath "MongoDB" - $DatabaseRestore = Restore-AlteryxDatabase -SourcePath $MongoDBPath -TargetPath $TargetPath -ServicePath $ServicePath - if ($DatabaseRestore -match "failed") { - Write-Log -Type "ERROR" -Message $DatabaseRestore - Write-Log -Type "ERROR" -Message "Database restore failed" -ExitCode 1 - } else { - Write-Log -Type "DEBUG" -Message $DatabaseRestore - } - } - } - # ---------------------------------------------------------------------------- # Restore configuration files if ($Restore.Configuration -eq $true) { Write-Log -Type "INFO" -Message "Restore configuration files" @@ -152,8 +136,93 @@ function Invoke-RestoreAlteryx { } } # ---------------------------------------------------------------------------- - # Set controller token + # Update configuration + Write-Log -Type "INFO" -Message "Updating configuration" + $RunTimeSettingsXML = New-Object -TypeName "System.XML.XMLDocument" + $RunTimeSettingsXML.Load($ConfigurationFiles.RunTimeSettings) + # Gallery URL + $BaseAddress = Select-XMLNode -XML $RunTimeSettingsXML -XPath "SystemSettings/Gallery/BaseAddress" + if ($BaseAddress.InnerText -match "https?://.+?/gallery") { + # Assume this is a hostname + $BaseAddressMatch = Select-String -InputObject $BaseAddress.InnerText -Pattern "https?://(.+?)/gallery" + $SourceHostname = $BaseAddressMatch.Matches.Groups[1].Value + $NewHostname = $env:ComputerName + if ($SourceHostname -ne $NewHostname) { + Write-Log -Type "INFO" -Message "Updating hostname" + # Update base Gallery URL + Write-Log -Type "DEBUG" -Message "Source=$SourceHostname" + Write-Log -Type "DEBUG" -Message "Destination=$NewHostname" + $NewBaseAddress = $BaseAddress.InnerText.Replace($SourceHostname, $NewHostname) + Write-Log -Type "DEBUG" -Message $NewBaseAddress + $BaseAddress.InnerText = $NewBaseAddress + # Update authentication URL + $ServiceProviderEntityID = Select-XMLNode -XML $RunTimeSettingsXML -XPath "SystemSettings/Authentication/ServiceProviderEntityID" + $ServiceProviderEntityID.InnerText = $ServiceProviderEntityID.InnerText.Replace($SourceHostname, $NewHostname) + } + } + # SSL + if ($Properties.EnableSSL -eq $true) { + $Protocol = "https" + $Action = "Enabling" + } else { + $Protocol = "http" + $Action = "Disabling" + } + # ! Node name is case-sensitive: SslEnabled + $SSLEnabled = Select-XMLNode -XML $RunTimeSettingsXML -XPath "SystemSettings/Gallery/SslEnabled" + if ($null -ne $SSLEnabled) { + if ($SSLEnabled.InnerText -ne $Properties.EnableSSL.ToString()) { + Write-Log -Type "INFO" -Message ($Action + " SSL") + $SSLEnabled.InnerText = $Properties.EnableSSL.ToString() + } + } else { + # If SSL configuration is not explicitly defined + if ($Properties.EnableSSL -eq $true) { + # Create SSL node + $Gallery = Select-XMLNode -XML $RunTimeSettingsXML -XPath "SystemSettings/Gallery" + $SSLEnabled = $RunTimeSettingsXML.CreateElement("SslEnabled") + $SSLEnabled.InnerText = $Properties.EnableSSL.ToString() + [Void]$Gallery.AppendChild($SSLEnabled) + } + } + if ($BaseAddress.InnerText -notmatch "^${Protocol}://") { + Write-Log -Type "INFO" -Message ($Action + " HTTPS") + $SSLAddress = $BaseAddress.InnerText -replace "^https?", "$Protocol" + Write-Log -Type "DEBUG" -Message $SSLAddress + $BaseAddress.InnerText = $SSLAddress + } + # Update configuration file + $RunTimeSettingsXML.Save($ConfigurationFiles.RunTimeSettings) + # Installation path + $WorkingPath = Select-XMLNode -XML $RunTimeSettingsXML -XPath "SystemSettings/Environment/WorkingPath" + if ($WorkingPath.InnerText -ne $Properties.InstallationPath) { + Write-Log -Type "INFO" -Message "Updating installation paths" + Write-Log -Type "DEBUG" -Message "Source=$($WorkingPath.InnerText)" + Write-Log -Type "DEBUG" -Message "Destination=$($Properties.InstallationPath)" + $RunTimeSettings = Get-Content -Path $ConfigurationFiles.RunTimeSettings + $UpdatedSettings = New-Object -TypeName "System.Collections.Arraylist" + foreach ($Property in $RunTimeSettings) { + [Void]$UpdatedSettings.Add($Property.Replace($WorkingPath.InnerText, $Properties.InstallationPath)) + } + # Overwrite source configuration + Set-Content -Path $ConfigurationFiles.RunTimeSettings -Value $UpdatedSettings + # Reload XML settings + $RunTimeSettingsXML.Load($ConfigurationFiles.RunTimeSettings) + } + # ---------------------------------------------------------------------------- + # (Re)Set controller token if ($Restore.Token -eq $true) { + Write-Log -Type "INFO" -Message "Remove encrypted controller token" + $ControllerSettingsXML = New-Object -TypeName "System.XML.XMLDocument" + $ControllerSettingsXML.Load($ConfigurationFiles.RunTimeSettings) + $ServerSecretEncrypted = Select-XMLNode -XML $ControllerSettingsXML -XPath "SystemSettings/Controller/ServerSecretEncrypted" + if ($null -ne $ServerSecretEncrypted) { + Write-Log -Type "DEBUG" -Message $ServerSecretEncrypted.InnerText + [Void]$ServerSecretEncrypted.ParentNode.RemoveChild($ServerSecretEncrypted) + $ControllerSettingsXML.Save($ConfigurationFiles.RunTimeSettings) + } else { + Write-Log -Type "WARN" -Message "Encrypted controller token could not be found" + } Write-Log -Type "INFO" -Message "Restore controller token" if ($PSCmdlet.ShouldProcess("Controller token", "Restore")) { $TokenFile = Join-Path -Path $BackupPath -ChildPath "ControllerToken.txt" @@ -164,7 +233,10 @@ function Invoke-RestoreAlteryx { Write-Log -Type "ERROR" -Message $SetToken Write-Log -Type "ERROR" -Message "Controller token update failed" } else { - Write-Log -Type "DEBUG" -Message $SetToken + # Ignore successfull empty output + if ($SetToken -ne "") { + Write-Log -Type "DEBUG" -Message $SetToken + } } } } @@ -173,11 +245,13 @@ function Invoke-RestoreAlteryx { # Set Run-As user if ($Restore.RunAsUser -eq $true) { # TODO + Write-Log -Type "WARN" -Message "Run As User restore is not currently supported" } # ---------------------------------------------------------------------------- # Set SMTP password if ($Restore.SMTPPassword -eq $true) { # TODO + Write-Log -Type "WARN" -Message "SMTP password restore is not currently supported" } # ---------------------------------------------------------------------------- # Reset storage key @@ -190,20 +264,48 @@ function Invoke-RestoreAlteryx { if ($null -ne $BackUpRunTimeSettings) { $BackupXML = New-Object -TypeName "System.XML.XMLDocument" $BackupXML.Load($BackUpRunTimeSettings.FullName) - $BackupXMLNode = Select-XMLNode -XML $BackupXML -XPath $XPath + $BackupXMLNode = Select-XMLNode -XML $BackupXML -XPath $XPath Write-Log -Type "DEBUG" -Message $BackupXMLNode.InnerText # Update configuration file - $RunTimeSettingsXML = New-Object -TypeName "System.XML.XMLDocument" - $RunTimeSettingsXML.Load($ConfigurationFiles.RunTimeSettings) - $NewXMLNode = Select-XMLNode -XML $RunTimeSettingsXML -XPath $XPath + $StorageSettingsXML = New-Object -TypeName "System.XML.XMLDocument" + $StorageSettingsXML.Load($ConfigurationFiles.RunTimeSettings) + $NewXMLNode = Select-XMLNode -XML $StorageSettingsXML -XPath $XPath $NewXMLNode.InnerText = $BackupXMLNode.InnerText - $RunTimeSettingsXML.Save($ConfigurationFiles.RunTimeSettings) + $StorageSettingsXML.Save($ConfigurationFiles.RunTimeSettings) } else { Write-Log -Type "WARN" -Message "RunTimeSettings.xml backup configuration file could not be located" } } } # ---------------------------------------------------------------------------- + # Restore database + if ($Restore.Database -eq $true) { + Write-Log -Type "INFO" -Message "Restore MongoDB database from backup" + $EmbeddedMongoDBEnabled = Select-XMLNode -XML $RunTimeSettingsXML -XPath "SystemSettings/Controller/EmbeddedMongoDBEnabled" + if ($EmbeddedMongoDBEnabled.InnerText -eq $true) { + if ($PSCmdlet.ShouldProcess("MongoDB", "Restore")) { + $EmbeddedMongoDBRootPath = Select-XMLNode -XML $RunTimeSettingsXML -XPath "SystemSettings/Controller/EmbeddedMongoDBRootPath" + if ($null -ne $EmbeddedMongoDBRootPath) { + $TargetPath = $EmbeddedMongoDBRootPath.InnerText + } else { + # Use system default + $TargetPath = Join-Path -Path $Properties.InstallationPath -ChildPath "Service\Persistence\MongoDB" + } + $MongoDBPath = Join-Path -Path $BackupPath -ChildPath "MongoDB" + $DatabaseRestore = Restore-AlteryxDatabase -SourcePath $MongoDBPath -TargetPath $TargetPath -ServicePath $ServicePath + if ($DatabaseRestore -match "failed") { + Write-Log -Type "ERROR" -Message $DatabaseRestore + Write-Log -Type "ERROR" -Message "Database restore failed" -ExitCode 1 + } else { + Write-Log -Type "DEBUG" -Message $DatabaseRestore + } + } + } else { + Write-Log -Type "ERROR" -Message "User-managed MongoDB is not supported" + Write-Log -Type "WARN" -Message "Skipping database restore" + } + } + # ---------------------------------------------------------------------------- # Remove staging folder if ($Staging -eq $true) { Write-Log -Type "INFO" -Message "Remove staging backup folder" diff --git a/powershell/Update-Alteryx.ps1 b/powershell/Update-Alteryx.ps1 index 61b399f..7a9343c 100644 --- a/powershell/Update-Alteryx.ps1 +++ b/powershell/Update-Alteryx.ps1 @@ -10,7 +10,7 @@ function Update-Alteryx { File name: Update-Alteryx.ps1 Author: Florian Carrier Creation date: 2021-09-02 - Last modified: 2021-11-22 + Last modified: 2021-12-08 #> [CmdletBinding ( SupportsShouldProcess = $true @@ -52,6 +52,8 @@ function Update-Alteryx { Write-Log -Type "DEBUG" -Object $AlteryxVersion $BackupVersion = Select-String -InputObject $AlteryxVersion -Pattern "\d+\.\d+.\d+(.\d+)?" | ForEach-Object { $PSItem.Matches.Value } } + # Set upgrade activation option + $Properties.ActivateOnInstall = $Properties.ActivateOnUpgrade } Process { Write-Log -Type "CHECK" -Object "Starting Alteryx Server upgrade from $BackupVersion to $($Properties.Version)"