Azure-sdk-for-python: How to create a azure vm backup via python sdk . Steps needed please with example

Created on 4 Aug 2020  路  58Comments  路  Source: Azure/azure-sdk-for-python

  • Operating System: Linux
  • Python Version: 3.6

Describe the bug
Not able to create a backup of azure vm via python sdk,. Need clear cut example if you have one.. Thank you
Can you please give some documentation with example how to do create given vm backup via python sdk please

Mgmt Recovery Services Backup Service Attention customer-reported question

All 58 comments

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @pvrk.

you can refer this doc: https://docs.microsoft.com/en-us/python/api/azure-mgmt-compute/azure.mgmt.compute.v2020_06_01.operations.virtualmachinesoperations?view=azure-python

seems method Capture may help you.

Hi thanks for reply,

I am looking for creation of backup via vault recovery services available on azure portal, as of now we are doing loggin in via portal, i wanted to perform this activity via python sdk.. can we have some usecase example please

which vault recovery services you used?I can check whether we have correspondin python sdk?

@sambitratha: Do we have some examples we can share out of our Azure CLI implementation?

@sambitratha: Do we have some examples we can share out of our Azure CLI implementation?

Thank you shall wait for it :).

@sambitratha: Do we have some examples we can share out of our Azure CLI implementation?

@pvrk Hi, can i get some example please. it will be really help us

@pvrk @sambitratha can we have some example please...

@onenessboy : @sambitratha is working on this. Since this is the first time we have had this request, it is taking some time for us. Apologize for the inconvenience caused.

@onenessboy : @sambitratha is working on this. Since this is the first time we have had this request, it is taking some time for us. Apologize for the inconvenience caused.

Thanks @pvrk for update. Sorry for the push. I know there are powershell to handle, but in our case we are moving ahead with pythonic way automation(due to integration plans) hence the ask. I am sorry to say, we dont have any full fledged python examples anywhere on internet (still googling for hours with out a valid example) :( hence the followup. we will be glad if we can get some workable sample. thank you. I hope i would see more python based sdk examples to automate our azure activities..

@onenessboy : Thanks for understanding. Once we have this sample, we will plan to officially publish samples for these scenarios as well so that it will be useful to everyone else.

@onenessboy : Thanks for understanding. Once we have this sample, we will plan to officially publish samples for these scenarios as well so that it will be useful to everyone else.

@pvrk thanks for update, meanwhile waiting for that, i raised another similar request but intention to find backup status of a azure vm via python sdk, though i figured out something but unless i give vault name, vault recovery resource group name and backup policy name then i am only getting status (i followed GET REST API for this in pythn program), but whole idea is to get backup status simply by providing hostname of azure , by hostname, it should find bacakupvaultname, and its vault resource group and backupplocy name dynamically substitute in GET API then give us result) . I have opened another issue with #12977 few days ago, if our existing solution which you were trying to have cover this aspect as well Please have a look at this issue details once. In our internal discussion, requestor told that i am able to see backup status in just 3 clicks, login to portal, click on backup, see the status. why cant you do these 3 steps in python (its very simple for them) but for me unless i have a concrete example difficult to execute :)

@onenessboy : This API is exactly for that purpose. You only need to provide the ARM ID of the VM, and the result will give you the vault name, backup item name and the policy name.

@onenessboy : This API is exactly for that purpose. You only need to provide the ARM ID of the VM, and the result will give you the vault name, backup item name and the policy name.

@pvrk thanks for that API, but that does not work in our case, we wanted output as per this API https://docs.microsoft.com/en-us/rest/api/backup/backupprotecteditems/list which is we are exactly looking for these to work I need to know backupvaultname, vault resource group name and backuppolicy name to fetch status where I supply filter condition as "$filter=backupManagementType eq 'AzureIaasVM' and itemType eq 'VM' and policyName eq '{backup_policy_name}' so now the issue is i want to know this information only by passing hostname not all other vault related parameters, i have to find it programatically. I wrote some python program based on this api, but it wont work unless i pass vault name,vault resourgroupname and backup policy name before hand, which is not possible all the time, only information we get is hostname (from perspective of automation)

SDKConfigureBackup.txt

@onenessboy Please find the attached sample script to configure backup for VM . Let us know if it helps.

SDKConfigureBackup.txt

@onenessboy Please find the attached sample script to configure backup for VM . Let us know if it helps.

Thank you @mepand , shall check, meanwhile, our use case is trigerring a backup is vaultbased, hope this covers that one...anyway letme try @pvrk Karthik, special thanks to you for following it up for sample

SDKConfigureBackup.txt

@onenessboy Please find the attached sample script to configure backup for VM . Let us know if it helps.

Hi @mepand

My intial understand of script is that we need to pass vaultname,vault resource group .vmname,vm rg as parameters . (correct if i am wrong in this understanding)
If my understanding is correct, this may not work, our requriement is to just pass on VM name, then it script should get its vault name, vault resourgrame, backupoloyc, then do a adhoc backup (in simple terms, how we login into portal --> click on vm --> go to backup upsection --> click on backup, we need to do the same via python sdk).. (my requriement is specifically to kicoff an adhoc backup of existing vm which is already configured on vault)

@onenessboy : Unfortunately, we translated this requirement differently
"How to create a Azure VM backup" -> We translated as "how to configure backup for an unprotected VM". We supplied the script for that.
Now, we have clarified requirement: "my requirement is specifically to kicoff an adhoc backup of existing vm which is already configured on vault and with only VM name". This is a completely different requirement have to go with the mixed API approach (API to get vault details using VM name -> Then trigger a backup for that backup item). I will try to see if we can do that but this will take few days because of other priorities.

@onenessboy : Unfortunately, we translated this requirement differently
"How to create a Azure VM backup" -> We translated as "how to configure backup for an unprotected VM". We supplied the script for that.
Now, we have clarified requirement: "my requirement is specifically to kicoff an adhoc backup of existing vm which is already configured on vault and with only VM name". This is a completely different requirement have to go with the mixed API approach (API to get vault details using VM name -> Then trigger a backup for that backup item). I will try to see if we can do that but this will take few days because of other priorities.

@pvrk thanks for update. but yeah, I shall wait for solution ..no other choice than waiting :). Might be i could have asked question in detailed manner when I created this ticket :) hmm. Anyway thanks for help

@onenessboy : For starters, the script will accept ARM ID of the VM. Hope that's fine.

@onenessboy : For starters, the script will accept ARM ID of the VM. Hope that's fine.

@pvrk Do you mean to say "Subscription ID "? If yes, then its fine

@onenessboy : For starters, the script will accept ARM ID of the VM. Hope that's fine.

@pvrk Do you mean to say "Subscription ID "? If yes, then its fine

@onenessboy : By ARM ID, I mean, the VM ID in the Azure resource model, in these lines (look at resource ID):

{
"resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.Compute/VirtualMachines/testVm",
"resourceType": "VM"
}

@onenessboy : We have 2 scripts (One listing backup items with just VM ID, then using that output to trigger backup). I am attaching these 2 scripts. Please see if you combine those and fulfill the requirement.

BkPItemUsingVMID.txt
trigger_backup.txt

@onenessboy : We have 2 scripts (One listing backup items with just VM ID, then using that output to trigger backup). I am attaching these 2 scripts. Please see if you combine those and fulfill the requirement.

BkPItemUsingVMID.txt
trigger_backup.txt

Thanks for those script, let me try :)

@onenessboy : We have 2 scripts (One listing backup items with just VM ID, then using that output to trigger backup). I am attaching these 2 scripts. Please see if you combine those and fulfill the requirement.

BkPItemUsingVMID.txt
trigger_backup.txt

Hi @pvrk ,

I am testing your code... client = ComputeManagementClient(credential, subscription.subscription_id) i
i am assuming client referes to ComputeManagementClient for this purpose , am i correct ? I mean which client to need to use get this vault rg and resource group ?

@sambitratha: Can you please help answer this question?

@sambitratha: Can you please help answer this question?

@sambitratha @pvrk Apart from this what is cmd parameter in this definition . Till now i am able to get vm id(VM_ID) with additional wrapper code i wrote apart from your script that value ...
what is this cmd parameter for this definition, do i need to install azure cli on my machine to test your code ?

def check_protection_enabled_for_vm(cmd, vm_id):
        vaults = list_vaults(vaults_cf(cmd.cli_ctx))
        protected_vault_name, protected_vault_rg = "", ""

Its says

result = check_protection_enabled_for_vm(cmd, vm_id)
NameError: name 'cmd' is not defined

@pvrk apologies, I guess this will be longest post in issues section :) . I know we will be achieving something out of this triage, .. thanks for your patience

@sambitratha can you please clarify what is cmd parameter here, please...if that is related to azure cli, i have now configure azure cli via pip install on my machine. But still what is value that i need to pass for cmd so that i can continue testing .

Hi @onenessboy ,
apologies for the delay. This is the first time we're having to write SDK examples. So we're also facing some difficulties so bear with us please :)
Regarding your query here is my response
1) except where we've use virtual_machines_cf in all other methods client is RecoveryServicesClient, for virtual machines it is computeClient.
2) cmd is something we get inherently in CLI. So it may not work for you. The other way would be to use the below line
mgmt_client.backup_protected_items.list
Basically what we're proposing is to replace subclient_cf(cmd.cli_ctx) by mgmt_client.subclient

Hi @onenessboy ,
apologies for the delay. This is the first time we're having to write SDK examples. So we're also facing some difficulties so bear with us please :)
Regarding your query here is my response

  1. except where we've use virtual_machines_cf in all other methods client is RecoveryServicesClient, for virtual machines it is computeClient.
  2. cmd is something we get inherently in CLI. So it may not work for you. The other way would be to use the below line
    mgmt_client.backup_protected_items.list
    Basically what we're proposing is to replace subclient_cf(cmd.cli_ctx) by mgmt_client.subclient

@sambitratha thanks for your updates. If you dont mind, can you update those scripts with mgmt.client and give me sample then i will test. Because want to make sure to replace with all nececcary places in script?, can you do it raw update on those scripts shared by @pvrk and give re attach here...:)

trigger_backup.txt
BkPItemUsingVMID.txt
Please find the updated scripts. Can you please try this and let me know if it works? Thanks

Note: please hardcode the value of credential and subscriptionid

trigger_backup.txt
BkPItemUsingVMID.txt
Please find the updated scripts. Can you please try this and let me know if it works? Thanks

Note: please hardcode the value of credential and subscriptionid

Let me try this @sambitratha .. Thanks buddy for your patience 馃憤

@pvrk @sambitratha Here the update, I have tried, till now able to list armid, then able to fecth vm if out it, and lists VM's resourcegroup. but i am getting error at below point

        def list_vaults(mgmt_recsvc_client, resource_group_name=None):
            if resource_group_name:
                return mgmt_recsvc_client.list_by_resource_group(resource_group_name)

            return mgmt_recsvc_client.list_by_subscription_id()

        vault_list_output = list_vaults(mgmt_recsvc_client, resource_group_name=None)
        print("Vault list is:",vault_list_output)

Error:

 return mgmt_recsvc_client.list_by_subscription_id()
AttributeError: 'RecoveryServicesClient' object has no attribute 'list_by_subscription_id'

for this fucntion, is mgmt_recsvc_client is correct client ? I tried with compute,mgmt_backup_client clients also, same error ?

and what is client here in below function: is Mgmt_resvc_client is correct ?

        def check_protection_enabled_for_vm(vm_id):
            vaults = list_vaults(mgmt_recsvc_client.vaults)
            protected_vault_name, protected_vault_rg = "", ""

            for vault in vaults:
                vault_rg = get_resource_group_from_id(vault.id)
                items = list_items(mgmt_backup_client.backup_protected_items, vault_rg, vault.name)
                if any(vm_id.lower() == item.properties.virtual_machine_id.lower() for item in items):
                    protected_vault_name, protected_vault_rg = vault.name, vault_rg

            if protected_vault_name != "":
                vm_name = vm_id

                item = show_item(mgmt_backup_client.backup_protected_items, protected_vault_rg, protected_vault_name,
                                 vm_name, vm_name)
                return item

            return None

any idea ?

Here is my observation, can you please correctly update which client I need to use for all functions defined. I am still confused which client used for what ? to list vault by resource group what is the client we need to use ? i mean in BkPItemUsingVMID.txt

Hi @onenessboy i have already mentioned it in the script. mgmt_recsvc_client which is an instance of RecoveryServicesClient is the uber level client. And we are using mgmt_recsvc_client.vaults as the client to list the vaults.

vaults = list_vaults(mgmt_recsvc_client.vaults)

if you look at the above line the correct client is already passed to the list_vaults function.

Hi @onenessboy i have already mentioned it in the script. mgmt_recsvc_client which is an instance of RecoveryServicesClient is the uber level client. And we are using mgmt_recsvc_client.vaults as the client to list the vaults.

vaults = list_vaults(mgmt_recsvc_client.vaults)

if you look at the above line the correct client is already passed to the list_vaults function.

@sambitratha What about client in this which is giving error ?
def list_vaults(mgmt_recsvc_client, resource_group_name=None):
Is this correct ? Because it's giving error , see above my previous comment I pasted error

def list_vaults(mgmt_recsvc_client, resource_group_name=None):
            if resource_group_name:
                return mgmt_recsvc_client.list_by_resource_group(resource_group_name)

            return mgmt_recsvc_client.list_by_subscription_id()

        vault_list_output = list_vaults(mgmt_recsvc_client, resource_group_name=None)
        print("Vault list is:",vault_list_output)

Error:

return mgmt_recsvc_client.list_by_subscription_id() AttributeError: 'RecoveryServicesClient'

please replace vault_list_output = list_vaults(mgmt_recsvc_client, resource_group_name=None)
by vault_list_output = list_vaults(mgmt_recsvc_client.vaults, resource_group_name=None)

please replace vault_list_output = list_vaults(mgmt_recsvc_client, resource_group_name=None)
by vault_list_output = list_vaults(mgmt_recsvc_client.vaults, resource_group_name=None)

Hi @sambrtratha thanks for your response, I modified like above, Now I am to print till below:

arm id is: /subscriptions/xxxxxxx/resourceGroups/xxxx/providers/Microsoft.Compute/virtualMachines/xxxxxxxx
vm id is: xxxxxx
resource group name is: xxxxxx
Vault list is: <azure.mgmt.recoveryservices.models._paged_models.VaultPaged object at 0x0131D9D0>

Tried:

       vault_list_output = list_vaults(mgmt_recsvc_client.vaults, resource_group_name=None)
        output = vault_list_output.as_dict()
        print("Vault list is:",output)

but got AttributeError: 'VaultPaged' object has no attribute 'as_dict'

Hence followup questions are :

1)How to print correctly the last item in readable format i.e Vault List i above output ?
2)Which function your code shall return vault name,vault resourcegroup typically like below:
"vaultId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.RecoveryServices/Vaults/testVault"

Hi @onenessboy Here is my response
1) For printing vault list please use print(list(vault_list_output))
2) The function check_protection_enabled_for_vm returns the protected item. There you can find all the details.

2. check_protection_enabled_for_vm

@sambitratha

It still prints like below print(list(vault_list_output):

[<azure.mgmt.recoveryservices.models._models_py3.Vault object at 0x01B3AA10>, <azure.mgmt.recoveryservices.models._models_py3.Vault object at 0x01B3AA90>, <azure.mgmt.recoveryservices.models._models_py3.Vault object at 0x01B3AAF0>, <azure.mgmt.recoveryservices.models._models_py3.Vault object at 0x01B3AA30>, <azure.mgmt.recoveryservices.models._models_py3.Vault object at 0x01B3ABB0>, <azure.mgmt.recoveryservices.models._models_py3.Vault object at 0x01B3AC10>]

can you please confirm if you are able to view dict of individual items?
vault_list = list(vault_list_output)
print(vault_list[0].__dict__

print(vault_list[0].__dict__

Hi @sambitratha ,

Now, i am able to print below, it only shows vault resource group i guess, Recovery services vault name is missing(which is testbackupreportin my case. if you see below output of print(vault_list[0].__dict__) there are still objects showing in object format, how to view this properly ? Might be vault name will be there in that object ?
```
'properties': , 'sku': }
````
in below ?

{'additional_properties': {'etag': 'W/"datetime\'2020-07-31T16%3A13%3A17.2269967Z\'"'}, 'id': '/subscriptions/xxxxxxx/resourceGroups/xxxxxx/providers/Microsoft.RecoveryServices/vaults/testbackup', 'name': 'testbackup', 'type': 'Microsoft.RecoveryServices/vaults', 'e_tag': None, 'location': 'eastus', 'tags': None, 'identity': None, 'properties': <azure.mgmt.recoveryservices.models._models_py3.VaultProperties object at 0x0157AAB0>, 'sku': <azure.mgmt.recoveryservices.models._models_py3.Sku object at 0x0157AAD0>}

Hi @onenessboy i believe vault name is showing. Vault resourceGroup is not.
{'additional_properties': {'etag': 'W/"datetime\'2020-07-31T16%3A13%3A17.2269967Z\'"'}, 'id': '/subscriptions/xxxxxxx/resourceGroups/xxxxxx/providers/Microsoft.RecoveryServices/vaults/testbackup', 'name': 'testbackup', 'type': 'Microsoft.RecoveryServices/vaults', 'e_tag': None, 'location': 'eastus', 'tags': None, 'identity': None, 'properties': <azure.mgmt.recoveryservices.models._models_py3.VaultProperties object at 0x0157AAB0>, 'sku': <azure.mgmt.recoveryservices.models._models_py3.Sku object at 0x0157AAD0>}

I can see 'name' : 'testbackup' in the response.
To get resourceGroup you have to extract from the id. Response doesn't return a specific property for that.
To print all the members of this object you can use pprint

Hi @onenessboy i believe vault name is showing. Vault resourceGroup is not.
{'additional_properties': {'etag': 'W/"datetime\'2020-07-31T16%3A13%3A17.2269967Z\'"'}, 'id': '/subscriptions/xxxxxxx/resourceGroups/xxxxxx/providers/Microsoft.RecoveryServices/vaults/testbackup', 'name': 'testbackup', 'type': 'Microsoft.RecoveryServices/vaults', 'e_tag': None, 'location': 'eastus', 'tags': None, 'identity': None, 'properties': <azure.mgmt.recoveryservices.models._models_py3.VaultProperties object at 0x0157AAB0>, 'sku': <azure.mgmt.recoveryservices.models._models_py3.Sku object at 0x0157AAD0>}

I can see 'name' : 'testbackup' in the response.
To get resourceGroup you have to extract from the id. Response doesn't return a specific property for that.
To print all the members of this object you can use pprint

@sambitratha

What ever I see resource group in that ID is belongs to my VM. But for this VM Backup config, We Vault Resource group is different, so was looking that that vaultresource group name and vault name. In console --> under backup --> I see recovery service vaultname as --'testbackupreport' and when i see its information its vault group is different (as per configuration). I came to know that VM's Resourge Group and its Backupvalut resource group can be same or different also . Anyway let me try to pprint that...let me see what that additional properties it will print

Hi @onenessboy i believe vault name is showing. Vault resourceGroup is not.
{'additional_properties': {'etag': 'W/"datetime\'2020-07-31T16%3A13%3A17.2269967Z\'"'}, 'id': '/subscriptions/xxxxxxx/resourceGroups/xxxxxx/providers/Microsoft.RecoveryServices/vaults/testbackup', 'name': 'testbackup', 'type': 'Microsoft.RecoveryServices/vaults', 'e_tag': None, 'location': 'eastus', 'tags': None, 'identity': None, 'properties': <azure.mgmt.recoveryservices.models._models_py3.VaultProperties object at 0x0157AAB0>, 'sku': <azure.mgmt.recoveryservices.models._models_py3.Sku object at 0x0157AAD0>}
I can see 'name' : 'testbackup' in the response.
To get resourceGroup you have to extract from the id. Response doesn't return a specific property for that.
To print all the members of this object you can use pprint

@sambitratha

What ever I see resource group in that ID is belongs to my VM. But for this VM Backup config, We Vault Resource group is different, so was looking that that vaultresource group name and vault name. In console --> under backup --> I see recovery service vaultname as --'testbackupreport' and when i see its information its vault group is different (as per configuration). I came to know that VM's Resourge Group and its Backupvalut resource group can be same or different also . Anyway let me try to pprint that...let me see what that additional properties it will print

Hi @sambitratha with pprint also its print same

'properties': <azure.mgmt.recoveryservices.models._models_py3.VaultProperties object at 0x04C59AB0>,
 'sku': <azure.mgmt.recoveryservices.models._models_py3.Sku object at 0x04C59AD0>,

Hmm. In that case you have to do vault_list[0].properties.__dict__
Just for my understanding, till which part of the script that i have pasted in this thread were you able to execute? because we don't need to know the vault name from the list_vaults method. We should only be concerned about the vault where the VM is protected. Were you able to run the script till there?

vault_list[0].properties.__dict__

@sambitratha Hi, Here the update.
1) I did use vault_list[0].properties.__dict__ print below, It prints following..
```
arm id is: /subscriptions/xxxxxx/resourceGroups/xxxxxxx/providers/Microsoft.Compute/virtualMachines/xxxxxx
vm id is: xxxxxx
resource group name is: xxxxxxx #(this is vm resource group name)
{'additional_properties': {'etag': 'W/"datetime\'2019-11-01T10%3A11%3A20.1503736Z\'"'},
'e_tag': None,
'id': '/subscriptions/xxxxxxxx/resourceGroups/ABC/providers/Microsoft.RecoveryServices/vaults/abcvault', # here it is one of vault group resides in my subscription, but not belong to vault belong my vm
'identity': None,
'location': 'eastus',
'name': 'abcvault',
'properties': ,
'sku': ,
'tags': None,
'type': 'Microsoft.RecoveryServices/vaults'}
{'additional_properties': {},
'private_endpoint_connections': None,
'private_endpoint_state_for_backup': 'None',
'private_endpoint_state_for_site_recovery': 'None',
'provisioning_state': 'Succeeded',
'upgrade_details': None}
````
2) so I guess subscription have many vault groups, but its displaying a resource group which not belong to vm which i am checking..I guess we may need to loop and find out which vault and vault group assinged to my vm ? how to achive this ? can you add some logic to find this

2) I have slightly modified the your original script and jumbled functions up and down because it was keep giving me not defined ..not defined. errors. :)

3) Attached updated script (which I tested)

4) .. all i need of this first script output is
my VM name --> its Recovery services vault name (which it shows on console backupsummary page) --> and its Vault resrouce group( assuming i have many vault names and corresponding vault resource group for a subscription ie. out of so many vault recovery group , which vault recovery group my VM' backup is attached to)
update.txt](https://github.com/Azure/azure-sdk-for-python/files/5102966/update.txt)

Hi @onenessboy Thank you for sharing your script. your changes look good to me. Can you also share the full output of the script.
Specially the output of protection_status = check_protection_enabled_for_vm(vm_id)
If you could attach the outputs and errors (if any) i'll be able to help you out
Thank you

Hi @onenessboy Thank you for sharing your script. your changes look good to me. Can you also share the full output of the script.
Specially the output of protection_status = check_protection_enabled_for_vm(vm_id)
If you could attach the outputs and errors (if any) i'll be able to help you out
Thank you

Here it is:
@sambitratha . Here is the output. This is based on print statement that I have used in my updated script attached..do you want to print any additional items ? let me know

arm id is: /subscriptions/xxxxxx/resourceGroups/xxxxxxx/providers/Microsoft.Compute/virtualMachines/xxxxxx
vm id is: xxxxxx
resource group name is: xxxxxxx   #(this is vm resource group name)
{'additional_properties': {'etag': 'W/"datetime\'2019-11-01T10%3A11%3A20.1503736Z\'"'},
 'e_tag': None,
 'id': '/subscriptions/xxxxxxxx/resourceGroups/ABC/providers/Microsoft.RecoveryServices/vaults/abcvault',   **# here it is one of vault group resides in my subscription, but not belong to vault belong my vm**
 'identity': None,
 'location': 'eastus',
 'name': 'abcvault',
 'properties': <azure.mgmt.recoveryservices.models._models_py3.VaultProperties object at 0x04C5BE30>,
 'sku': <azure.mgmt.recoveryservices.models._models_py3.Sku object at 0x04C5BBB0>,
 'tags': None,
 'type': 'Microsoft.RecoveryServices/vaults'}
{'additional_properties': {},
 'private_endpoint_connections': None,
 'private_endpoint_state_for_backup': 'None',
 'private_endpoint_state_for_site_recovery': 'None',
 'provisioning_state': 'Succeeded',
 'upgrade_details': None}
Protection status is: None

@onenessboy : This is going longer than we anticipated. I suggest we can get onto a call and discuss more. Can you please let me know your email ID to which I can send a Teams meeting invite?

@onenessboy : This is going longer than we anticipated. I suggest we can get onto a call and discuss more. Can you please let me know your email ID to which I can send a Teams meeting invite?

@pvrk @sambitratha thanks

@onenessboy : This is going longer than we anticipated. I suggest we can get onto a call and discuss more. Can you please let me know your email ID to which I can send a Teams meeting invite?

@pvrk @sambitratha thanks

@sambitratha @pvrk Fantastic, first script got the output requried.. vaultname, vaultgroup as expected.. will now test the trigger backup script and let u know details. Thank you so much for call and your valuable time... I will keep posted updated on trigger backup stuff when I test it

@onenessboy : Good to know that the first script worked. Any update on the 2nd one?

@onenessboy : Good to know that the first script worked. Any update on the 2nd one?

Hi @pvrk @sambitratha , sorry for delayed response. Shall give update soon.

@onenessboy : Good to know that the first script worked. Any update on the 2nd one?

Hi @pvrk @sambitratha , sorry for delayed response. Shall give update soon.

@sambitratha @pvrk Done with backup trigger script as well unfortunately no erros, but backup not triggered...

        protection_status = check_protection_enabled_for_vm(arm_id,region)
        vaultid = protection_status.vault_id        
        vault_rsc_group = vaultid.split("/")
        vault_rg_name = vault_rsc_group[4]
        print("vault rg name is :",vault_rg_name)
        vault_name = vault_rsc_group[8]
        print("vault name is :", vault_name)
         mgmt_backup_client = RecoveryServicesBackupClient(credential, subscription.subscription_id)
        def get_protection_container_uri_from_id(arm_id):
            m = re.search('(?<=protectionContainers/)[^/]+', arm_id)
            return m.group(0)

        def get_protected_item_uri_from_id(arm_id):
            m = re.search('(?<=protectedItems/)[^/]+', arm_id)
            return m.group(0)


        def get_backup_request(workload_type, retain_until):
            trigger_backup_properties = IaasVMBackupRequest(recovery_point_expiry_time_in_utc=retain_until)
            trigger_backup_request = BackupRequestResource(properties=trigger_backup_properties)
            return trigger_backup_request


        def backup_now(mgmt_backup_client, vault_rg_name, vault_name, item, retain_until=None):
            # default retention of RP
            if retain_until is None:
                retain_until = (datetime.utcnow() + timedelta(days=30)).strftime('%d-%m-%Y')
            client = mgmt_backup_client.backups
            container_uri = get_protection_container_uri_from_id(item.id)
            item_uri = get_protected_item_uri_from_id(item.id)
            trigger_backup_request = get_backup_request(item.properties.workload_type, retain_until)
            fabric_name = "Azure"
            mgmt_backup_client.trigger(vault_name, vault_rg_name, fabric_name, container_uri, item_uri, trigger_backup_request, raw=True)

this is the code i am using.... from which u shared.. slightly changed..i am getting vaultname and vault resource group from our ealier script which geneated the protection stuatus which has all the vault infomration.

@onenessboy : Thanks for the update. Were you able to visit Azure Portal and confirm that no backup was triggered? No Job? What was the output of your script?

@sambitratha : tagging for information.

@onenessboy : Thanks for the update. Were you able to visit Azure Portal and confirm that no backup was triggered? No Job? What was the output of your script?

@sambitratha : tagging for information.

Yeah, @pvrk Kartik, It did not trigger any job there.. verified twice. Bascially No error. Huh. @sambitratha if possible, when you have some time, can we have catchup of 15 min or so (based on your availbility) shedule a call to close this. Thanks in advacne

@onenessboy : Strange behavior. What was the output of the script? can you please share over email? That would help us prepare for any meeting, if required.

@onenessboy : A gentle reminder to share updates/information over email.

Was this page helpful?
0 / 5 - 0 ratings