Solved

script is needed for backing up DNS integrated zones

Posted on 2015-01-23
3
112 Views
Last Modified: 2015-01-26
script is needed for backing up DNS integrated zones
0
Comment
Question by:creative555
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

627 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