Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

script is needed for backing up DNS integrated zones

Posted on 2015-01-23
3
Medium Priority
?
114 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 1000 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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
Screencast - Getting to Know the Pipeline

877 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