nt_export_djb.pl error in files_diff

Started by monachus, September 15, 2009, 01:15:59 AM

Previous topic - Next topic

monachus

The file nt_export_djb.pl has a sub called files_diff which looks to do the md5 checksums of "data" and "data.orig" to determine if it should rsync the data.  When this is run the first time for a new nameserver, it fails with the error:

No filehandle passed at /usr/local/sbin/nt_export_djb.pl line 528.

This seems to be because "data.orig" doesn't exist yet - it only just exported "data" from the database.  When this fails, no rsync is performed to the remote nameserver.  The next time that nt_export_djb.pl is run, data is renamed to data.orig and the files are diffed again with no changes, and the rsync is still not performed:

[02:59 AM] 74 [/service/nictool-a-ns-web-client]:dns-1% envdir ./env /usr/local/sbin/nt_export_djb.pl -nsid 36 -r -md5 -force -buildcdb
building data.cdb for a.ns.web.client.org
a.ns.web.client.org: build_data: 0 build_cdb: 0 rsync_cdb: 0


Thus, for a new nameserver, no data is written out until the actual DNS information changes.

To work around this I added a line to files_diff that checks to make sure the file it's about to MD5 exists, returning -1 if it doesn't find it.  The result is a successful initial rsync:

[03:06 AM] 83 [/service/nictool-a-ns-web-client]:dns-1% envdir ./env /usr/local/sbin/nt_export_djb.pl -nsid 36 -r -md5 -force -buildcdb
building data.cdb for a.ns.web.client.org
Checksums differ: doing rsync
rsync try #0 ..
/usr/bin/rsync -az -e ssh data.cdb tinydns@x.x.x.x:/etc/tinydns/root/data.cdb
rsync: finished
a.ns.web.client.org: build_data: 0 build_cdb: 1 rsync_cdb: 0


Here's the patch:

diff -u nt_export_djb.pl.orig nt_export_djb.pl
--- nt_export_djb.pl.orig 2009-09-15 03:07:42.000000000 -0400
+++ nt_export_djb.pl 2009-09-15 03:07:25.000000000 -0400
@@ -515,6 +515,7 @@
     return -1 unless scalar @files eq 2;
     my @md5sums;
     foreach my $f (@files) {
+        return -1 unless ( -f $f );
         my $ctx = Digest::MD5->new;
         my $sum;
         if ( -f "$f.md5" ) {
Adrian Goins - President / CEO
Arces Network, LLC
http://www.arces.net

PGP Key: 1024D/8AADA4B8 2009-04-20
Fingerprint: E3CD 96EA DF3F B345 7ADB  FB74 31EC 9F54 8AAD A4B8

matt