Deploy to a folder but leave 1 or more folders untouched

I need a very straightforward way to deploy a package to a folder – but leave 1 or more folders (and the files therein) untouched in the destination folder.

I’ve tried various types of Powershell scripts, but with mixed results.

Please advise on the best way to do this as of the current release of OD.

Hi Michael,

Thanks for getting in touch. As you might now by now, the best practice recommended by Octopus is to have packages that contain all that you need for your app to run, and deploy it in 1 go. There’s no built-in way to do partial deployments like you suggest.

My recommendation would be to script this out, if possible using robocopy as the brains for the copy process. This tiny tool is way smarter than the built-in copy-item or xcopy for these kind of scenarios where you need to cherry-pick what you want to copy. You would first deploy everything to a custom work folder and then use robocopy to copy the files from the working folder to the desired destination without overwriting your specific folders/files.


Thanks for your reply, but honestly I’m very surprised that OD can’t handle this out of the box. If I wanted to do deployments using RoboCopy or some other tool, I’d save my company’s money and not invest in OD.

But we did invest in OD (overall a great investment) and expect it to be able to handle such everyday scenarios which exist in nearly all production-type deployments, where production files exist (uploads, logs etc) that must be preserved.

Having said all that, my alternate approach is:

  1. Prior to deployment, backup (ZIP) the folder(s) that need to be preserved
  2. Deploy
  3. Restore the backed up folder(s) to their original location

We can do all this with powershell.

Please confirm the correct times to do the backup and the restore. I’m thinking “pre-deploy” and “post-deploy” – but want to be sure.

I’ve implemented the following approach using PowerShell. So far it looks like it will be quite reliable.

  1. (pre deploy script) stop website
  2. (pre deploy script) back up the folder that needs to be preserved to a ZIP file in a separate temporary folder (using System.IO.Compression.ZipFile)
  3. OD - purge deploy directory
  4. OD - copy package to deploy directory
  5. (post deploy script) restore folder that needs to be preserved back to its original location
  6. (post deploy script) start website