-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwitchCloudTenantsQuotasRepository.ps1
More file actions
184 lines (141 loc) · 6.08 KB
/
SwitchCloudTenantsQuotasRepository.ps1
File metadata and controls
184 lines (141 loc) · 6.08 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
##################################################################
# User Defined Variables
##################################################################
# Names of tenant accounts separated by comma (Mandatory)
# For instance, $TenantsForMigration = @("Tenant1", "Tenant2")
#
# Requirements:
# Tenants running Veeam Backup and Replication version older than 9.5 are not supported for migration
# Tenants with special characters in their names are not supported for migration
$TenantsForMigration = @(
""
)
# Name of Scale-Out Backup Repository tenants backups should be migrated to
# For instance, $ScaleOutRepositoryName = "sobr"
# Requirements:
# Extents cannot be in maintenance mode
$ScaleOutRepositoryName = ""
##################################################################
# End User Defined Variables
##################################################################
#################### DO NOT MODIFY PAST THIS LINE ################
add-pssnapin veeampssnapin
function SwitchVBRCloudTenantsQuotasRepository()
{
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[Veeam.Backup.PowerShell.Infos.VBRCloudTenant[]] $Tenants,
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[Veeam.Backup.PowerShell.Infos.VBRScaleOutBackupRepository] $Repository = $(throw "Scale Out Backup Repository required.")
)
Write-Output "Validating tenants and target repository"
$validationResult = Validate-VBRCloudTenantQuota -Tenants $tenants -ScaleOutBackupRepository $Repository
if ($validationResult.ValidTenants.Length -ne 0)
{
Write-Output "Valid tenants:"
foreach($tenant in $validationResult.ValidTenants)
{
Write-Output $tenant.Name
}
Write-Output ""
}
if ($validationResult.HasErrors)
{
if ($validationResult.RepositoryErrors.Length -ne 0)
{
Write-Warning "Repository errors:"
foreach($error in $validationResult.RepositoryErrors)
{
Write-Output $error
}
Write-Output ""
}
if ($validationResult.TenantsErrors.Length -ne 0)
{
Write-Warning "Tenants errors:"
foreach($tenantErrors in $validationResult.TenantsErrors.GetEnumerator())
{
$tenantName = $tenantErrors.Key.Name
Write-Output "$tenantName"
foreach($error in $tenantErrors.Value)
{
Write-Output " $error"
}
Write-Output ""
}
}
#In case of one or multiple failures additional confirmation dialog box is shown
$title = "Tenant backups' migration"
$message = "Start migration process?"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Yes"
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "No"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
}
if ($validationResult.ValidTenants.Length -ne 0)
{
if($result -ne 1)
{
Write-Output "Tenants were validated. Starting migration process..."
$switchingResult = Switch-VBRCloudTenantQuotaRepository -Tenants $validationResult.ValidTenants -ScaleOutBackupRepository $Repository -WaitRescan
if ($switchingResult.ProcessedTenants.Length -ne 0)
{
Write-Output "The following tenants were processed:"
foreach($tenant in $switchingResult.ProcessedTenants)
{
Write-Output $tenant.Name
}
Write-Output ""
}
if ($switchingResult.TenantsWithErrors.Length -ne 0)
{
Write-Warning "The following tenants had one or several issues associated with them and were skipped from processing:"
foreach($tenant in $switchingResult.TenantsWithErrors)
{
Write-Output $tenant.Name
}
Write-Output ""
}
if ($switchingResult.StoragesErrors.Length -ne 0)
{
Write-Warning "Could not find the following storages:"
foreach($storageError in $switchingResult.StoragesErrors)
{
Write-Output $tenant.Name
}
Write-Output ""
}
Write-Warning "Do not rescan old repository that hosted tenants' backup and backup metadata files, before you remove from it tenants' backup and backup metadata files that were migrated to the Scale-Out Repository. Otherwise, multiple issues are expected."
}
else
{
break;
}
}
else
{
Write-Warning "No valid tenants to update."
}
Write-Output "Finish."
}
##########
Write-Output "Loading tenants list"
$tenants = Get-VBRCloudTenant -Name $TenantsForMigration -ErrorVariable TenantsErrors -ErrorAction SilentlyContinue
if($TenantsErrors)
{
"$($TenantsErrors.Count) errors encountered:"
foreach ($e in $TenantsErrors.GetEnumerator())
{
$e.Exception # errors list
}
}
$sobr = Get-VBRBackupRepository -Name $ScaleOutRepositoryName -ScaleOut
if ($sobr.Count -eq 0){
$RepositoryErrors = 1
Write-Output "Failed to find repository: $ScaleOutRepositoryName"
}
if ($TenantsErrors.Count + $RepositoryErrors -eq 0)
{
SwitchVBRCloudTenantsQuotasRepository $tenants $sobr
}