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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


@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 Cleaning out the today.log incase it wasn't removed properly.
if exist d:\auto\dhcplogs\today.log del d:\auto\dhcplogs\today.log

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.

REM this script uses the postie.exe utility from
d:\auto\postie.exe -s:%SENDLINE% -file:d:\auto\dhcplogs\%date%.log -gmt
goto :EOF

REM This is the guts of the process.
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
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)
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?
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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.
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.
hmmm i have followed that numerous times - are they different versions of 2003? R2 and standard etc?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2003

From novice to tech pro — start learning today.