Azure - Copy Storage Account Containers AZCopy Inline

Octopus.Script exported 2016-07-24 by ahmedig belongs to ‘Azure’ category.

Copies Storage Account containers, from a source storage account to destination. It copies the containers with the same names.

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

Source Storage Account Name

SourceStorageAccountName

Storage Account Name of the source storage account

Source Storage Account Key

SourceStorageAccountKey

Storage Account Key of the source storage account

Destination Storage Account Name

DestinationStorageAccountName

Storage Account Name of the destination storage account

Destination Storage Account Key

DestinationStorageAccountKey

Storage Account key of the destination storage account

Containers Included

ContainersIncluded

A comma separated list of containers that will be copied only, and all the rest will be excluded. If this value is filled with a value, the “Containers Excluded” value will be neglected.

Containers Excluded

ContainersExcluded

A comma separated list of containers that will be excluded. All containers in source storage account will be copied to destination except these containers. Please note that if the “Containers Included” has a value, the “Containers Excluded” will be neglected.

Script body

Steps based on this template will execute the following PowerShell script.

$SourceStorageAccountName = $OctopusParameters['SourceStorageAccountName'];
$SourceStorageAccountKey = $OctopusParameters['SourceStorageAccountKey'];
$DestinationStorageAccountName = $OctopusParameters['DestinationStorageAccountName'];
$DestinationStorageAccountKey = $OctopusParameters['DestinationStorageAccountKey'];
$ContainersIncluded = $OctopusParameters['ContainersIncluded'];
$ContainersExcluded = $OctopusParameters['ContainersExcluded'];

$AzCopy = Join-Path ${env:ProgramFiles(x86)} "Microsoft SDKs\Azure\AzCopy\AzCopy.exe"

function AzCopyContainer($containerName)
{
    &$AzCopy /Source:http://$($SourceStorageAccountName).blob.core.windows.net/$containerName `
	/Dest:http://$($DestinationStorageAccountName).blob.core.windows.net/$containerName `
	/SourceKey:$SourceStorageAccountKey `
	/DestKey:$DestinationStorageAccountKey `
	/S /XO /XN /V | Out-Host
}

# List all Containers
$ctx = New-AzureStorageContext -StorageAccountName $SourceStorageAccountName -StorageAccountKey $SourceStorageAccountKey
$containers = Get-AzureStorageContainer -Context $ctx

	
# If Containers Included is there  => Copy Included Only 
if($ContainersIncluded)
{
	# Parse the Included list
	$ContainersIncluded.Split(",") | foreach {
		AzCopyContainer $_
	}
}

# If Containers Excluded is there, and no Included => Copy all except excluded
elseif(!$ContainersIncluded -and $ContainersExcluded)
{
	#Parse the exclusion list
	[Collections.Generic.List[String]]$lst = $ContainersExcluded.Split(",")

	# Loop through all the containers, and
	foreach ($container in $containers) 
	{
		if($lst.Contains($container.Name)) {
			continue
		}
		else 
		{
			$containerName = $container.Name
            AzCopyContainer $containerName
		}
	} 
}

# Copy all containers
else
{
	# Loop through all the containers, and
	foreach ($container in $containers) 
	{
		$containerName = $container.Name
        AzCopyContainer $containerName
	} 
}

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "24ab7967-8ae5-4852-bfdf-4e81d57245f6",
  "Name": "Azure - Copy Storage Account Containers AZCopy Inline",
  "Description": "Copies Storage Account containers, from a source storage account to destination. It copies the containers with the same names.",
  "Version": 2,
  "ExportedAt": "2016-07-24T12:55:38.909+00:00",
  "ActionType": "Octopus.Script",
  "Author": "ahmedig",
  "Parameters": [
    {
      "Name": "SourceStorageAccountName",
      "Label": "Source Storage Account Name",
      "HelpText": "Storage Account Name of the source storage account",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "SourceStorageAccountKey",
      "Label": "Source Storage Account Key",
      "HelpText": "Storage Account Key of the source storage account",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "DestinationStorageAccountName",
      "Label": "Destination Storage Account Name",
      "HelpText": "Storage Account Name of the destination storage account",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "DestinationStorageAccountKey",
      "Label": "Destination Storage Account Key",
      "HelpText": "Storage Account key of the destination storage account",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "ContainersIncluded",
      "Label": "Containers Included",
      "HelpText": "A comma separated list of containers that will be copied only, and all the rest will be excluded. If this value is filled with a value, the \"Containers Excluded\" value will be neglected.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "ContainersExcluded",
      "Label": "Containers Excluded",
      "HelpText": "A comma separated list of containers that will be excluded. All containers in source storage account will be copied to destination except these containers. Please note that if the \"Containers Included\" has a value, the \"Containers Excluded\" will be neglected.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptBody": "$SourceStorageAccountName = $OctopusParameters['SourceStorageAccountName'];\n$SourceStorageAccountKey = $OctopusParameters['SourceStorageAccountKey'];\n$DestinationStorageAccountName = $OctopusParameters['DestinationStorageAccountName'];\n$DestinationStorageAccountKey = $OctopusParameters['DestinationStorageAccountKey'];\n$ContainersIncluded = $OctopusParameters['ContainersIncluded'];\n$ContainersExcluded = $OctopusParameters['ContainersExcluded'];\n\n$AzCopy = Join-Path ${env:ProgramFiles(x86)} \"Microsoft SDKs\\Azure\\AzCopy\\AzCopy.exe\"\n\nfunction AzCopyContainer($containerName)\n{\n    &$AzCopy /Source:http://$($SourceStorageAccountName).blob.core.windows.net/$containerName `\n\t/Dest:http://$($DestinationStorageAccountName).blob.core.windows.net/$containerName `\n\t/SourceKey:$SourceStorageAccountKey `\n\t/DestKey:$DestinationStorageAccountKey `\n\t/S /XO /XN /V | Out-Host\n}\n\n# List all Containers\n$ctx = New-AzureStorageContext -StorageAccountName $SourceStorageAccountName -StorageAccountKey $SourceStorageAccountKey\n$containers = Get-AzureStorageContainer -Context $ctx\n\n\t\n# If Containers Included is there  => Copy Included Only \nif($ContainersIncluded)\n{\n\t# Parse the Included list\n\t$ContainersIncluded.Split(\",\") | foreach {\n\t\tAzCopyContainer $_\n\t}\n}\n\n# If Containers Excluded is there, and no Included => Copy all except excluded\nelseif(!$ContainersIncluded -and $ContainersExcluded)\n{\n\t#Parse the exclusion list\n\t[Collections.Generic.List[String]]$lst = $ContainersExcluded.Split(\",\")\n\n\t# Loop through all the containers, and\n\tforeach ($container in $containers) \n\t{\n\t\tif($lst.Contains($container.Name)) {\n\t\t\tcontinue\n\t\t}\n\t\telse \n\t\t{\n\t\t\t$containerName = $container.Name\n            AzCopyContainer $containerName\n\t\t}\n\t} \n}\n\n# Copy all containers\nelse\n{\n\t# Loop through all the containers, and\n\tforeach ($container in $containers) \n\t{\n\t\t$containerName = $container.Name\n        AzCopyContainer $containerName\n\t} \n}",
    "Octopus.Action.Script.ScriptFileName": null,
    "Octopus.Action.Package.NuGetFeedId": null,
    "Octopus.Action.Package.NuGetPackageId": null
  },
  "Category": "Azure",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/Azure-CopySelectiveStorageAccountContainersUsingAZCopy.json",
  "Website": "/step-templates/24ab7967-8ae5-4852-bfdf-4e81d57245f6",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////AHjXf7vrv931QJrh7/f8EIDaIIncMJHfYKvmz+b3n8zw3+76j8Ttr9XycLPpUKLkkKvYFAAABGZJREFUeNrsnNmCqjoQRc1MEiD8/9cer7Yt2KBJZQC8ez07sKlKTQlcLgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzoUSnt8YxXlFuGHSbIaxvj+fip4btkLn1blkWLaF5v03yLhLOYlVuGYfMOMZzNGxCOzhjTJqFkXnjq3Dr1yyvPI3hGl3Ih3zzHHNKudRstRhX5O58vIcShY67Gq6EPIESlzUWvazaGAOGbvU7ArDu/g8M4o8opDZWvbvPzlL/MMBE8jT9T9W7PbAJlHPTBFRf9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