Backup DNS zone using Azure Functions

Roland Barreto 66 Reputation points
2022-06-22T16:23:49.89+00:00

I have this scenario.

I have a dns zone that I want to backup in a Azure Blob Storage.

These are the commands to do it manually.

  1. Export the DNS zone file using this Azure CLI command:

az network dns zone export -g myresourcegroup -n contoso.com -f /path/to/zonefile.txt

  1. Upload the exported DNS zone file to Azure blob storage using this Azure CLI command:

az storage blob upload -f /path/to/file -c MyContainer -n MyBlob --account-name xxxx --account-key xxxx

I'm not a dev but I have asigned this job, and I have to do it.

Is it possible to automate this into an Azure Function? How?

Azure Backup
Azure Backup
An Azure backup service that provides built-in management at scale.
1,490 questions
Azure DNS
Azure DNS
An Azure service that enables hosting Domain Name System (DNS) domains in Azure.
775 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Carlos Solís Salazar 18,191 Reputation points MVP Volunteer Moderator
    2022-06-22T18:56:20.957+00:00

    Hi anonymous user

    Thank you for asking this question on the **Microsoft Q&A Platform. **

    The azure function does not support AZ CLI, here you can check the Supported languages in Azure Functions

    I recommend you execute your script with PowerShell (Get-AzDnsZone)

    Running it with PowerShell will allow you to execute it in a runbook in an Automation Account

    Hope this helps,
    Carlos Solís Salazar

    ----------

    Accept Answer and Upvote, if any of the above helped, this thread can help others in the community looking for remediation for similar issues.
    NOTE: To answer you as quickly as possible, please mention me in your reply.



  2. Roland Barreto 66 Reputation points
    2022-06-22T23:42:37.21+00:00

    Thanks for your answer. It was very heplful. I did this. ![213994-image.png][1] This is a great result. I got the record sets of the dns zone. this is the output. ![213995-image.png][2] Now do you know how to get this output from this runbook in a file .txt? I need to get the txt to upload it to a storage account. [1]: /api/attachments/213994-image.png?platform=QnA [2]: /api/attachments/213995-image.png?platform=QnA

    0 comments No comments

  3. Luke Murray 11,436 Reputation points MVP Volunteer Moderator
    2022-06-23T10:23:23.967+00:00

    You could try:

    Get-AzDNSRecordSet -ResourceGroupName 'dnsreg' -ZoneName "geeknica.com" | Out-File 'DNSRecord.txt'

    This post is a good start:

    https://savilltech.com/2018/03/25/writing-to-files-with-azure-automation/

    Another option to consider is using Azure Bicep to control your DNS zones, so your backup is in code already - https://luke.geek.nz/azure/azure-public-dns-as-code/


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.