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
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? |
Thank you shall wait for it :). |
@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. |
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. |
@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. |
@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) |
@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 |
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) |
@onenessboy : Unfortunately, we translated this requirement differently |
@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. |
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
Error:
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 ?
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. |
@sambitratha What about client in this which is giving error ?
Error:
|
please replace vault_list_output = list_vaults(mgmt_recsvc_client, resource_group_name=None) |
Hi @sambrtratha thanks for your response, I modified like above, Now I am to print till below:
Tried:
but got Hence followup questions are : 1)How to print correctly the last item in readable format i.e Vault List i above output ? |
Hi @onenessboy Here is my response
|
It still prints like below print(list(vault_list_output):
|
can you please confirm if you are able to view dict of individual items? |
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
in below ?
|
Hi @onenessboy i believe vault name is showing. Vault resourceGroup is not. I can see 'name' : 'testbackup' in the response. |
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
|
Hmm. In that case you have to do |
@sambitratha Hi, Here the update.
|
Hi @onenessboy Thank you for sharing your script. your changes look good to me. Can you also share the full output of the script. |
Here it is:
|
@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? |
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...
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. |
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. |
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. |
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
The text was updated successfully, but these errors were encountered: