Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepowershell
titleOctopusBackup.ps1
$DaysToStore = "-30" # Days to store backups
$OctoMigratorPath = "C:\Program Files\Octopus Deploy\Octopus\Octopus.Migrator.exe" # Path to octopus migrator tool
$Dest = "C:\Backup\srv\octopus" # Destination path for backup archives. It can be network location (\\servername\share\path)
$defaultPwd = "stR()n9p@s$w0rd" # Default password to encrypt backup

$tmp = "$env:TEMP"
$date = $(Get-Date -Format "dd-MM-yyyy-HH-mm-ss")
$CurrentDate = Get-Date
$DatetoDelete = $CurrentDate.AddDays($DaysToStore)

& "$OctoMigratorPath" export --directory="$tmp\octobak-$date" --password=$defaultPwd

# PS 5+
# Compress-Archive -Path "$tmp\octobak-$date\*" -DestinationPath "$Dest\$date.zip" -CompressionLevel Optimal

# PS 4
Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::CreateFromDirectory("$tmp\octobak-$date", "$Dest\$date.zip")

Remove-Item "$tmp\octobak-$date" -Recurse -Force
Get-ChildItem "$Dest" -Recurse | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Remove-Item

Task Sheduler

General

Image Added

Triggers - new

Image Added

Actions - new

Image Added