-
Notifications
You must be signed in to change notification settings - Fork 507
Expand file tree
/
Copy pathAzure-Container-Copy-to-another-Container.json.human
More file actions
141 lines (137 loc) · 4.75 KB
/
Azure-Container-Copy-to-another-Container.json.human
File metadata and controls
141 lines (137 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
{
"Id": "bf955a12-57ee-41b0-af58-672ca48ea07d",
"Name": "Azure - Copy Storage Account Containers",
"Description": "Copy blobs between specified containers across two different storage accounts",
"ActionType": "Octopus.Script",
"Version": 1,
"Properties": {
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.Script.ScriptBody": "# Define the source storage account and context
$SourceStorageAccountName = $OctopusParameters['SourceStorageAccountName'];
$SourceStorageAccountKey = $OctopusParameters['SourceStorageAccountKey'];
$SourceContainerName = $OctopusParameters['SourceContainerName'];
$SourceContext = New-AzureStorageContext -StorageAccountName $SourceStorageAccountName -StorageAccountKey $SourceStorageAccountKey
$SourceBlobPrefix = $OctopusParameters['SourceBlobPrefix'];
# Define the destination storage account and context
$DestinationStorageAccountName = $OctopusParameters['DestinationStorageAccountName'];
$DestinationStorageAccountKey = $OctopusParameters['DestinationStorageAccountKey'];
$DestinationContainerName = $OctopusParameters['DestinationContainerName'];
$DestinationContext = New-AzureStorageContext -StorageAccountName $DestinationStorageAccountName -StorageAccountKey $DestinationStorageAccountKey
$DestinationBlobPrefix = $OctopusParameters['DestinationBlobPrefix'];
# Check if container exists, otherwise create it
$isContainerExist = Get-AzureStorageContainer -Context $DestinationContext | Where-Object { $_.Name -eq $DestinationContainerName }
if($isContainerExist -eq $null)
{
New-AzureStorageContainer -Name $DestinationContainerName -Context $DestinationContext
}
# Get a reference to blobs in the source container
$blobs = $null
if ($SourceBlobPrefix -eq $null) {
$blobs = Get-AzureStorageBlob -Container $SourceContainerName -Context $SourceContext
}
else {
$blobs = Get-AzureStorageBlob -Container $SourceContainerName -Context $SourceContext -Prefix $SourceBlobPrefix
}
# Copy blobs from one container to another
if ($DestinationBlobPrefix -eq $null) {
\t$blobs | Start-AzureStorageBlobCopy -DestContainer $DestinationContainerName -DestContext $DestinationContext
}
else {
\t$uri = $SourceContext.BlobEndPoint + $SourceContainerName +\"/\"
\t$blobs | ForEach-Object `
\t{ Start-AzureStorageBlobCopy `
\t -SrcUri \"$uri$($_.Name)\" `
-Context $SourceContext `
\t -DestContext $DestinationContext `
\t -DestContainer $DestinationContainerName `
\t -DestBlob \"$DestinationBlobPrefix/$($_.Name)\" `
\t }
}
",
"Octopus.Action.Script.ScriptFileName": null,
"Octopus.Action.Package.NuGetFeedId": null,
"Octopus.Action.Package.NuGetPackageId": null
},
"Parameters": [
{
"Name": "SourceStorageAccountName",
"Label": "Source Storage Account Name",
"HelpText": null,
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "SourceStorageAccountKey",
"Label": "Source Storage Account Key",
"HelpText": null,
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "SourceContainerName",
"Label": "Source Container Name",
"HelpText": null,
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "SourceBlobPrefix",
"Label": "Source Blob Prefix (Optional)",
"HelpText": null,
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "DestinationStorageAccountName",
"Label": "Destination Storage Account Name",
"HelpText": null,
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "DestinationStorageAccountKey",
"Label": "Destination Storage Account Key",
"HelpText": null,
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "DestinationContainerName",
"Label": "Destination Container Name",
"HelpText": null,
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "DestinationBlobPrefix",
"Label": "Destination Blob Prefix (Optional)",
"HelpText": null,
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
}
],
"LastModifiedBy": "ahmedig",
"$Meta": {
"ExportedAt": "2016-05-12T03:09:48.287+00:00",
"OctopusVersion": "3.3.9",
"Type": "ActionTemplate"
},
"Category": "azure"
}