How to rollback quickly?

Hi guys,

I’ve encountered an issue with rollback process. For example, I have a deployment process which lasts for 30 minutes. It suits us, as we upgrade services one by one, so customers don’t notice anything. But sometimes force majeure happens and we must rollback ASAP, but there is no rollback process, there is only a deployment process, so it lasts for 30 minutes and our service is down for those 30 minutes.

I’ve found the only way to solve this issue is to create a separate deployment process, but I think it’s a bad decision as there will be duplicated process and every change should be made in two places.

So, is there a good solution for a quick rollback? Are you going to add it soon?

Thank you in advance,
Kind regards,
Denis Titusov

Hi Denis,

Thanks for getting in touch.

When Octopus installs a windows service package, it keeps a copy of the package in its cache, so when re-deploying an older version of packages it should not need to re-transfer files from the server to the Tentacle. A rollback should be faster compared to when deploying a new version of packages.

That said, if your deployment steps are failing and you need to roll back after a failed deployment, our opinions from this older blog post are still relevant today.

If your deployments are succeeding, but then you realise there’s a bug and you need to roll back to the previous version for your services, there are a couple of ways you could structure a rollback…

For example, Octopus exposes variables regarding the previous package (see Octopus.Tentacle/PreviousInstallation/PackageFilePath in the System variables documentation).

Combined with channels, you could create a Rollback channel. You could then create an equivalent rollback step for each services package in your deployment process, scope it to the Rollback channel and have it run some custom powershell script to go and find the previous installation directory and point your services to use that directory instead (all the previously installed package files should still exist at their install location on the Tentacle, so you can re-use them).

Depending on how complicated your deployment process is (and what’s taking up most of the time during your deployments), you could go in another direction and move your services into their own project, so a rollback would be faster to deploy only your services. There’s pros and cons to different approaches, so you’d need to analyse what provides the best contingency plan for you.

Hope that helps :slight_smile:

Cheers
Mark

Hi Mark,

Thank you for your suggestion. I think I could create some kind of custom Powershell script, which only purpose is to switch Windows Services/IIS sites/Scheduled Tasks to the previous version of application.

I will let you know if that helps.

Kind regards,
Denis Titusov

Hi Mark,

I’ve done a rollback step using teamcity and octupus, this might help you:

param(
[string] $IISName = $OctopusParameters[“WebsiteName”],
[string] $rollbackTag = $OctopusParameters[“Octopus.Release.Number”]
)

Import-Module ‘WebAdministration’

$livePath = Get-ItemProperty (“IIS:\Sites” + $IISName) -name physicalPath
$directoryPath = Split-Path $livePath
$rollbackPath = $directoryPath + “” + $rollbackTag + “”

Write-Host “Stop live site”
Stop-Website $IISName

Write-Host “Change live site directory to rollback tag”
Set-ItemProperty (“IIS:\Sites” + $IISName) -name physicalPath -value ($rollbackPath)

Write-Host “Start live site”
Start-Website $IISName

Write-Host “Done”

If you have any questions or feedback, just let me know.
Ale,