How to restore DNS Zones on cPanel server

How to restore DNS Zones on cPanel server

Well, it is very rare to have DNS Zone get disappear from cpanel server. But, we heard about this problem when any administration error occurs or due to any bind package update on server. Whatever the case, we may be able to restore the missing DNS Zones or Recreate it.

As we know the server itself not behave as Nameserver whole, but still there are some functions within cPanel that require the DNS Zones to exist in server locally.

These DNS records may be or may not be clustered with cPanel DNSONLY server.

Restoring DNS Zones from DNS cluster:-

If you have clustered your cPanel server with any other server then it will be more easy to restore your cPanel records. What you have to do is just sync the DNS Zones from this server to the server which is clustered with your cPanel server. The way to make it possible is quite easy, you have to run a Python script on your cPanel server.

It will dig out all list of domains(main, add-on domains, parked domains) from cPanel server and sync it back to your cPanel server.

Point to keep in mind is you have to make sure that your remote Server's DNS cluster is already set to "synchronize" status. This can be done through :

1). Through WHM:

Login to your WHM account >> click on "Clusters" >> Click on "Configuration Cluster" >> set cluster's role to "Synchronize changes"
cluster.png

OR

2). Through script:

You can do this through script also. For that you have to run below command by replacing your IP of your DNS server(also keep in mind that 'root' is used if it for the server itself. You have to use your username if you are a reseller).

echo -n "sync">/var/cpanel/cluster/"root-or-reseller-usaername"/config/"IP address"

Now you have to create a file and name it as "syncdnszones.py" on server and file permission should be 755. Paste the content given below.

--------------
#!/usr/bin/env python
import os
import subprocess
import yaml

data_dir = '/var/cpanel/userdata'
user_list = os.listdir('/var/cpanel/users')

for user in user_list:

data_file = '%s/%s/main' % (data_dir, user)

data_map = None

try:

f = open(data_file, 'r')

data_map = yaml.load(f)

f.close()

except:

pass

if data_map is not None:

domains = []

domains.append(data_map['main_domain'])

domains.extend(data_map['parked_domains'])

for addon in data_map['addon_domains']:

domains.append(addon)

for domain in domains:

subprocess.call(['/scripts/dnscluster', 'synczone', domain])

-------------

Now, you have to run this script and after that all your missing zones will be restored to your cPanel server from remote server.


If you have have no other clustered server linked to your cPanel server, then you have only one choice either you have to re-create the DNS Zones again or you have to restore them from backup.


Restoring DNS Zones from backup:-

Let us assume you have already taken backup of your cPanel server which is in your cPanel backup directory. If you have no idea about the backup directory you can check it throguh WHM >> "Backup" >> "Backup configuration" >> "Configure Backup Directory"
backup.png

Let us assume your backup directory is "/backup". To restore backup from here kindly run the below given command.

---------------
tar -C/-xvf_var_named.tar.gz
---------------

Recreating the DNS Zones:-

You have only this way to recreate DNS Zones if you have no backup or remote DNS clusters.

You can re-create the DNS Zones through adddns script which is directly provide by cPanel.inc

------
/scripts/adddns<yourdomainname.com><IPaddress>
------

You have to use IP as your server main IP. This script will recreate the Default DNS zone, so any modification which was done previously by you will be gone.
Author
Bhawani Singh
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from Bhawani Singh

Top