Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create a azure vm backup via python sdk . Steps needed please with example #12878

Closed
onenessboy opened this issue Aug 4, 2020 · 59 comments
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Recovery Services Backup Service Attention This issue is responsible by Azure service team.

Comments

@onenessboy
Copy link

  • 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

@ghost ghost added needs-triage This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Aug 4, 2020
@lmazuel lmazuel added Mgmt This issue is related to a management-plane library. Recovery Services Backup Service Attention This issue is responsible by Azure service team. labels Aug 4, 2020
@ghost ghost removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Aug 4, 2020
@ghost
Copy link

ghost commented Aug 4, 2020

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

@chenjianfei2017
Copy link
Contributor

@chenjianfei2017 chenjianfei2017 self-assigned this Aug 6, 2020
@onenessboy
Copy link
Author

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

@chenjianfei2017
Copy link
Contributor

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

@pvrk
Copy link
Member

pvrk commented Aug 6, 2020

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

@onenessboy
Copy link
Author

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

Thank you shall wait for it :).

@onenessboy
Copy link
Author

onenessboy commented Aug 10, 2020

@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

@onenessboy
Copy link
Author

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

@pvrk
Copy link
Member

pvrk commented Aug 11, 2020

@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
Copy link
Author

onenessboy commented Aug 11, 2020

@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..

@pvrk
Copy link
Member

pvrk commented Aug 13, 2020

@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
Copy link
Author

onenessboy commented Aug 13, 2020

@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 :)

@pvrk
Copy link
Member

pvrk commented Aug 13, 2020

@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
Copy link
Author

onenessboy commented Aug 13, 2020

@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)

@mepand
Copy link

mepand commented Aug 14, 2020

SDKConfigureBackup.txt

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

@onenessboy
Copy link
Author

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

@onenessboy
Copy link
Author

onenessboy commented Aug 14, 2020

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)

@pvrk
Copy link
Member

pvrk commented Aug 17, 2020

@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
Copy link
Author

onenessboy commented Aug 17, 2020

@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

@pvrk
Copy link
Member

pvrk commented Aug 17, 2020

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

@onenessboy
Copy link
Author

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 👍

@onenessboy
Copy link
Author

onenessboy commented Aug 19, 2020

@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

@sambitratha
Copy link

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.

@onenessboy
Copy link
Author

onenessboy commented Aug 19, 2020

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' ```

@sambitratha
Copy link

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)

@onenessboy
Copy link
Author

onenessboy commented Aug 20, 2020

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"

@sambitratha
Copy link

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.

@onenessboy
Copy link
Author

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>]

@sambitratha
Copy link

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__

@onenessboy
Copy link
Author

onenessboy commented Aug 20, 2020

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': <azure.mgmt.recoveryservices.models._models_py3.VaultProperties object at 0x0157AAB0>, 'sku': <azure.mgmt.recoveryservices.models._models_py3.Sku object at 0x0157AAD0>}

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>}

@sambitratha
Copy link

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

@onenessboy
Copy link
Author

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

@onenessboy
Copy link
Author

onenessboy commented Aug 20, 2020

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>,

@sambitratha
Copy link

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?

@onenessboy
Copy link
Author

onenessboy commented Aug 20, 2020

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': <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}
  1. 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)

@sambitratha
Copy link

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

@onenessboy
Copy link
Author

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

@pvrk
Copy link
Member

pvrk commented Aug 20, 2020

@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
Copy link
Author

onenessboy commented Aug 21, 2020

@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
Copy link
Author

@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

@pvrk
Copy link
Member

pvrk commented Sep 2, 2020

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

@onenessboy
Copy link
Author

@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
Copy link
Author

onenessboy commented Sep 8, 2020

@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.

@pvrk
Copy link
Member

pvrk commented Sep 9, 2020

@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
Copy link
Author

onenessboy commented Sep 10, 2020

@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

@pvrk
Copy link
Member

pvrk commented Sep 15, 2020

@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.

@pvrk
Copy link
Member

pvrk commented Sep 22, 2020

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

@mepand
Copy link

mepand commented Dec 8, 2020

Closing the issue since there is no action pending at our end. @onenessboy If you still need some assistance, feel free to reach out to us over mail.

@mepand mepand closed this as completed Dec 8, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Recovery Services Backup Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

7 participants