Octopus.Script exported 2016-08-25 by bobjwalker belongs to ‘File System’ category.
Uses Robocopy to backup directories and files from a source to a destination.
Parameters
When steps based on the template are included in a project’s deployment process, the parameters below can be set.
Source
BackupSource
The source directory where files and folders will be copied from
Destination folder
BackupDestination
The Destination where the files will be copied to.
Robocopy options
Options = /E /V
Robocopy accepts a few command line options (e.g. /S /E /Z). List of these can be found here
Create stamped backup folder
CreateStampedBackupFolder = True
If set to True then it will create a dated backup folder under the destination folder (e.g. c:\backup\2014-05-11)
Script body
Steps based on this template will execute the following PowerShell script.
function Get-Stamped-Destination($BackupDestination) {
$stampedFolderName = get-date -format "yyyy-MM-dd"
$count = 1
$stampedDestination = Join-Path $BackupDestination $stampedFolderName
while(Test-Path $stampedDestination) {
$count++
$stamped = $stampedFolderName + "(" + $count + ")"
$stampedDestination = Join-Path $BackupDestination $stamped
}
return $stampedDestination
}
$BackupSource = $OctopusParameters['BackupSource']
$BackupDestination = $OctopusParameters['BackupDestination']
$CreateStampedBackupFolder = $OctopusParameters['CreateStampedBackupFolder']
if($CreateStampedBackupFolder -like "True" ) {
$BackupDestination = get-stamped-destination $BackupDestination
}
$options = $OctopusParameters['Options'] -split "\s+"
if(Test-Path -Path $BackupSource) {
robocopy $BackupSource $BackupDestination $options
}
if($LastExitCode -gt 8) {
exit 1
}
else {
exit 0
}
Provided under the Apache License version 2.0.
To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.
{
"Id": "0acca3d2-7afa-4c51-963e-6f204b009f85",
"Name": "File System - Backup Directory",
"Description": "Uses Robocopy to backup directories and files from a source to a destination.",
"Version": 4,
"ExportedAt": "2016-08-25T15:50:24.584+00:00",
"ActionType": "Octopus.Script",
"Author": "bobjwalker",
"Parameters": [
{
"Name": "BackupSource",
"Label": "Source",
"HelpText": "The source directory where files and folders will be copied from",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "BackupDestination",
"Label": "Destination folder",
"HelpText": "The Destination where the files will be copied to.",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "Options",
"Label": "Robocopy options",
"HelpText": "Robocopy accepts a few command line options (e.g. /S /E /Z). List of these can be [found here](http://ss64.com/nt/robocopy.html)",
"DefaultValue": "/E /V",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "CreateStampedBackupFolder",
"Label": "Create stamped backup folder",
"HelpText": "If set to _True_ then it will create a dated backup folder under the destination folder (e.g. c:\\backup\\2014-05-11)",
"DefaultValue": "True",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
}
],
"Properties": {
"Octopus.Action.Script.ScriptBody": "function Get-Stamped-Destination($BackupDestination) {\n\t$stampedFolderName = get-date -format \"yyyy-MM-dd\"\n\t$count = 1\n\t$stampedDestination = Join-Path $BackupDestination $stampedFolderName\n\twhile(Test-Path $stampedDestination) {\n\t\t$count++\n\t\t$stamped = $stampedFolderName + \"(\" + $count + \")\"\n\t\t$stampedDestination = Join-Path $BackupDestination $stamped\n\t}\n\treturn $stampedDestination\n}\n\n$BackupSource = $OctopusParameters['BackupSource']\n$BackupDestination = $OctopusParameters['BackupDestination']\n$CreateStampedBackupFolder = $OctopusParameters['CreateStampedBackupFolder']\nif($CreateStampedBackupFolder -like \"True\" ) {\n\t$BackupDestination = get-stamped-destination $BackupDestination\n}\n\n$options = $OctopusParameters['Options'] -split \"\\s+\"\n\nif(Test-Path -Path $BackupSource) {\n robocopy $BackupSource $BackupDestination $options\n}\n\nif($LastExitCode -gt 8) {\n exit 1\n}\nelse {\n exit 0\n}\n",
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.Script.ScriptFileName": null,
"Octopus.Action.Package.NuGetFeedId": null,
"Octopus.Action.Package.NuGetPackageId": null
},
"Category": "File System",
"HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/file-system-backup-directory.json",
"Website": "/step-templates/0acca3d2-7afa-4c51-963e-6f204b009f85",
"Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAKhQTFRF/////78A/6oAVVVV/++//+q/gICA1dXV/79A/9R///ff/8MQ/9dg/8cg//vv/68A/+ef//PP//rv/7Ug/68Q/+Sv/8sw/9tw/9NQ/89w/+uv/+OP/8pg/89A/8VQ/9+f/9+A/9qP/+/P/99//7cA/7IA/7wA/6sA/+/A39/f/64A2tjX//Tfn5+f/7MA/7sA/74A/60A/9Zw/7gA/74Q/7oA/7UA/7EAi6g4fwAAAuRJREFUeNrs21tT2mAUheEvaaCQQCSczyi29WzP7f//Z6UdZBIIM44us9hf13vbC+eRbLo3qnNKKaWUUkoppZRSSimllFJKKaWUwlVrLhsvbrLqnoai2+yFr2x+fwKOwasZm/oXdEczxDQnOyYhqgn3uQpxDZhz3gdCesQ3r3mIjDfwXagj7NEgKywkXLMgSzCE9mz1wBDaOzDYETYEEUSQ/wPSaz6rQa174pDnt1x5Atm8emtPIGG48gUClJAh/XtPILi36+L3Zz6oVdBF4w32/sIbYmWH6qAPX5fzjio/14Q/W7nnqtIPDnYfFfThkGpPovXu68IhNdKSVyXkoQ7qgQypvwNVFwQDuXkP6oYM8WbYBWFDYMPNHnZBTv3tV8MuiCC+Q6K36+ypkn/LsJC4lQSkhhkQch4Qa+MgrYBahIKcB35AYrIjyEAQ9gsCm5E2GTIDQabsJysFQcZkxxj0H2LKfkGmIMjM3KgfgbBHfQSCROwnKwZByNtJsACt8WlChnRAkA7ZkaAOqyEZ0gJB7O2LRyAjsmOIutlNjnoJhD3qL9gXyyFjk6N+CKGPegSC2DsNj0DY++IlCEI/DWMQhL0vjh0GYvE0LIWwT8PEgSDsfXEEgmRmR30PYvI0LIGkRvfFAwj9NExBkIXRfXEfYvQ0PISwT8O2A0HYoz4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