Miguel
Miguel

Reputation: 53

Octopus - backup of current deployment folder

I want to make a backup of the DLL's and Web.Config's that are going to be replaced during the deployment, before they are replaced, so I can easily rollback in case the deployment fails.

People say, "Just deploy the previous version using octopus", but imagine that the octopus deployment process doesn't work well anymore, and in that case you don't have other option than replacing the old files manually from a backup zip file.

Is there any functionality in Octopus to create automatically this zip file in the tentacle?

Upvotes: 1

Views: 1404

Answers (2)

Justin Walker
Justin Walker

Reputation: 11

This is a bit old but I thought I'd add what I do in my process in octo.

I run rolling deploy with child steps.

I have a powershell step to record the previous IIS path in an output variable.

Import-Module 'WebAdministration'

Write-Host ('IIS:\Sites\Online-' + $OctopusParameters["Octopus.Environment.Name"])

$formerPath = (Get-ItemProperty -Path ('IIS:\Sites\Site-' + $OctopusParameters["Octopus.Environment.Name"]) -Name physicalPath)
if($formerPath.length -gt 0) {
    Set-OctopusVariable -Name 'FormerIISPath' -Value $formerPath
    Write-Host "Former path is '$formerPath'"
}

I then do what I need to do for my deployments and have a manual step to review each rolling deploy.

If that manual step gets cancelled I have an on fail set of child items which has the following powershell script.

$formerPath = $OctopusParameters["Octopus.Action[Set previous path].Output.FormerIISPath"]

if($formerPath.Length -gt 0) {
Import-Module 'WebAdministration'
    $currentPath = (Get-ItemProperty -Path ('IIS:\Sites\Online-' + 
    $OctopusParameters["Octopus.Environment.Name"]) -Name physicalPath)
    if($currentPath -ne $formerPath) {
         Set-ItemProperty -Path ('IIS:\Sites\Site-' + $OctopusParameters["Octopus.Environment.Name"]) -Name 'physicalPath' -Value $formerPath
         Write-Host "Deployment failed, reverted to former path - '$formerPath'"
    }
}

This will revert all the servers back to whatever they were showing before.

I want to add that I also use the default package location and never overwrite previous files. The other option is to use the REST API on octo to trigger the previous successful deployment (param is on octo) if your deployment steps are more complex but for me I want to fail back fast.

Upvotes: 1

Matt
Matt

Reputation: 3704

Rather than overwriting the previous deployed version, I would deploy a new version to a versioned directory. Octopus will be default install apps to paths like /Applications/TEST/App.Name/1.2.1/ so the next install will go to /Applications/TEST/App.Name/1.3.0/ for example. Then if you want to rollback but find your deployment process is broken you just need to repoint to the previous version. If this was a website in IIS then you'd just change the wwwroot directory - If this was a windows service you'd just install it using the old path.

Combine this with lifecycles too to ensure you keep a certain number of versions available and there's no need to write any custom custom code. I'd really avoid doing anything manual as part of your deployment, even rolling back (unzipping a previous file and copying contents etc) as this is the window of opportunity for us humans to introduce mistakes. Now imagine you have to do that over 10 servers... If you really want to have something repeatable then you could script that bit, but it would be far easier to script changing the root directory in IIS or install path for a service.

If you're deploying directly to Paas in the cloud, then maybe there's a use case for this. There's a step in the Octopus Library which could help you with this.

Hope this helps

Upvotes: 2

Related Questions