Automated backup of Azure DNS Zone records

%3CLINGO-SUB%20id%3D%22lingo-sub-719339%22%20slang%3D%22en-US%22%3EAutomated%20backup%20of%20Azure%20DNS%20Zone%20records%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-719339%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDoes%20anybody%20know%20if%20it%20is%20possible%20to%20somehow%20automate%20the%20backup%20of%20DNS%20zone%20records%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20can%20perform%20a%20manual%20export%20using%20the%20following%20command%20but%20would%20like%20it%20on%20a%20schedule%2C%20with%20the%20output%20dumped%20into%20a%20azure%20storage%20if%20possible.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eaz%20network%20dns%20zone%20export%20-g%20myresourcegroup%20-n%20contoso.com%20-f%20contoso.com.txt%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fdns%2Fdns-import-export%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fdns%2Fdns-import-export%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Echeers%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-719339%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAutomation%20%26amp%3B%20Control%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-720453%22%20slang%3D%22en-US%22%3ERe%3A%20Automated%20backup%20of%20Azure%20DNS%20Zone%20records%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-720453%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20can%20accomplish%20this%20with%20an%20automation%20account%20and%20runbook.%20As%20far%20as%20I%20am%20aware%20there%20is%20now%20way%20baked%20into%20the%20Azure%20portal%20to%20do%20this%20natively.%20It%20would%20have%20to%20be%20accomplished%20by%20scheduling%20that%20script%20you%20have%20outlined.%20Let%20me%20know%20if%20you%20would%20like%20some%20assistance%20with%20that%20and%20I%20can%20point%20you%20in%20the%20right%20direction.%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F342294%22%20target%3D%22_blank%22%3E%40GregHunter%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-721279%22%20slang%3D%22en-US%22%3ERe%3A%20Automated%20backup%20of%20Azure%20DNS%20Zone%20records%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-721279%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Bryan%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDo%20you%20mean%20there%20is%20'no'%20way%20baked%20into%20the%20portal%20to%20do%20this%20naively%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESome%20assistance%20would%20be%20much%20appreciated!%20I%20was%20hoping%20to%20pipe%20the%20out%20of%20the%20above%20command%26nbsp%3B%20into%20a%20blob%20file%20using%20the%20'az%20storage%20blob%20upload'%20command%2C%20but%20I%20dont%20think%20this%20is%20possible.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethanks%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F183000%22%20target%3D%22_blank%22%3E%40Bryan%20Haslip%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2061123%22%20slang%3D%22en-US%22%3ERe%3A%20Automated%20backup%20of%20Azure%20DNS%20Zone%20records%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2061123%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F183000%22%20target%3D%22_blank%22%3E%40Bryan%20Haslip%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Bryan!%20I%20know%20the%20post%20I%20am%20replying%20on%20is%20very%20old%20but%20it%20is%20exceptionally%20relevant%20to%20what%20I%20am%20currently%20fighting%20and%20I%20was%20hoping%20you%20could%20provide%20some%20direction.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20PowerShell%20script%20that%20I%20can%20log%20into%20the%20Azure%20Cloud%20Shell%20and%20run%20manually%20that%20exports%20all%20our%20public%20DNS%20zones%20and%20saves%20them%20to%20files.%20The%20goal%20is%20to%20get%20a%20backup.%20Obviously%20a%20manual%20backup%20is%20less%20than%20ideal%20so%20I%20am%20trying%20to%20automate%20this.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20you%20recommended%2C%20I%20have%20been%20fighting%20getting%20this%20working%20in%20an%20automation%20account%20for%20weeks%20now.%20Essentially%2C%20it%20is%20not%20recognizing%20the%20az%20command.%20In%20an%20effort%20to%20simplify%20troubleshooting%20I%20have%20created%20and%20published%20a%20runbook%20that%20runs%20only%20this%20(Resource%20Group%20name%20cut%20intentionally)%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CEM%3Eaz%26nbsp%3Bnetwork%26nbsp%3Bdns%26nbsp%3Bzone%26nbsp%3Blist%26nbsp%3B-g%20%25ResourceGroupName%25%3C%2FEM%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EA%20simple%20command%20that%20should%20just%20list%20the%20zones%20in%20the%20group.%20This%20fails%20with%20this%20error%3A%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CEM%3Eaz%20%3A%20The%20term%20'az'%20is%20not%20recognized%20as%20the%20name%20of%20a%20cmdlet%2C%20function%2C%20script%20file%2C%20or%20operable%20program.%20Check%20the%20spelling%20of%20the%20name%2C%20or%20if%20a%20path%20was%20included%2C%20verify%20that%20the%20path%20is%20correct%20and%20try%20again.%20At%20line%3A1%20char%3A1%20%2B%20az%20network%20dns%20zone%20list%20-g%20%25ResourceGroupName%25%20%2B%20~~%20%2B%20CategoryInfo%20%3A%20ObjectNotFound%3A%20(az%3AString)%20%5B%5D%2C%20CommandNotFoundException%20%2B%20FullyQualifiedErrorId%20%3A%20CommandNotFoundException%20%26nbsp%3B%3C%2FEM%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EDo%20you%20know%20if%20this%20is%20supported%20in%20an%20automation%20account%3F%20If%20not%2C%20is%20there%20a%20better%20way%20to%20do%20this%3F%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2068745%22%20slang%3D%22en-US%22%3ERe%3A%20Automated%20backup%20of%20Azure%20DNS%20Zone%20records%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2068745%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F929173%22%20target%3D%22_blank%22%3E%40nickfletcher%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAz%20CLI%20is%20not%20available%20in%20the%20cloud%20hosted%20Automation%20workers.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20either%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1)%20try%20to%20download%20and%20install%20Az%20CLI%20on%20the%20fly%20with%20PowerShell%20before%20running%20%22az%22%20commands.%20Of%20course%2C%20you%20would%20need%20first%20to%20authenticate%20with%20the%20Run%20As%20Account%20or%20other%20service%20principal.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2)%20use%20an%20Azure%20VM%20or%20a%20machine%20on-premises%20as%20a%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fautomation%2Fautomation-hybrid-runbook-worker%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EHybrid%20Worker%3C%2FA%3E.%20Runbooks%20will%20run%20in%20this%20machine%2C%20which%20is%20owned%20by%20you%20and%20where%20you%20can%20install%20whatever%20dependencies%20are%20needed.%20If%20you%20want%20to%20reuse%20Run%20As%20Accounts%20inside%20the%20worker%2C%20you%20will%20have%20to%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fautomation%2Fautomation-hrw-run-runbooks%23runas-script%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Einstall%20the%20Run%20As%20certificate%3C%2FA%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2070912%22%20slang%3D%22en-US%22%3ERe%3A%20Automated%20backup%20of%20Azure%20DNS%20Zone%20records%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2070912%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F453722%22%20target%3D%22_blank%22%3E%40hspinto%3C%2FA%3E%26nbsp%3BJust%20ot%20make%20sure%20I%20understand%20option%201%20correctly%2C%20you%20mean%20in%20the%20script%20I%20am%20trying%20to%20run%20add%20the%20commands%20to%20download%20the%20Az%20CLI%20so%20it%20will%20install%20in%20the%20sandboxed%20environment%20each%20time%20it%20runs%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2071009%22%20slang%3D%22en-US%22%3ERe%3A%20Automated%20backup%20of%20Azure%20DNS%20Zone%20records%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2071009%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F929173%22%20target%3D%22_blank%22%3E%40nickfletcher%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECorrect%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2071405%22%20slang%3D%22en-US%22%3ERe%3A%20Automated%20backup%20of%20Azure%20DNS%20Zone%20records%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2071405%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F453722%22%20target%3D%22_blank%22%3E%40hspinto%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you!%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hello,

 

Does anybody know if it is possible to somehow automate the backup of DNS zone records?

 

I can perform a manual export using the following command but would like it on a schedule, with the output dumped into a azure storage if possible.

 

az network dns zone export -g myresourcegroup -n contoso.com -f contoso.com.txt

https://docs.microsoft.com/en-us/azure/dns/dns-import-export

 

cheers

 

7 Replies

You can accomplish this with an automation account and runbook. As far as I am aware there is now way baked into the Azure portal to do this natively. It would have to be accomplished by scheduling that script you have outlined. Let me know if you would like some assistance with that and I can point you in the right direction. @GregHunter 

Hi Bryan,

 

Do you mean there is 'no' way baked into the portal to do this naively?

 

Some assistance would be much appreciated! I was hoping to pipe the out of the above command  into a blob file using the 'az storage blob upload' command, but I dont think this is possible. 

 

thanks @Bryan Haslip 

 

 

@Bryan Haslip 

 

Hi Bryan! I know the post I am replying on is very old but it is exceptionally relevant to what I am currently fighting and I was hoping you could provide some direction. 

 

I have a PowerShell script that I can log into the Azure Cloud Shell and run manually that exports all our public DNS zones and saves them to files. The goal is to get a backup. Obviously a manual backup is less than ideal so I am trying to automate this. 

 

As you recommended, I have been fighting getting this working in an automation account for weeks now. Essentially, it is not recognizing the az command. In an effort to simplify troubleshooting I have created and published a runbook that runs only this (Resource Group name cut intentionally):

az network dns zone list -g %ResourceGroupName%
 
A simple command that should just list the zones in the group. This fails with this error:
 
az : The term 'az' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + az network dns zone list -g %ResourceGroupName% + ~~ + CategoryInfo : ObjectNotFound: (az:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException  
 
Do you know if this is supported in an automation account? If not, is there a better way to do this? 
 

@nickfletcher 

 

Az CLI is not available in the cloud hosted Automation workers.

 

You can either:

 

1) try to download and install Az CLI on the fly with PowerShell before running "az" commands. Of course, you would need first to authenticate with the Run As Account or other service principal. 

 

2) use an Azure VM or a machine on-premises as a Hybrid Worker. Runbooks will run in this machine, which is owned by you and where you can install whatever dependencies are needed. If you want to reuse Run As Accounts inside the worker, you will have to install the Run As certificate.

@hspinto Just ot make sure I understand option 1 correctly, you mean in the script I am trying to run add the commands to download the Az CLI so it will install in the sandboxed environment each time it runs?