dhcp backup restore netsh

A couple of things. I did a netsh dhcp show server and 4 servers were found in the directory services.
Only one server is the dhcp server, the other 3 do not exist any longer. their Directory service Ds location: cn= , etc. How do I remove those 3 bad entries?
Also I did a copy bat file in task scheduler to copy the contents from c:\windows\system32\dhcp\backup to another DC server to a mapped Z drive. This will run everyday at 6pm.
What is the process for restoring this dhcp db if my primary dhcp server fails.
both servers are virtual enterprise windows 2008 sp2 servers
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.

Logon to root Domain DC as member of domain admins \ enterprise admins ID and load configuration partition in Adsiedit.msc tool
The tool is available under Start\administrative tools
Then navigate to Configuration\services\Net Services
There you will find all authorized DHCP servers in active directory, just delete unwanted server from there and force AD replication
At same place above you will find DHCPRoot, go to its properties and navigate to DHCPServers attribute, double click it and ensure that there are no stale DHCP server entry left, if found, just delete it as well.
Again force AD replication.
This will remove unwanted DHCP servers from AD

The process of exporting DHCP scope from one server and importing it on another server is pretty straight forward. User netsh command for that, Check below article for step by step

jim3725Author Commented:
Mahesh,  I launched the adsiedit and i only see the default naming conxted for my domain , plus the CN= computers, CN=Bulletin, CN=Domain Controllers. I don't see where to  navigate to Configuration\services\Net Services
This is great info, but I need alittle more help.
jim3725Author Commented:
Also, I am not able to located the export command within my DC1 server, so I can do the export
The following command exports the full service configuration to the c:\Temp\Dhcpdb file:
export c:\temp\dhcpdb all
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

In adsiedit.msc right click adsiedit and click connect to
Under "Select well known naming context" radio button, from drop down list, select Configuration and click OK

For export and import, you need to 1st get into netsh prompt

Open elevated command prompt on DHCP server
Then type Netsh and hit enter
Then type Dhcp server \\DHCPServerName - logged on server
Then type export c:\temp\dhcpdb all
This will backup \ export DHCP server database.

Copy this DHCP server backup folder to new DHCP server where you want to restore Database
Now from elevated command prompt run Netsh and hit enter
Then type Dhcp server \\DHCPServerName - logged on server
Then type import c:\temp\dhcpdb all
This will restore \ import DHCP server database to new server

The both links shown in earlier already mentioned all these steps, you forgot to run netsh from elevated command prompt
jim3725Author Commented:
Mahesh, I found the netservices. and deleted the entries. How do I force AD replication ?
I appreciate your explanations, they are very helpfull
jim3725Author Commented:
Do I just go to Action and update schema now for AD replication?
Logon to domain controller
From elevated command prompt run repadmin /syncall command
This command will force D replication
U may run this command on every domain controller OR AD replication will automatically takes place after 3 HRS
jim3725Author Commented:
quick question: If on my other server that I would run the import command on, If the server does not have dhcp server activated, cause I don't want to activate , but will the import command work, if dhcp is not active?
Just wanted to ask.
Import will work, you can later authorize DHCP server

DHCP server service get stopped automatically before you import database
jim3725Author Commented:
Mahesh, I added the dhcp server role on to my other dc.
I rebooted server. I am not able to unauthorize it when the service is started.  It's says parameter is incorrect when I try to unauthorize it. I currently have dhcp server service disabled. Not sure if if can do the import they way it stands now.
I'm hesitant on enabling this, I haven't added any scope parameters.  My goal was to have a 2nd dhcp ready incase their my primary dhcp server failed.
jim3725Author Commented:
I got the following error message then trying to do import see attatchment.
Option 6 is dns entry, and is the server that I 'm trying the import on.
If its already authorized, no need to unauthorized it.

The error message is came because existing DNS entry is got created under DHCP server options during your initial DHCP installation \ setup

Start the DHCP server service for time being and Go to server options on DHCP server snap-ins and remove the option 6 dns option

Then restore DHCP database (Import with Netsh) and check if everything is restored correctly, then stop and disable DHCP service and let me know if it works.
jim3725Author Commented:
mahesh, This worked sucessfully. Is it best to just do a manual export and import weekly to keep a current copy on the spare dhcp server?
jim3725Author Commented:
Mahesh, I also validated that the spare server is an  authorized DHCP servers in active directory.
thanks again for your help
No need to import every week on spare DHCP server to make it current.

All you need to do is, just set some thing like .bat file to backup DHCP DB from Netsh export command and make it schedule task on primary server on daily or weekly basis.

Any time you wanted to bring spare server online, just ensure that this server goes offline and start dhcp service on spare server and import DHCP from backup above

Ex bat file

Dhcp server \\DHCPServerName
export c:\temp\dhcpdb all

If you created this type of .bat script, its output will get overwritten every time by new output and you will get latest backup copy if required.

As additional measure you can backup this already backed up DB to another location if required
jim3725Author Commented:
Mahesh, I tried this as a bat file, and It didn't overwrite it, Can you take a look at it.
the task history says task dhcp-export sucessfully completed cation "c:\windows\system32\cmd.exe" with return code 1.
I didn't see the date change on the c:\temp\dhcpdb file
I think its refusing to overwrite

You can rename old dhcp db and check if new file gets created

In that case you can delete old file after backing it to else location
also copy command should be
copy c:\temp\* z:\
jim3725Author Commented:
When I run this from command line, it works fine for exporting, it takes about 5-10 sec.
When I use the batch file it doesn't seem to wait long enough before it goes on to the next command for copying, so the dhcpdb file in c:\temp isn't created yet.
jim3725Author Commented:
How do I get out of the command when the export is finished, I am still in the netsh > prompt.
I've tried quit or exit but that doesn't work.

By default, Windows Server automatically backs up the DHCP database files and registry configuration every 60 minutes and saves the backed up information in the \System32\DHCP\Backup folder

try below command to backup dhcp through netsh instead of export
This can be imported through netsh if wanted to

netsh dhcp server \\servername backup destdir
netsh dhcp server backup C:\Backups\DHCP

If you didn't mention dhcp server name \ IP, it will assume local server
This will back up DHCP registry configuration and DHCP database file (.mdb format) to the destinated folder.
jim3725Author Commented:
This works better in the batch file. Do I do a restore on the spare server, what's the command to replace the import side since it's a mdb file ?
I have not tested, but you should be able to restore dhcp backup with netsh import command, you need to provide import path with .mdb extension.
Please test it.

Sorry to say, but I haven't played with DHCP backup and restore much.
I always used to backup %systemroot%\dhcp\backup folder
My dhcp server is installed on DC, as a fact it is getting backed up automatically with System State backup.
In case if wanted to restore I use method mentioned in below article

Only above method don't work correctly if DHCP server OS are different, (Ex: source 2003 and destination 2008), that is why I suggested you netsh method.
Only thing I note down dhcp reservations in additions to above method, so in case even if I failed to restore DHCP, I can manually create scopes as required and later on create reservations.
One might don't like this as he might have 100's of DHCP scopes

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
jim3725Author Commented:
Thanks Mahesh for assisting me. I do a BMR on these two windows 2008 servers, so i could restore these files from that source if needed. I will try the netsh with mdb extension and see how it works, along with documenting the scope.
Seth SimmonsSr. Systems AdministratorCommented:
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
jim3725Author Commented:
very helpful throughout the entire process.
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 2008

From novice to tech pro — start learning today.