10
10
# pylint: disable=broad-except
11
11
# pylint: disable=too-many-locals
12
12
# pylint: disable=too-many-statements
13
+ # pylint: disable=too-many-branches
13
14
14
15
from knack .log import get_logger
15
16
21
22
AzureWorkloadSQLPointInTimeRestoreRequest , AzureWorkloadSAPAsePointInTimeRestoreRequest , \
22
23
AzureVmWorkloadSAPHanaDatabaseProtectedItem , AzureVmWorkloadSQLDatabaseProtectedItem , \
23
24
RecoveryPointRehydrationInfo , AzureWorkloadSAPHanaRestoreWithRehydrateRequest , \
24
- AzureWorkloadSQLRestoreWithRehydrateRequest , ProtectionState , AzureVmWorkloadSAPAseDatabaseProtectedItem , \
25
- MoveRPAcrossTiersRequest \
25
+ AzureWorkloadSQLRestoreWithRehydrateRequest , ProtectionState , SnapshotRestoreParameters , \
26
+ UserAssignedManagedIdentityDetails , UserAssignedIdentityProperties , \
27
+ AzureVmWorkloadSAPAseDatabaseProtectedItem , MoveRPAcrossTiersRequest
26
28
27
29
from azure .mgmt .recoveryservicesbackup .passivestamp .models import CrossRegionRestoreRequest
28
30
41
43
42
44
from azure .mgmt .recoveryservicesbackup .activestamp import RecoveryServicesBackupClient
43
45
from azure .cli .core .commands .client_factory import get_mgmt_service_client
46
+ from azure .cli .core .profiles import ResourceType
44
47
45
48
46
49
fabric_name = "Azure"
51
54
'SAPHANA' : 'SAPHanaDatabase' ,
52
55
'SQLDataBase' : 'SQLDataBase' ,
53
56
'SAPHanaDatabase' : 'SAPHanaDatabase' ,
57
+ 'SAPHanaDBInstance' : 'SAPHanaDBInstance' ,
54
58
'SAPASE' : 'SAPAseDatabase' ,
55
59
'SAPAseDatabase' : 'SAPAseDatabase' }
56
60
70
74
'HANAInstance' : 'SAPHanaSystem' ,
71
75
'SAPHanaSystem' : 'SAPHanaSystem' ,
72
76
'SQLInstance' : 'SQLInstance' ,
77
+ 'SAPHanaDBInstance' : 'SAPHanaDBInstance' ,
73
78
'SQLAG' : 'SQLAvailabilityGroupContainer' ,
74
79
'SAPASE' : 'SAPAseDatabase' ,
75
80
'SAPAseDatabase' : 'SAPAseDatabase' }
@@ -441,12 +446,12 @@ def enable_protection_for_azure_wl(cmd, client, resource_group_name, vault_name,
441
446
# Get protectable item.
442
447
protectable_item_object = protectable_item
443
448
protectable_item_type = protectable_item_object .properties .protectable_item_type
444
- if protectable_item_type .lower () not in ["sqldatabase" , "sqlinstance" , "saphanadatabase" , "saphanasystem" ,
445
- "sapasedatabase" ]:
449
+ if protectable_item_type .lower () not in ["sqldatabase" , "sqlinstance" , "saphanadatabase" ,
450
+ "saphanasystem" , "saphanadbinstance" , " sapasedatabase" ]:
446
451
raise CLIError (
447
452
"""
448
- Protectable Item must be either of type SQLDataBase, HANADatabase, HANAInstance, SAPAseDatabase or
449
- SQLInstance.
453
+ Protectable Item must be of type SQLDataBase, HANADatabase, HANAInstance,
454
+ SAPAseDatabase, SAPHanaDBInstance, or SQLInstance.
450
455
""" )
451
456
452
457
item_name = protectable_item_object .name
@@ -659,6 +664,9 @@ def restore_azure_wl(cmd, client, resource_group_name, vault_name, recovery_conf
659
664
alternate_directory_paths = recovery_config_object ['alternate_directory_paths' ]
660
665
recovery_mode = recovery_config_object ['recovery_mode' ]
661
666
filepath = recovery_config_object ['filepath' ]
667
+ attach_and_mount = recovery_config_object ['attach_and_mount' ]
668
+ identity_arm_id = recovery_config_object ['identity_arm_id' ]
669
+ snapshot_instance_resource_group = recovery_config_object ['snapshot_instance_resource_group' ]
662
670
663
671
item = common .show_item (cmd , backup_protected_items_cf (cmd .cli_ctx ), resource_group_name , vault_name ,
664
672
container_uri , item_uri , "AzureWorkload" )
@@ -734,6 +742,42 @@ def restore_azure_wl(cmd, client, resource_group_name, vault_name, recovery_conf
734
742
setattr (trigger_restore_properties , 'should_use_alternate_target_location' , True )
735
743
setattr (trigger_restore_properties , 'is_non_recoverable' , False )
736
744
745
+ if recovery_mode == 'SnapshotAttachAndRecover' or recovery_mode == 'SnapshotAttach' :
746
+ trigger_restore_properties .recovery_mode = recovery_mode
747
+ if snapshot_instance_resource_group is None :
748
+ target_resource_group_name = container_id .split ('/' )[4 ]
749
+ else :
750
+ target_resource_group_name = snapshot_instance_resource_group
751
+
752
+ # For SnapshotAttach (--attach-and-mount was not provided), skip_attach_and_mount should be False
753
+ skip_attach_and_mount = False
754
+ if recovery_mode == 'SnapshotAttachAndMount' :
755
+ skip_attach_and_mount = not attach_and_mount
756
+
757
+ snapshot_restore_parameters = SnapshotRestoreParameters (skip_attach_and_mount = skip_attach_and_mount ,
758
+ log_point_in_time_for_db_recovery = '' )
759
+
760
+ # Fetching UAMI details
761
+ rg_name = identity_arm_id .split ('/' )[- 5 ]
762
+ id_name = identity_arm_id .split ('/' )[- 1 ]
763
+ sub_name = identity_arm_id .split ('/' )[- 7 ]
764
+ identity_client = get_mgmt_service_client (cmd .cli_ctx , ResourceType .MGMT_MSI ,
765
+ subscription_id = sub_name ).user_assigned_identities
766
+ identity_details = identity_client .get (resource_group_name = rg_name , resource_name = id_name )
767
+ user_assigned_identity_properties = UserAssignedIdentityProperties (
768
+ client_id = identity_details .client_id ,
769
+ principal_id = identity_details .principal_id
770
+ )
771
+ user_assigned_managed_identity_details = UserAssignedManagedIdentityDetails (
772
+ identity_arm_id = identity_arm_id ,
773
+ user_assigned_identity_properties = user_assigned_identity_properties
774
+ )
775
+
776
+ setattr (trigger_restore_properties , 'snapshot_restore_parameters' , snapshot_restore_parameters )
777
+ setattr (trigger_restore_properties , 'target_resource_group_name' , target_resource_group_name )
778
+ setattr (trigger_restore_properties , 'user_assigned_managed_identity_details' ,
779
+ user_assigned_managed_identity_details )
780
+
737
781
trigger_restore_request = RestoreRequestResource (properties = trigger_restore_properties )
738
782
739
783
if use_secondary_region :
@@ -774,18 +818,19 @@ def restore_azure_wl(cmd, client, resource_group_name, vault_name, recovery_conf
774
818
775
819
def show_recovery_config (cmd , client , resource_group_name , vault_name , restore_mode , container_name , item_name ,
776
820
rp_name , target_item , target_item_name , log_point_in_time , from_full_rp_name ,
777
- filepath , target_container , target_resource_group , target_vault_name , target_subscription ):
821
+ filepath , target_container , target_resource_group , target_vault_name , target_subscription ,
822
+ workload_type , attach_and_mount , identity_arm_id , snapshot_instance_resource_group ):
778
823
if log_point_in_time is not None :
779
824
datetime_type (log_point_in_time )
780
825
781
826
if restore_mode == 'AlternateWorkloadRestore' :
782
827
_check_none_and_many (target_item , "Target Item" )
783
828
784
829
protectable_item_type = target_item .properties .protectable_item_type
785
- if protectable_item_type .lower () not in ["sqlinstance" , "saphanasystem" ]:
830
+ if protectable_item_type .lower () not in ["sqlinstance" , "saphanasystem" , "saphanadbinstance" ]:
786
831
raise CLIError (
787
832
"""
788
- Target Item must be either of type HANAInstance or SQLInstance .
833
+ Target Item must be of type HANAInstance, SQLInstance, or SAPHanaDBInstance .
789
834
""" )
790
835
791
836
if restore_mode == 'RestoreAsFiles' and target_container is None :
@@ -862,6 +907,11 @@ def show_recovery_config(cmd, client, resource_group_name, vault_name, restore_m
862
907
if restore_mode == 'RestoreAsFiles' :
863
908
recovery_mode = 'FileRecovery'
864
909
container_id = target_container .id
910
+ if workload_type == 'SAPHanaDBInstance' :
911
+ if attach_and_mount is not None :
912
+ recovery_mode = 'SnapshotAttachAndRecover'
913
+ else :
914
+ recovery_mode = 'SnapshotAttach'
865
915
866
916
return {
867
917
'restore_mode' : restore_mode_map [restore_mode ],
@@ -876,7 +926,10 @@ def show_recovery_config(cmd, client, resource_group_name, vault_name, restore_m
876
926
'container_id' : container_id ,
877
927
'recovery_mode' : recovery_mode ,
878
928
'filepath' : filepath ,
879
- 'alternate_directory_paths' : alternate_directory_paths }
929
+ 'alternate_directory_paths' : alternate_directory_paths ,
930
+ 'attach_and_mount' : attach_and_mount ,
931
+ 'identity_arm_id' : identity_arm_id ,
932
+ 'snapshot_instance_resource_group' : snapshot_instance_resource_group }
880
933
881
934
882
935
def _fetch_nodes_list_and_auto_protection_policy (cmd , paged_items , resource_group_name , vault_name ,
0 commit comments