Index: [Article Count Order] [Thread]

Date:  Wed, 22 Oct 2008 21:22:41 +0200
From:  Michael Stauber <bq (at mark) solarspeed.net>
Subject:  [coba-e:14205] Re: Mass updating DNS
To:  coba-e (at mark) bluequartz.org
Message-Id:  <200810222122.41905.bq (at mark) solarspeed.net>
In-Reply-To:  <1224701337.17833.27.camel (at mark) columbus.webtent.org>
References:  <1224701337.17833.27.camel (at mark) columbus.webtent.org>
X-Mail-Count: 14205

Hi Robert,

> Has anyone yet figured out how to do mass updates to the DNS records on
> the CentOS+BQ without having to update individual records? I need to
> update all mx records for many domains. I can write a Perl script to
> handle mass file changes, but they'll be lost after using the GUI,
> correct?

Here is a quick an dirty script that I once wrote for DNS mass IP changes:

#----------------------------------------------------------------------------------
#!/usr/bin/perl -I/usr/sausalito/perl
# $Id: dns-masschange2.pl, v1.1.0.0
# Mon 23 Apr 2008 04:30:09 PM CEST mstauber Exp $
# Copyright 2006-2008 Solarspeed Ltd. All rights reserved.

use CCE;
my $cce = new CCE;

$cce->connectuds();

$oldip = '10.0.1.1';
$newip = '192.168.1.1';

&feedthemonster;
&setdirty;

$cce->bye('SUCCESS');
exit(0);

sub feedthemonster {
    (@oids) = $cce->find('DnsRecord', { 'ipaddr' => $oldip });
        for $object (@oids) {
            print $object . "\n";
                ($ok) = $cce->set($object, '',{
                    'ipaddr' => $newip
                });
        }
}

sub setdirty {
    # Get 'System' details:
    @system_main = $cce->find('System');
    if (!defined($system_main[0])) {
        print "Sorry, no 'System' object found in CCE!\n";
        exit(1);
    }
    else {
        # Build Records:
        #($ok, $my_system_main) = $cce->get($system_main[0]);
        ($ok) = $cce->set($system_main[0], 'DNS', {
            'dirty' => time()
        });
    }
}
#----------------------------------------------------------------------------------

What it does is the following:

It looks through the GUI's CODB database to find all "DnsRecord" entries with 
the given old IP address. Each and any record with the old IP address will be 
changed to the new IP address specified in that script.

When it has changed all records, then it will update the switch "dirty" in the 
DNS Namespace of  the System object. Whenever that is done, the changes made 
to the DNS entries in the backend are pushed out to the filesystem. 

That means: At that point the updated DNS record files are written and Bind is 
restarted.

-- 
With best regards,

Michael Stauber