[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pdns-users
Subject:    [Pdns-users] FW:  Deleted DNS Records not Removing from Slave
From:       "Mark Scholten" <mark () streamservice ! nl>
Date:       2010-07-28 20:42:09
Message-ID: 012801cb2e95$597f4970$0c7ddc50$ () nl
[Download RAW message or body]

Hello,

I did forget to add the script, now it's attached. It is made to be used
from the command line interface (php pdns_clean.php).

With kind regards,

Mark Scholten

-----Original Message-----
From: Mark Scholten [mailto:mark@streamservice.nl] 
Sent: Wednesday, July 28, 2010 10:41 PM
To: 'pdns-users@mailman.powerdns.com'
Cc: 'fredj toukebri'
Subject: RE: [Pdns-users] Deleted DNS Records not Removing from Slave

Hello,

Sorry for the delay, attached is a working file that tries to do a AXFR (so
you need to run it on a server that is allowed to receive AXFR from the
(hidden) master). It uses PHP and dig. It is tested on Debian (4 and 5)
systems.

At the top there is a small configuration part (database connection/test or
not/verbose or not).

The license is included at the top of the script (above the configuration
section).

Tips:
- Do the first run with $test = 1 and $verbose = 1 to see if it does work in
your situation.
- Set $verbose = 0 if you want to use it in a cron (no output except if
there is a PHP/MySQL problem)
- I advise to do the first run with deleting zones without using a cron,
just to check it

Please contact me off list with improvements/problems. If someone wants to
include it with powerdns, feel free to include it (please respect the
license).

With kind regards,

Mark Scholten

> -----Original Message-----
> From: pdns-users-bounces@mailman.powerdns.com [mailto:pdns-users-
> bounces@mailman.powerdns.com] On Behalf Of Mark Scholten
> Sent: Saturday, June 26, 2010 12:02 PM
> To: 'Nils Breunese (Lemonbit)'; pdns-users@mailman.powerdns.com
> Subject: Re: [Pdns-users] Deleted DNS Records not Removing from Slave
> 
> 
> 
> > -----Original Message-----
> > From: pdns-users-bounces@mailman.powerdns.com [mailto:pdns-users-
> > bounces@mailman.powerdns.com] On Behalf Of Nils Breunese (Lemonbit)
> > Sent: Saturday, June 26, 2010 11:58 AM
> > To: pdns-users@mailman.powerdns.com
> > Subject: Re: [Pdns-users] Deleted DNS Records not Removing from Slave
> >
> > Brandon Lee wrote:
> >
> > > We have 2 PDNS servers using the MySQL backend.  Both servers have
> > their own MySQL database.  When inserting a DNS record, or making
> > changes the record is updated by the slave server.  However, when a
> > record is deleted, the record is not being deleted from the slave
> > server.  Is there some additional configuration option that must be
> > set, or is it not possible for the slave to delete records?
> >
> > AFAIK you'll need to manually remove the zone from the slave if your
> > servers use independent database backends as I don't think there is a
> > way for the master to notify slaves of a removed zone. Please correct
> > me if I'm wrong.
> >
> > You can solve this by setting up replication or sharing the database
> if
> > that's possible in your situation. I have a server which is a slave
> to
> > multiple supermasters, so I'm kind of stuck with the same problem
> > there.
> I did write a small PHP script for that. It checks the master (based on
> the
> IP listed in the MySQL database used by the slave) to see if a zone
> still
> exists. It records it when it doesn't get a response containing the SOA
> record (as I require the SOA record). It also records the reason (if
> known),
> for example a time out is different compared to an "I don't
> know"/"doesn't
> exist"/"recursion not allowed" response. After getting 3 times a
> response
> saying the zone doesn't exist the zone is dropped on the slave. On
> request I
> can share that PHP script with the community (it works using a cron on
> a
> daily base).
> 
> Mark
> >
> > Nils.
> > _______________________________________________
> > Pdns-users mailing list
> > Pdns-users@mailman.powerdns.com
> > http://mailman.powerdns.com/mailman/listinfo/pdns-users
> 
> _______________________________________________
> Pdns-users mailing list
> Pdns-users@mailman.powerdns.com
> http://mailman.powerdns.com/mailman/listinfo/pdns-users

["pdns_clean.php" (application/octet-stream)]

<?php
############################### LICENSE ###################################
# 1. You are allowed to do everything with it you like, but with the exceptions \
below: # 1a. Don't use it to do illegal things.
# 1b. You didn't create it (Mark Scholten, mark@mscholten.eu, did create it), so \
don't say to others that you did create it. # 2. This script/software comes without \
guaranteed support or any other guarantee; use it on your own risk! The creator isn't \
responsible for using it and doesn't accept any responsibility # 3. Support might be \
available (look at mscholten.eu for the ways to get support and to see if support is \
available, you can also try to email to mark@mscholten.eu if support on mscholten.eu \
is not available). # 4. Commercial use is allowed.
# 5. Distribution is allowed, asking money for it is allowed. Using it in other \
scripts is allowed as long as you respect point 1/1a/1b in this license. \
############################### END LICENSE ################################

// configuration section
mysql_connect(  'localhost', // host
				'mysql username', //username
				'mysql pass'); //pass
mysql_select_db('mysql database');
$test = 1; // change to 0 to delete records/domains, if set to something else it will \
not delete anything $verbose = 1; // set to 1 to be verbose (output domainnames that \
are deleted/are to be deleted (depending on the $test setting)

// no configuration below this line

	function is_stil_active($domain,$server){
		$axfr = shell_exec("dig AXFR ".$domain." @".$server."");
		$explode = explode("XFR size:",$axfr);
		if(isset($explode['1'])){
			return TRUE;
		}else{
			return FALSE;
		}
	}

$sql3 = "SELECT `id`,`name`,`master` FROM domains WHERE `type`='SLAVE'";
$query = mysql_query($sql3) or die(mysql_error());
if(mysql_num_rows($query) == FALSE){
}else{
	while($record = mysql_fetch_object($query)){
		if(!is_stil_active($record->name,$record->master)){
			if($test === 0){
				mysql_query("DELETE FROM domains WHERE id='".$record->id."'") or \
die(mysql_error());  mysql_query("DELETE FROM records WHERE \
domain_id='".$record->id."'") or die(mysql_error());  }
			if($verbose === 1){
				echo $record->name."
";
			}
		}
	}
	if($verbose === 1){
		echo "Done
";
	}
}
?>



_______________________________________________
Pdns-users mailing list
Pdns-users@mailman.powerdns.com
http://mailman.powerdns.com/mailman/listinfo/pdns-users


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic