DNS Backup & Restore

by , under DNS

One of the things I have learned from my past experiences is never underestimate anything, especially “windows services” you do not know from top to bottom. DNS is a kind of service like this. It is operational for 99% or more of the year I think. Therefore, it is forgotten somewhere out, because it works and if you have an automated infrastructure, no configuration or operational procedure is needed most of the time.

Then one day, DNS makes itself reminded. Computers randomly begin to work so slow, bla bla bla. At last, you notice, one of your dns servers is not functioning properly.

Anyway, it is useful to have a backup of dns in need of restore or something else.

Here it is:

“C:\Windows\System32\dnscmd.exe” is used for this operation.

To Backup DNS

[code language=”bash”]
set THISDAY=%date:~10,4%-%date:~3,2%-%date:~0,2%
dnscmd.exe /ZoneExport domain.com DNSBACKUP_%THISDAY%.txt
Move C:\Windows\System32\dns\DNSBACKUP_%THISDAY%.txt C:\DNSBACKUP

To Restore DNS

[code language=”bash”]
Move C:\DNSBACKUP\DNSBACKUP_2014-09-10.txt C:\Windows\System32\dns
dnscmd /ZoneDelete domain.com /dsdel /f
dnscmd /ZoneAdd domain.com ^
/primary ^
/file C:\DNSBACKUP\DNSBACKUP_2014-09-10.txt ^
dnscmd /ZoneResetType domain.com /dsprimary