Scheduling a DNS backup

Using this script you can schedule a backup of forward lookup zones and keep the archive for 30 days.

$old=30
$DNSSERVER="DNSServerName"
$BkfFolder=”c:\windows\system32\dns\backup\Zones”
$List = Get-WmiObject -ComputerName $DNSSERVER -Namespace root\MicrosoftDNS -Class MicrosoftDNS_Zone | Where-Object{$_.reverse -like 'False'} | select name,ZoneType,AllowUpdate,MasterServers,DsIntegrated
$Dailybackups = "\DNSServerName\c$\windows\system32\dns\backup\Zones"
$Finallocation = "\BackupSharePath\Backups\IS-Domain\DNSBackups\DNSServerName"
Get-ChildItem "\BackupSharePath\Backups\IS-Domain\DNSBackups\DNSServerName" | ?{$_.CreationTime -le $old} |Remove-Item -Force
if (Test-Path $Dailybackups)
{
Remove-Item $Dailybackups -recurse
}
New-Item $Dailybackups -type Directory | Out-Null
$list | foreach {
$path=”backup\Zones\”+$_.name+"_"+(get-date -format MMddyyyy)+".txt"
$Archive="\DNSServerName\c$\windows\system32\dns\backup\Zones"+(get-date -format MMddyyyy)+".zip"
$cmd=”dnscmd {0} /ZoneExport {1} {2}-f $DNSSERVER,$</em>.Name,$path
Invoke-Expression $cmd
}
Compress-Archive $Dailybackups $Archive
Start-Sleep -Seconds 2
Move-Item $Archive $finallocation

Be the first to comment

Leave a Reply

Your email address will not be published.


*