New Script to synchronize DomainZone files between DirectAdmin Servers

judab2

Verified User
Joined
Feb 14, 2006
Messages
24
Hi All,


I have created a script which basicly synchronize all DNS zones from a remote
DirectAdmin server,

the script can be usefull for creating a secondary DNS without doing a MultiServers Link in the DA,

It also can be use if you want to create a secondary DNS that will do only DNS without panel at all.

For automation script i used SSH public/private key infastracutre,
i will be happy to hear your comments.


#----------------- Code From Here
#!/bin/bash
# All Rights reserverd Juda Barnes (c) 2010
# This Script is usefull to copy all DNS domain files from a remote
# directadmin server to your local server
# it can be usefull to create secondary DNS server to several directadmin
# servers without using the DIRECTADMIN MultiServer synch option
#
# Basicly if you addent to have a secondary linux server that use for
# Secondary DNS then you shall run the script from the secondary server
# the script will remote copy *.db files from the remote directadmin server
# and also copy the servered domains from the remote directadmin server
# all the necesery files will be copied localy to directory /etc/bind/transfer
# and the IP Address of the server
# after you run the script you will have a file /etc/bind/transfer/named.ip.conf
# just load this configuration file to your orginal named.conf
# and you can start run a secondary dns server
# without use the DA MultiServer option
#
# ------------------------------------------------------------------------
# Parameters that need to be added when you run the command
# $1 Remote directAdmin server IP Address
# $2 Local Ident file to be use for remote ssh FILE
# $3 Remote username to be used

# For example
# ./get-domain.sh 222.222.222.222 /home/myuser/my-private-key judab
#

# Confiure remote user
# It is suggested not to use root as remote user
# Therefore i have created user name judab
# i have generated public/private key and copy the public key signature
# to the remote user directory into /home/judab/.ssh/authorized_keys file
# You can find information how to generate the Signature in this Link
# http://troy.jdmz.net/rsync/index.html
REMOTEUSER="$3"
# This user shall have access to read /etc/virtual/domains
# And to read /etc/bind/* files
#



#-------------------------------


if [ "$1" = "" ] ; then
echo Error: Please sepcifiy server IP Address
echo Syntax ./get-domain [remote server] [ident file] [remote username]

exit
else
echo start copy domains from server $1
fi

if [ "$2" = "" ] ; then
echo Error: No ident file
echo Syntax ./get-domain [remote server] [ident file] [remote username]
exit
else
echo Using ident
fi

if [ "$3" = "" ] ; then
echo Error: No remote user speicifed
echo Syntax ./get-domain [remote server] [ident file] [remote username]
exit
else
echo Using username $3
fi

if [ "$3" = "root" ] ; then
echo Error: You can not use root remote account for security reason
echo Syntax ./get-domain [remote server] [ident file] [remote username]
exit
fi


#Check server alive
ping -c 1 $1 > /dev/null

if [ "$?" = "0" ] ; then
echo Server alive
else
echo Server is not answering ping.. exiting ..
exit 1
fi


#mkdir
mkdir /etc/bind/transfer
mkdir /etc/bind/transfer/$1

#Copy Domain Files
scp -B -i $2 $REMOTEUSER@$1:/etc/bind/*.db /etc/bind/transfer/$1

if [ "$?" = "0" ] ; then
echo Copy name File OK
else
echo Copy Name file FAIL .
exit 1
fi



scp -B -i $2 $REMOTEUSER@$1:/etc/virtual/domains /etc/bind/transfer/$1

if [ "$?" = "0" ] ; then
echo Copy Domain list OK
else
echo Copy Domain list FAIL .
exit 1
fi


cd /etc/bind/transfer/$1
echo Generate conf fle
cat domains | awk -v namesrv=$1 '{ print "zone \"" $1 "\"" " { type master; file
\"/etc/bind/transfer/" namesrv "/" $1 ".db\"; }; " }' > /etc/bind/trans
fer/named.$1.conf


#------------------ End of File
 
It looks a bit easier to use than my Master2Slave DNS Replicator (nobaloney.net) which I paid to have written a few years ago and put into the GNU General Public License version 2.0 (GPLv2).

I haven't completely studied it but at first glance it looks a bit simplistic.

How, for example, doesit handle duplicates (if one domain has a DNS record on two servers)?

Does it store slave records (records for domains not on that server) in a separate directory?

Does it store the named.conf zone file lines in separate files so you can easily see which came from which server?

When something fails does it send an email to an easily defined email address?

Jeff
 
Hi,
Actually i use the current directory stracture of bind and add to it
a new stracture to store the *.db files ,


so i have
/etc/bind - where usually *.db files are stored

then i added another directory

/etc/bind/transfer

the new directory will contain all the *.db files from all replicate servers

for example i have
/etc/bind/transfer/194.90.1.5/*.db this directory contain all the *.db files from server 194.90.1.5
/etc/bind/transfer/199.203.1.20/*.db this directory contain all the *.db files from server 199.203.1.20

so basicly you have sort of arrange and stracture

now for named.conf file i prefer to regenerate a named.conf for each server ,
insted of copy from the remote server (because the remote server possible wont work) so i regenerate and store the named.conf for each server
in seperate file , all the configuration files are stored with convenstion that inlcude the server ip address so it will be easy to track it down
for example:

/etc/bind/transfer/named.194.90.1.5.conf
/etc/bind/transfer/named.199.203.1.20.conf


now all you have to do is to add single time a the configuration file to your existing named.conf
and thats it,



I do not have error handling or alert, it's very easy to add this functionality i will add it and post a link,


regarding duplicates the script is pooling all *.db files , and use the /etc/virtual/domains list
so basicly this procedure will avoid duplication,
 
so i have
/etc/bind - where usually *.db files are stored
What OS Distribution did you use for this? I ask because every installation of BIND I've used always puts db files in /var/named, but of course I don't use all distributions.
regarding duplicates the script is pooling all *.db files , and use the /etc/virtual/domains list so basicly this procedure will avoid duplication
I'm lost a bit... do you clear duplicates from the named.conf file? That's critical, as otherwise BIND may not even start (I've seen this behavior).

And what do you do if one version of the .db file is different from the other? Is there an order to which one is used (for example the oldest file, the newest)?

I believe I understand that you keep separate lists for each server in named.conf, but all your zone files together.

Thanks.

I don't know if you've ever looked at my Master2Slave DNS Replicator; we replicate only the zone files (similarly to how you do it) and we use standard master-slave functionality built into BIND to get new zone files. We keep zone files by server, but all records in the same named.conf file.

Just two different ways of looking at it, but I believe the duplicate-finding provision is important and in fact it took us more time to get it right than everything else combined.

Ours was never properly finished and taken out of beta because though it works, my programmer (who I paid to do the project) has disappeared and I don't feel comfortable bringing it out of beta since I don't feel comfortable working on it on an emergency basis.

So maybe once yours meets my requirements :) I can pull mine out of circulation.

Jeff
 
Back
Top