Skip to content

Commit 5325a73

Browse files
authored
[Storage] Support Planned and Unplanned failoverType in Storage account failover (#20311)
* Add Planned option for failovertype * support soft failover * support soft failover * update help
1 parent e02597a commit 5325a73

File tree

4 files changed

+112
-26
lines changed

4 files changed

+112
-26
lines changed

src/Storage/Storage.Management/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Supported Planned and Unplanned types in Storage account failover type
22+
- `Invoke-AzStorageAccountFailover`
2123
* Supported TierToCold and TierToHot in Storage account management policy
2224
- `Add-AzStorageAccountManagementPolicyAction`
2325
* Supported MaxPageSize, Include, and Filter parameters for listing encryption scopes

src/Storage/Storage.Management/StorageAccount/InvokeAzureStorageAccountFailover.cs

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ public class InvokeAzureStorageAccountFailoverCommand : StorageAccountBaseCmdlet
5959
[ValidateNotNullOrEmpty]
6060
public string Name { get; set; }
6161

62+
[Parameter(
63+
Mandatory = false,
64+
HelpMessage = "Specify the failover type. Possible values are: Unplanned, Planned. If not specified, the default failover type is Unplanned.")]
65+
[PSArgumentCompleter(AccountFailoverType.Planned,
66+
AccountFailoverType.Unplanned)]
67+
public string FailoverType { get; set; }
68+
6269
[Parameter(Mandatory = true,
6370
HelpMessage = "Storage account object",
6471
ValueFromPipeline = true,
@@ -83,30 +90,53 @@ public override void ExecuteCmdlet()
8390

8491
if (ShouldProcess(this.Name, "Invoke Failover of Storage Account"))
8592
{
86-
StringBuilder shouldContinuePrompt = new StringBuilder();
87-
shouldContinuePrompt.AppendLine("Failover the storage account, the secondary cluster will become primary after failover. Please understand the following impact to your storage account before you initiate the failover:");
88-
shouldContinuePrompt.AppendLine(" 1. Please check the Last Sync Time using Get-"+ ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "StorageAccount cmdlet with -IncludeGeoReplicationStats parameter, and check GeoReplicationStats property of your account. This is the data you may lose if you initiate the failover.");
89-
shouldContinuePrompt.AppendLine(" 2. After the failover, your storage account type will be converted to locally redundant storage (LRS). You can convert your account to use geo-redundant storage (GRS).");
90-
shouldContinuePrompt.AppendLine(" 3. Once you re-enable GRS for your storage account, Microsoft will replicate data to your new secondary region. Replication time is dependent on the amount of data to replicate. Please note that there are bandwidth charges for the bootstrap. Please refer to doc: https://azure.microsoft.com/en-us/pricing/details/bandwidth/");
91-
92-
93-
if (this.force || ShouldContinue(shouldContinuePrompt.ToString(), ""))
93+
if (ParameterSetName == AccountObjectParameterSet)
9494
{
95-
if (ParameterSetName == AccountObjectParameterSet)
95+
this.ResourceGroupName = InputObject.ResourceGroupName;
96+
this.Name = InputObject.StorageAccountName;
97+
}
98+
99+
StorageModels.FailoverType? type = null;
100+
if (!String.IsNullOrEmpty(this.FailoverType)) {
101+
if (this.FailoverType.ToLower() == AccountFailoverType.Planned.ToLower())
96102
{
97-
this.ResourceGroupName = InputObject.ResourceGroupName;
98-
this.Name = InputObject.StorageAccountName;
103+
type = StorageModels.FailoverType.Planned;
104+
}
105+
else if (this.FailoverType.ToLower() != AccountFailoverType.Unplanned.ToLower())
106+
{
107+
throw new ArgumentException(string.Format("The Failover Type {0} is invalid.", this.FailoverType), "FailoverType");
99108
}
109+
}
100110

101-
this.StorageClient.StorageAccounts.Failover(
102-
this.ResourceGroupName,
103-
this.Name);
104-
105-
var storageAccount = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name);
111+
if (type == null) {
112+
StringBuilder shouldContinuePrompt = new StringBuilder();
113+
shouldContinuePrompt.AppendLine("Failover the storage account, the secondary cluster will become primary after failover. Please understand the following impact to your storage account before you initiate the failover:");
114+
shouldContinuePrompt.AppendLine(" 1. Please check the Last Sync Time using Get-" + ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "StorageAccount cmdlet with -IncludeGeoReplicationStats parameter, and check GeoReplicationStats property of your account. This is the data you may lose if you initiate the failover.");
115+
shouldContinuePrompt.AppendLine(" 2. After the failover, your storage account type will be converted to locally redundant storage (LRS). You can convert your account to use geo-redundant storage (GRS).");
116+
shouldContinuePrompt.AppendLine(" 3. Once you re-enable GRS for your storage account, Microsoft will replicate data to your new secondary region. Replication time is dependent on the amount of data to replicate. Please note that there are bandwidth charges for the bootstrap. Please refer to doc: https://azure.microsoft.com/en-us/pricing/details/bandwidth/");
117+
118+
if (this.force || ShouldContinue(shouldContinuePrompt.ToString(), ""))
119+
{
120+
ExecuteFailover(type);
121+
}
106122

107-
WriteStorageAccount(storageAccount);
123+
} else
124+
{
125+
ExecuteFailover(type);
108126
}
109127
}
110128
}
129+
130+
private void ExecuteFailover(StorageModels.FailoverType? type = null)
131+
{
132+
this.StorageClient.StorageAccounts.Failover(
133+
this.ResourceGroupName,
134+
this.Name,
135+
type);
136+
137+
var storageAccount = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name);
138+
139+
WriteStorageAccount(storageAccount);
140+
}
111141
}
112142
}

src/Storage/Storage.Management/StorageAccount/StorageAccountBaseCmdlet.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ protected struct DefaultSharePermissionType
102102
internal const string StorageFileDataSmbShareOwner = "StorageFileDataSmbShareOwner";
103103
}
104104

105+
protected struct AccountFailoverType
106+
{
107+
internal const string Planned = "Planned";
108+
internal const string Unplanned = "Unplanned";
109+
}
110+
105111
public IStorageManagementClient StorageClient
106112
{
107113
get

src/Storage/Storage.Management/help/Invoke-AzStorageAccountFailover.md

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ Invokes failover of a Storage account.
1414

1515
### AccountName (Default)
1616
```
17-
Invoke-AzStorageAccountFailover [-ResourceGroupName] <String> [-Name] <String> [-Force] [-AsJob]
18-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
17+
Invoke-AzStorageAccountFailover [-ResourceGroupName] <String> [-Name] <String> [-FailoverType <String>]
18+
[-Force] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
1919
```
2020

2121
### AccountObject
2222
```
23-
Invoke-AzStorageAccountFailover -InputObject <PSStorageAccount> [-Force] [-AsJob]
23+
Invoke-AzStorageAccountFailover [-FailoverType <String>] -InputObject <PSStorageAccount> [-Force] [-AsJob]
2424
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2525
```
2626

@@ -34,22 +34,55 @@ Please understand the following impact to your storage account before you initia
3434

3535
## EXAMPLES
3636

37-
### Example 1: Invoke failover of a Storage account
37+
### Example 1: Invoke an unplanned failover of a Storage account
3838
<!-- Skip: Output cannot be splitted from code -->
39+
40+
3941
```
4042
PS C:\>$account = Get-AzStorageAccount -ResourceGroupName "MyResourceGroup" -Name "mystorageaccount" -IncludeGeoReplicationStats
4143
PS C:\>$account.GeoReplicationStats
4244
43-
Status LastSyncTime
44-
------ ------------
45-
Live 11/13/2018 2:44:22 AM
45+
Status LastSyncTime CanFailover
46+
------ ------------ -----------
47+
Live 11/29/2018 6:41:03 AM True
4648
4749
PS C:\>$job = Invoke-AzStorageAccountFailover -ResourceGroupName "MyResourceGroup" -Name "mystorageaccount" -Force -AsJob
4850
PS C:\>$job | Wait-Job
4951
```
5052

5153
This command check the last sync time of a Storage account then invokes failover of it, the secondary cluster will become primary after failover. Since failover takes a long time, suggest to run it in the backend with -Asjob parameter, and then wait for the job complete.
5254

55+
### Example 2: Invoke a planned failover of a Storage account
56+
<!-- Skip: Output cannot be splitted from code -->
57+
```
58+
PS C:\>$account = Get-AzStorageAccount -ResourceGroupName "MyResourceGroup" -Name "mystorageaccount" -IncludeGeoReplicationStats
59+
PS C:\>$account.GeoReplicationStats
60+
61+
Status LastSyncTime CanFailover
62+
------ ------------ -----------
63+
Live 11/29/2022 6:41:03 AM True
64+
65+
PS C:\>$job = Invoke-AzStorageAccountFailover -ResourceGroupName "MyResourceGroup" -Name "mystorageaccount" -FailoverType Planned -Force -AsJob
66+
PS C:\>$job | Wait-Job
67+
```
68+
This command check the last sync time and canFailover status of a Storage account and then invokes a planned failover of it.
69+
70+
### Example 3: Invoke an unplanned failover of a Storage account with FailoverType set to Unplanned
71+
<!-- Skip: Output cannot be splitted from code -->
72+
```
73+
PS C:\>$account = Get-AzStorageAccount -ResourceGroupName "MyResourceGroup" -Name "mystorageaccount" -IncludeGeoReplicationStats
74+
PS C:\>$account.GeoReplicationStats
75+
76+
Status LastSyncTime CanFailover
77+
------ ------------ -----------
78+
Live 11/29/2022 6:41:03 AM True
79+
80+
PS C:\>$job = Invoke-AzStorageAccountFailover -ResourceGroupName "MyResourceGroup" -Name "mystorageaccount" -FailoverType Unplanned -Force -AsJob
81+
PS C:\>$job | Wait-Job
82+
```
83+
This command check the last sync time and canFailover status of a Storage account and then invokes an unplanned failover of it.
84+
85+
5386
## PARAMETERS
5487

5588
### -AsJob
@@ -82,6 +115,21 @@ Accept pipeline input: False
82115
Accept wildcard characters: False
83116
```
84117
118+
### -FailoverType
119+
Specify the failover type. Possible values are: Unplanned, Planned. If not specified, the default failover type is Unplanned.
120+
121+
```yaml
122+
Type: System.String
123+
Parameter Sets: (All)
124+
Aliases:
125+
126+
Required: False
127+
Position: Named
128+
Default value: None
129+
Accept pipeline input: False
130+
Accept wildcard characters: False
131+
```
132+
85133
### -Force
86134
Force to Failover the Account
87135
@@ -174,11 +222,11 @@ Accept wildcard characters: False
174222
```
175223
176224
### CommonParameters
177-
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
225+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
178226
179227
## INPUTS
180228
181-
### System.String
229+
### Microsoft.Azure.Commands.Management.Storage.Models.PSStorageAccount
182230
183231
## OUTPUTS
184232

0 commit comments

Comments
 (0)