Home » IT - Microsoft » Backup/Restore all DNS zones

Backup/Restore all DNS zones

Escribe tu dirección de correo electrónico para suscribirte a este blog, y recibir notificaciones de nuevos mensajes por correo.

Join 5 other followers

March 2016
M T W T F S S
« Feb   May »
 123456
78910111213
14151617181920
21222324252627
28293031  

NO! A LOS TOROS

Disclaimer

All messages posted to this blog are provided "AS IS" with no warranties, and confer no rights. The content of this site are personal opinions and might not represent the Microsoft Corporation view. Regarding any sample code that we provide: This Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment. THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. This blog serves 2 purposes. Firstly, I want to share information with other IT pros about the technologies we work with and how to solve problems we often face. Secondly, I use my blog as a notebook. There's so much to learn and remember in our jobs that it's impossible to keep up. By blogging, I have a notebook that I can access from anywhere. Anything you do to your IT infrastructure, applications, services, computer or anything else is 100% down to your own responsibility and liability. Mcselles bears no responsibility or liability for anything you do. Please independently confirm anything you read on this blog before doing whatever you decide to do.
Advertisements

Backup/Restore all DNS zones

These scripts backup and restore all DNS zones on specific DNS server (source).
The backup script uses the Powershell cmdlet get-wmiobject to list the DNS zone present in the WMI database and then export each zone using the dnscmd tool.
The restore script uses the dnscmd tool to create the zone and his content.

Useful link on how to export and import AD integrated zone files.

Backup script :

#——————————————————————————————–#
# Script_Name : DNS_Backup.ps1
# Description : backup all DNS Zones defined on a Windows 2008 DNS Server
# Requirements : Windows 2008/R2 + DNS Management console Installed
# Version : 0.4 – Intergrated comments from Jeffrey Hicks
# Date : October 2011
# Created by Griffon
#——————————————————————————————-##– DEFINE VARIABLE——#
# Get Name of the server with env variable

$DNSSERVER=get-content env:computername

#—Define folder where to store backup  —–#
$BkfFolder=”c:\windows\system32\dns\backup”

#—Define file name where to store Dns Settings
$StrFile=Join-Path $BkfFolder “input.csv”

#—-Check if folder exists. if exists, delete contents–#
if (-not(test-path $BkfFolder)) {
new-item $BkfFolder -Type Directory | Out-Null
} else {

Remove-Item $BkfFolder”\*” -recurse
}

#—- GET DNS SETTINGS USING WMI OBJECT ——–#
#– Line wrapped should be only one line –#
$List = get-WmiObject -ComputerName $DNSSERVER
-Namespace root\MicrosoftDNS -Class MicrosoftDNS_Zone

#—-Export information into input.csv file —#
#– Line wrapped should be only one line –#
$list | Select Name,ZoneType,AllowUpdate,@{Name=”MasterServers”;Expression={$_.MasterServers}},
DsIntegrated | Export-csv $strFile -NoTypeInformation

#— Call Dnscmd.exe to export dns zones
$list | foreach {
$path=”backup\”+$_.name
$cmd=”dnscmd {0} /ZoneExport {1} {2}” -f $DNSSERVER,$_.Name,$path
Invoke-Expression $cmd
}

# End of Script
#——————————————————————————————-#

 

Restore script :

#———————————————————————-#
# Script_Name : RestoreDNS.ps1
# Description : Perform Restore of DNS Zones of a Windows 2008 DNS SErver
# Requirements : Windows 2008/R2 + DNS Management console Installed
# Version : 0.4
# Date : October 2011
# Created by Griffon
#———————————————————————–##– DEFINE VARIABLE——#
#———————————#
# Get Name of the server with env variable

$DNSSERVER=gc env:computername

#—DEFINE WHERE TO Look for DNS BACKUP FILES —–#

$BkfFolder=”c:\windows\system32\dns\backup”

#—Define file name where Dns Settings are Stored

$StrFile=Join-Path $BkfFolder “input.csv”

#—-  RESTORE ZONES BASED ON SETTINGS FOUND IN INPUT.CSV —— #

$Zone=import-csv $StrFile
$Zone | foreach {

$path=”backup\”+$_.name
$Zone=$_.name
$IP=$_.MasterServers
$Update=$_.AllowUpdate

#—– Checking if AD Integrated or Not ——-#if ($_.DsIntegrated -eq $True) {
Switch ($_.ZoneType)
{
1 {
#—– Need to Create Zone As Primary to get all records imported ——-#
$cmd0=”dnscmd {0} /ZoneAdd {1} /primary /file {2} /load” -f $DNSSERVER,$Zone,$path
Invoke-Expression $cmd0
$cmd1=”dnscmd {0} /ZoneResetType {1} /dsprimary” -f $DNSSERVER,$Zone
}

3 { $cmd1=”dnscmd {0} /ZoneAdd {1} /dsstub {2} /load” -f $DNSSERVER,$Zone,$IP }
4 { $cmd1=”dnscmd {0} /ZoneAdd {1} /dsforwarder {2} /load” -f $DNSSERVER,$Zone,$IP }
}
} else {

Switch ($_.ZoneType)
{
1 {$cmd1=”dnscmd {0} /ZoneAdd {1} /primary /file {2} /load” -f $DNSSERVER,$Zone,$path}
2 {$cmd1=”dnscmd {0} /ZoneAdd {1} /secondary {2}” -f $DNSSERVER,$Zone,$IP }
3 {$cmd1=”dnscmd {0} /ZoneAdd {1} /stub {2}” -f $DNSSERVER,$Zone,$IP }
4 {$cmd1=”dnscmd {0} /ZoneAdd {1} /forwarder {2}” -f $DNSSERVER,$Zone,$IP }
}
}

#Restore DNS Zones
Invoke-Expression $cmd1

Switch ($_.AllowUpdate)
{
#No Update
0 {$cmd2=”dnscmd /Config {0} /allowupdate {1}” -f $Zone,$Update}
#Secure and non secure
1 {$cmd2=”dnscmd /Config {0} /allowupdate {1}” -f $Zone,$Update}
#Only Secure Updates
2 {$cmd2=”dnscmd /Config {0} /allowupdate {1}” -f $Zone,$Update}

}

#Reset DNS Update Settings
Invoke-Expression $cmd2

}

# End of Script
#———————————————————————–#

Source: https://www.shellandco.net/backuprestore-all-dns-zones/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Microsoft on the Issues

News and perspectives on legal, public policy and citizenship topics

Mike Crowley's Whiteboard

“There are no limits to what you can accomplish when you are supposed to be doing something else."

T.B.D.

There Be Dragons

Ken Cenerelli

My life in software development

VMware, Windows, Virtualization (Servers & Desktops)

VMware, Windows, Virtualization (Servers & Desktops)

Just a random "Microsoft Server / Client Tech" info..

"Feeding Your Training and Technology Obsessions"

WordPress.com

WordPress.com is the best place for your personal blog or business site.

DocSharing

Documentación técnica, notas y apuntes sobre Administración de Sistemas, Servidores, Redes y más

Microsoft Taste

Mary's Blog

%d bloggers like this: