Hi @gregory.blanc,
Thanks for getting in touch.
That’s an impressive automated backup and restore setup you have going there. I think there might be an easier way to set this up though, so you get a better experience.
You could enable Maintenance mode and set all nodes to drain mode so that no tasks run on start-up in Production. This also stops tasks at the Space level as well. This would likely resolve your issue around tasks being executed on Staging.
For your issue on start-up, I would also recommend deleting your Staging instance before any restoration. We don’t store anything in registry, but we do use C:\ProgramData\Octopus\OctopusServer\Instances
. This is where previous instances will likely be getting stored and causing issues on startup.
Another approach would be to effectively automate this document on https://octopus.com/docs/administration/managing-infrastructure/moving-your-octopus/move-the-database-and-server with one additional key step. I’d put your nodes in to drain mode and maintenance mode. Drain mode means no tasks are run, including tasks such as health checks etc…
High level approach would be:
- Delete Staging Instance
- Put Octopus Production nodes into drain mode.
- Place Octopus Production mode into maintenance mode.
- Take a backup of the Production SQL Database
- Take a copy of the Octopus Config file.
- Restore the backup to the Staging SQL Database. You can do this as a new DB or overwriting the existing Database.
- Copy the Production Files (artifacts, logs and packages) to the staging location to the same location. i.e
C:\Octopus\Artifacts etc…
- Automate the installation of Octopus. Chocolatey is a good tool for this.
choco install octopusdeploy --version=INPUTREQUIREDVERSION
- Automate the installation https://octopus.com/docs/installation/automating-installation.
We have a Powershell script which helps here, which you could use and edit for your purposes. You will need to copy the config file to the new Staging Octopus server before running this script. You could do this using File System - Copy File
Community step template. Alternatively, you could copy the full Production Octopus folder using File System - Backup Directory
community step template.
param (
[Parameter(Mandatory=$true)]
[string]
$instanceName,
[Parameter(Mandatory=$true)]
[string]
$configFilePath
)
Write-Host “Setting up customer database, instance: ‘$instanceName’, configFilePath: ‘$configFilePath’”
$octopusExePath = “C:\Program Files\Octopus Deploy\Octopus\Octopus.Server.exe”
function exec
{
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=1)][scriptblock]$cmd
)
&$cmd
if ($LASTEXITCODE -ne 0)
{
Write-Error “Command returned exit code $LASTEXITCODE. Command was: $cmd”
}
}
exec { & $octopusExePath delete-instance --instance $instanceName }
exec { & $octopusExePath create-instance --instance $instanceName --config $configFilePath --nologo --console }
exec { & $octopusExePath lost-master-key --instance $instanceName --iReallyWantToResetAllMySensitiveData --upgradeDatabase --scrubPii --iHaveBackedUpMyDatabase --skipCurrentMasterKeyTest }
exec { & $octopusExePath configure --instance=$instanceName --webCorsWhitelist=* --usernamePasswordIsEnabled=true --oktaIsEnabled=false --activeDirectoryIsEnabled=false }
exec { & $octopusExePath path --instance=$instanceName --nugetRepository=./Server/Packages --artifacts=./Server/Artifacts --taskLogs=./Server/TaskLogs }
exec { & $octopusExePath admin --instance=$instanceName --username=Admin --password=Password01! }
- Start the Staging server Octopus instance. You should restore in Maintenance mode with all tasks set to drain mode meaning no tasks will run on your production Tentacles.
Please let me know what you think,
Thanks
Derek