Solved

script is needed for backing up DNS integrated zones

Posted on 2015-01-23
3
106 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you very much!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Are you looking to recover an email message or a contact you just deleted mistakenly? Or you are searching for a contact that you erased from your MS Outlook ‘Contacts’ folder and now realized that it was important.
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
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…

772 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

12 Experts available now in Live!

Get 1:1 Help Now