• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3599
  • Last Modified:

Script to backup DHCP database

Need to have a script file that can run every 6 hrs to backup the dhcp database while server is on and functioning.  If need to script in the netsh command from what I have read just not sure of all the switches or content needed.  Woudl right this file to another server location that contains the current scope, exclusions and is not authorized at the moment.
0
Lombwar
Asked:
Lombwar
  • 3
  • 3
1 Solution
 
jderaCommented:
Example:

@Echo Off
REM This script assumes that you are running it from a directory called "auto" on the "d:" drive and have a directory called "dhcplogs" inside of it.
REM It also assumes you have a file called dhcpbak.ini in the auto directory in which the names of the servers you want to back up is each on an individual line.
REM EXAMPLE (Sans REM):
REM DCHPSRV1
REM DCHPSRV2
REM DHCPSRV3

REM Cleaning out the today.log incase it wasn't removed properly.
if exist d:\auto\dhcplogs\today.log del d:\auto\dhcplogs\today.log

Set DHCPOK=YES
REM Get current time.
for /f "tokens=1 delims= " %%l in ('time /t') do (set time=%%l)
echo Starting the daily DHCP backup script %0 at %time%m. >> d:\auto\dhcplogs\today.log

REM Get current date in a usable format.
for /f "tokens=2-4 delims=/ " %%i in ('date /t') do (set month=%%i& set day=%%j& set year=%%k)
set month=%month:~0,2%
set date=%year%%month%%day%
echo The month is %month%, the day is %day%, and the year is %year%.>> d:\auto\dhcplogs\today.log

REM Start the process.
echo Backing up the DHCP backup databases...>> d:\auto\dhcplogs\today.log
for /f %%a in (d:\auto\dhcpbak.ini) do call :dhcpcopy %%a
echo >> d:\auto\dhcplogs\today.log
for /f "tokens=1 delims= " %%l in ('time /t') do (set time=%%l)

REM Finish and cleanup.
echo Script report finished at %time%m.>> d:\auto\dhcplogs\today.log
move d:\auto\dhcplogs\today.log d:\auto\dhcplogs\%date%.log

REM Create the title of the email report.
If %DHCPOK%==YES SET SENDLINE="Good DHCP Report"
If %DHCPOK%==NO SET SENDLINE="Bad DHCP Report"

REM this script uses the postie.exe utility from www.infradig.com
d:\auto\postie.exe -host:mailsrv.you.com -to:you@you.com -from:Automation@you.com -s:%SENDLINE% -file:d:\auto\dhcplogs\%date%.log -gmt
goto :EOF

REM This is the guts of the process.
:dhcpcopy
echo >> d:\auto\dhcplogs\today.log
echo Working on %1 ->> d:\auto\dhcplogs\today.log
if not exist \\%1\admin$\system32\dhcp\backup (echo DHCP backup path not found for %1.>> d:\auto\dhcplogs\today.log set DHCPOK=NO goto :EOF)
if NOT exist d:\DBBACKUP\DHCP\%1 (md d:\DBBACKUP\DHCP\%1 echo Creating DHCP backup storage directory for %1>> d:\auto\dhcplogs\today.log)
rd /s /q d:\DBBACKUP\DHCP\%1
md d:\DBBACKUP\DHCP\%1
xcopy \\%1\admin$\system32\dhcp\backup d:\DBBACKUP\DHCP\%1 /s /v
if not errorlevel 1 (for /f "tokens=1 delims= " %%l in ('time /t') do (set time=%%l)
echo %1 's backup DHCP database copied successfully at %time%m.>> d:\auto\dhcplogs\today.log
d:\auto\uptime.exe \\%1>> d:\auto\dhcplogs\today.log)
if errorlevel 1 (echo Encountered an error copying %1's DHCP database.>> d:\auto\dhcplogs\today.log set DHCPOK=NO)
0
 
LombwarAuthor Commented:
This is good, will have to take offline in our lab to test.

Is there a single command line that can be run to perform this operation in a temporary type of arrangement?
0
 
Jay_Jay70Commented:
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LombwarAuthor Commented:
have attempted to copy the files in the "backup" folder under DHCP in System 32 and restore to another location but this has not worked properly.  Used the netsh command for export of the database and imported to another server but get error that unable to determine the DHCP server version.

Checked the article and it indicated the GUI for this is this merely the "backup" option under the Actions menu in DHCP administrator?  Tried to use this also to do a restore to another Win 2k03 server with DHCP loaded and did not see the scopes pop up.
0
 
Jay_Jay70Commented:
0
 
LombwarAuthor Commented:
Thanks, have that document and followed the information under the Export the database from Win 2k03 server which is where after importing it onto another Win 2k03 server received the version mis match error.
0
 
Jay_Jay70Commented:
hmmm i have followed that numerous times - are they different versions of 2003? R2 and standard etc?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now