Solved

script is needed for backing up DNS integrated zones

Posted on 2015-01-23
3
107 Views
Last Modified: 2015-01-26
script is needed for backing up DNS integrated zones
0
Comment
Question by:creative555
3 Comments
 
LVL 7

Accepted Solution

by:
Deadman earned 250 total points
ID: 40567885
Backs up all the DNS zones on a server, including Active Directory-integrated zones. Requires DNSCMD.exe in the current directory or path.

Script in BAT file

@echo off
REM ======================================================================
REM
REM NAME: DNSBackup.bat
REM
REM AUTHOR:
REM DATE  :
REM  
REM    Version: 1.0
REM  
REM COMMENT: Requires DNSCMD.exe in the current directory or in the path.
REM        Will create a backup of all zones hosted local, even AD integrated
REM     zones.  Will auto-create CABS directory where script is
REM        executed from.  This will store .dns (standard primary zone files)
REM        in CAB file.
REM  
REM **DISCLAIMER**
REM    THIS MATERIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
REM    EITHER EXPRESS OR IMPLIED, INCLUDING, BUT Not LIMITED TO, THE
REM    IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
REM    PURPOSE, OR NON-INFRINGEMENT. SOME JURISDICTIONS DO NOT ALLOW THE
REM    EXCLUSION OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY NOT
REM    APPLY TO YOU. IN NO EVENT WILL I BE LIABLE TO ANY PARTY FOR ANY
REM    DIRECT, INDIRECT, SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY
REM    USE OF THIS MATERIAL INCLUDING, WITHOUT LIMITATION, ANY LOST
REM    PROFITS, BUSINESS INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON
REM    YOUR INFORMATION HANDLING SYSTEM OR OTHERWISE, EVEN If WE ARE
REM    EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.  
REM
REM ======================================================================
REM Create Date Variable (US Only) YYYYMMDD
:DATE
For /F "Tokens=2" %%I in ('Date /t') Do Set DTemp=%%I
For /F "Delims=/,= Tokens=2" %%I in ('Set DTemp') Do Set TDate=%%I
For /F "Delims=/,= Tokens=3" %%I in ('Set DTemp') Do Set TDate=%TDate%%%I
For /F "Delims=/,= Tokens=4" %%I in ('Set DTemp') Do Set TDate=%%I%TDate%
Set DTemp=
 
REM Current Directory
set DNSBACKUPPATH=%~dp0
 
REM Default DNS Backup location
set DNSDEFAULTPATH=%systemroot%\system32\dns\
 
REM Directory of where to store DNS Backup Cab files
set CABDIR=%DNSBACKUPPATH%cabs
 
REM Create Directory to store cab files if it does not exist
if not exist %CABDIR% md %CABDIR%
 
REM Create a DATED directory to store today's DNS Backup
if not exist %DNSBACKUPPATH%%TDATE% md %DNSBACKUPPATH%%TDATE%
 
REM CAB directive file (.DDF) needed to cab all files backed up in to one Cab file
Set CABDIRFILE=%DNSBACKUPPATH%%TDATE%\DNSBackup.DDF
 
REM Enumerate primary dns zones, export them, and move them to a dated folder
for /f "tokens=1" %%I in ('dnscmd  /enumzones ^|find /i "primary"') do @dnscmd /zoneexport %%I %%I.%TDATE%.dns >NUL  &  
move %DNSDEFAULTPATH%%%I.%TDATE%.dns %DNSBACKUPPATH%%TDATE%\ >NUL
 
REM Create DDF (cab directive file) heading
echo ;***%COMPUTERNAME% DNS Backup %TDATE% Directive file >%CABDIRFILE%
echo ; >>%CABDIRFILE%
echo .OPTION EXPLICIT >>%CABDIRFILE%
echo .Set CabinetNameTemplate=%COMPUTERNAME%_DNSBackup_%TDATE%.CAB >>%CABDIRFILE%
echo .set DiskDirectoryTemplate=%CABDIR% >>%CABDIRFILE%
echo .Set MaxDiskSize=CDROM >>%CABDIRFILE%
echo .Set FolderSizeThreshold=2000000 >>%CABDIRFILE%
echo .Set CompressionType=MSZIP >>%CABDIRFILE%
echo .Set Cabinet=on >>%CABDIRFILE%
echo .Set Compress=on >>%CABDIRFILE%
 
REM add files to cab'ed to the DDF
for /f %%I in ('dir %DNSBACKUPPATH%%TDATE%\*.dns /b') do @echo %DNSBACKUPPATH%%TDATE%\%%I >>%CABDIRFILE%
 
REM switch to the dated folder and create cab file
cd /d %DNSBACKUPPATH%%TDATE% & makecab /f %CABDIRFILE% /L %CABDIR% >NUL
 
REM switch to script root directory and remove the dated folder and all files
cd /d %DNSBACKUPPATH% & rd /s /q %DNSBACKUPPATH%%TDATE% >NUL


https://gallery.technet.microsoft.com/scriptcenter/5931a49f-e7d0-4d5d-aff4-cb799213b29f#content
0
 
LVL 53

Assisted Solution

by:Will Szymkowski
Will Szymkowski earned 250 total points
ID: 40568195
You can accomplish this using Powershell. Use the powershell script from Jeffrey Hicks Powershell MVP.

Backup DNS using Powershell

Will.
0
 

Author Closing Comment

by:creative555
ID: 40571635
Thank you very much!
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Synchronize a new Active Directory domain with an existing Office 365 tenant
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through the process of configuring basic necessities in order to use the 2010 version of Data Protection Manager. These include storage, agents, and protection jobs. Launch Data Protection Manager from the deskt…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now