(fwd) Re: rsync and named-xfer

Craig Sanders cas at taz.net.au
Fri Jul 27 11:05:07 EST 2001

i'm posting this to the bind-users and rsync mailing lists in order to
get this archived for the next person who needs to do this :)

comments and suggestions are welcome, but please cc: to me because i'm
not subscribed to either list.


----- Forwarded message from Craig Sanders <cas at taz.net.au> -----

Date: Fri, 27 Jul 2001 10:30:20 +1000
From: Craig Sanders <cas at taz.net.au>
To: debian-isp at lists.debian.org
Subject: Re: rsync and named-xfer
User-Agent: Mutt/1.3.18i
X-Mailing-List: <debian-isp at lists.debian.org> archive/latest/7138

On Thu, Jul 26, 2001 at 05:51:03PM +1000, Craig Sanders wrote:
> has anyone used rsync to transfer zone files?
> i'm thinking of writing a wrapper script which runs rsync to transfer
> some domains, and falls back to named-xfer for other domains.

ok, i've figured out how to do this and got it running between two of my
own name servers. 

there's two sides to the configuration, server side and client side.

i hope this is useful to someone...there was no information at all on
the topic when i searched for it on google yesterday.


1. install rsync and add something like the following to /etc/inetd.conf
to run it as a daemon:

rsync	stream	tcp	nowait	root	/usr/sbin/tcpd	/usr/bin/rsync --daemon

2. edit /etc/rsyncd.conf like so:

---cut here---
syslog facility  = daemon

	comment = zonefiles for rsync transfer
	path = /var/cache/bind/rsync
	read only = yes
    # see rsyncd.conf(5) for details on hosts allow specification
	hosts allow = a.a.a.a b.b.b.b c.c.c.c    ...etc...

---cut here---

/var/cache/bind/rsync is the directory containing the rsyncable zone
file(s). this should be a dedicated subdirectory with only the zonefiles
you want to be fetchable via rsync in it.

your zone file configuration in named.conf should look something like this:

zone "example.com" {
	type master;
	file "rsync/example.com.db";

whenever you edit the file and run "ndc reload", a NOTIFY will be sent
to the secondaries. this will cause them to run named-xfer to transfer
the updated zone. if any of the secondaries have the client-side set up
as below, then the transfer will be done with rsync rather than slow

for small zonefiles, this makes no difference (in fact, the rsync
protocol overhead may be a net loss), but for large zonefiles (e.g. a
16MB dnsrbl type zonefile) it makes an enormous difference - only a
hundred kilobytes or so transferred rather than the full 16MB.


1. install rsync

2. configure named as usual to secondary the zone.  e.g.

zone "example.com" {
        type slave;
        file "example.com.db";
        masters {
                x.x.x.x;   // doesn't matter

you have to specify the masters { ... } section, but it will be ignored
by the rsync named-xfer. you tell it where to fetch the zonefile from in
the named-rsync.conf file.

3. create an /etc/bind/named-rsync.conf file like so:

---cut here---
# domain        hostname/ip     rsync_SRC   filename
example.com		x.x.x.x			zonefile    example.com.db
---cut here---

this will cause rsync to fetch x.x.x.x::zonefile/example.com.db

this version requires you to specify the hostname to fetch the zonefile
from...a future version may extract that information from the named-xfer
command line.

3. create the following script, /usr/local/sbin/named-xfer.pl

---cut here---
#! /usr/bin/perl 

# named-xfer.pl
# transfer zone files using rsync.  falls back to
# standard named-xfer for zones not listed in
# /etc/bind/named-rsync.conf
# Copyright Craig Sanders <cas at taz.net.au> 2001
# This software is licensed under the terms of the GNU
# General Public License.

# configuration variables.  adjust to suit your system
$dir="/var/cache/bind" ;
$realxfer="/usr/sbin/named-xfer" ;
$rsync="/usr/bin/rsync" ;

# read in the config file
# format is:
# domain	hostname/ip		rsync_SRC	filename
open(CONF,"<$conffile") || warn "couldn't open $conffile: $!" ;
while(<CONF>) {
	chomp ;
	next if (/^$/) ;
	($domain,$hostname,$src,$filename) = split ;
	$rsync{$domain} = "$hostname:$src:$filename" ;
close(CONF) ;

# extract useful info from command line args...
for $i (0.. at ARGV) {
	if ($ARGV[$i] eq "-z") { $domain = $ARGV[++$i] } ;
	if ($ARGV[$i] eq "-f") { $zonefile = $ARGV[++$i] } ;

# do the transfer
if ($rsync{$domain}) {
	($hostname,$src,$filename) = split /:/, $rsync{$domain} ;
	exec("rsync","$hostname\:\:$src/$filename","$dir/$zonefile") ;
} else {
	exec($realxfer, at ARGV) ;
} ;
---cut here---

4. now edit /etc/bind/named.conf and tell bind to use the above script
instead of the standard named-xfer by adding the following line to the
options {...} ; section:

	named-xfer "/usr/local/sbin/named-xfer.pl" ;


craig sanders <cas at taz.net.au>

Fabricati Diem, PVNC.
 -- motto of the Ankh-Morpork City Watch

To UNSUBSCRIBE, email to debian-isp-request at lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster at lists.debian.org

----- End forwarded message -----

More information about the rsync mailing list