Do you have many “old” cPanel servers? Perhaps you have the cpanel servers configured in a DNS cluster for redudancy? If so, you may encounter the same problem as I did where you have “stale” (or old) DNS zones cluttering up the server. Here’s a script to get rid of any unused zone files (use at your own risk yadda yadda yadda – you will have to rebuild /etc/named.conf afterwards):
It’ll first take a copy of the DNS zones (into /root/oldzones ), then pull out all the domain names in /etc/localdomains and /etc/remotedomains and /etc/secondarymx and copy those zone files to the temporary /root/newzones folder.
It’ll then clear down the /var/named/ folder totally (the multiple rm commands are there because you could have several thousand files there: yes, I know this could be cleared up by using find . -type f -name...
style syntax: but it was a “quickly hacked together” script). It then copies all the files from /root/newzones to /var/named ready for you to rebuild /etc/named.conf !
#!/usr/bin/perl
system("rm -rf /root/newzones");
system("rm -rf /root/oldzones");
system("mkdir /root/oldzones");
system("rsync -ar /var/named/ /root/oldzones/");
system("mkdir /root/newzones");
open(VA,"< /etc/localdomains") || die("Unable to open /etc/localdomains");
$zonecount=0;
while (<VA>) {
$filename=$_;
$filename=~s/\n//g;
$filename=$filename.'.db';
$source='/var/named/'.$filename;
$dest='/root/newzones/'.$filename;
$command="cp $source $dest";
system($command);
$zonecount++;
}
close (VA);
open(VA,"< /etc/remotedomains") || die("Unable to open /etc/remoteldomains");
$zonecount=0;
while (<VA>) {
$filename=$_;
$filename=~s/\n//g;
$filename=$filename.'.db';
$source='/var/named/'.$filename;
$dest='/root/newzones/'.$filename;
$command="cp $source $dest";
system($command);
$zonecount++;
}
close (VA);
open(VA,"< /etc/secondarymx") || die("Unable to open /etc/secondarymx");
$zonecount=0;
while (<VA>) {
$filename=$_;
$filename=~s/\n//g;
$filename=$filename.'.db';
$source='/var/named/'.$filename;
$dest='/root/newzones/'.$filename;
$command="cp $source $dest";
system($command);
$zonecount++;
}
close (VA);
print "Zones:$zonecount\n";
system("rm -rf /var/named/a*.db");
system("rm -rf /var/named/b*.db");
system("rm -rf /var/named/c*.db");
system("rm -rf /var/named/d*.db");
system("rm -rf /var/named/e*.db");
system("rm -rf /var/named/f*.db");
system("rm -rf /var/named/g*.db");
system("rm -rf /var/named/h*.db");
system("rm -rf /var/named/i*.db");
system("rm -rf /var/named/j*.db");
system("rm -rf /var/named/k*.db");
system("rm -rf /var/named/l*.db");
system("rm -rf /var/named/m*.db");
system("rm -rf /var/named/n*.db");
system("rm -rf /var/named/o*.db");
system("rm -rf /var/named/p*.db");
system("rm -rf /var/named/q*.db");
system("rm -rf /var/named/r*.db");
system("rm -rf /var/named/s*.db");
system("rm -rf /var/named/t*.db");
system("rm -rf /var/named/u*.db");
system("rm -rf /var/named/v*.db");
system("rm -rf /var/named/w*.db");
system("rm -rf /var/named/x*.db");
system("rm -rf /var/named/y*.db");
system("rm -rf /var/named/z*.db");
system("rm -rf /var/named/0*.db");
system("rm -rf /var/named/1*.db");
system("rm -rf /var/named/2*.db");
system("rm -rf /var/named/3*.db");
system("rm -rf /var/named/4*.db");
system("rm -rf /var/named/5*.db");
system("rm -rf /var/named/6*.db");
system("rm -rf /var/named/7*.db");
system("rm -rf /var/named/8*.db");
system("rm -rf /var/named/9*.db");
system("rm -rf /var/named/a*.bak");
system("rm -rf /var/named/b*.bak");
system("rm -rf /var/named/c*.bak");
system("rm -rf /var/named/d*.bak");
system("rm -rf /var/named/e*.bak");
system("rm -rf /var/named/f*.bak");
system("rm -rf /var/named/g*.bak");
system("rm -rf /var/named/h*.bak");
system("rm -rf /var/named/i*.bak");
system("rm -rf /var/named/j*.bak");
system("rm -rf /var/named/k*.bak");
system("rm -rf /var/named/l*.bak");
system("rm -rf /var/named/m*.bak");
system("rm -rf /var/named/n*.bak");
system("rm -rf /var/named/o*.bak");
system("rm -rf /var/named/p*.bak");
system("rm -rf /var/named/q*.bak");
system("rm -rf /var/named/r*.bak");
system("rm -rf /var/named/s*.bak");
system("rm -rf /var/named/t*.bak");
system("rm -rf /var/named/u*.bak");
system("rm -rf /var/named/v*.bak");
system("rm -rf /var/named/w*.bak");
system("rm -rf /var/named/x*.bak");
system("rm -rf /var/named/y*.bak");
system("rm -rf /var/named/z*.bak");
system("rm -rf /var/named/0*.bak");
system("rm -rf /var/named/1*.bak");
system("rm -rf /var/named/2*.bak");
system("rm -rf /var/named/3*.bak");
system("rm -rf /var/named/4*.bak");
system("rm -rf /var/named/5*.bak");
system("rm -rf /var/named/6*.bak");
system("rm -rf /var/named/7*.bak");
system("rm -rf /var/named/8*.bak");
system("rm -rf /var/named/9*.bak");
system("rm -rf /var/named/*.bak");
system("rm -rf /var/named/*.db");
system("rsync -arv /root/newzones/ /var/named/");
One Comment
[…] Richy’s Random Ramblings Random ramblings and ravings of Richy C « Techy: cPanel DNS Cleardown script […]
Comments are closed.