remove duplicated DNS zones from cPanel cluster servers

#!/bin/bash

# Find and remove duplicated DNS zones from cPanel cluster servers

cp -r /var/named /var/named_$(date +%F)
cp /etc/named.conf /etc/named.conf_$(date +%F)

> /tmp/all_zones
> /tmp/good
> /tmp/bad

find /var/named -maxdepth 1 -name '*.db' -exec basename {} .db \; > /tmp/all_zones

for z in $(cat /tmp/zonos.txt); do
grep -qE "DNS[0-9]*=$z" /var/cpanel/users/* && echo $z >> /tmp/good
done

grep -vwf /tmp/good /tmp/all_zones > /tmp/bad

wc -l /tmp/good /tmp/bad
wc -l /tmp/all_zones

for z in $(cat /tmp/bad); do
rm -f /var/named/$z.db
done

rm -f /var/named/cache/*
mv -f /etc/named.conf /tmp/
/scripts/rebuilddnsconfig

service named restart
sleep 5
service named status

Leave a Reply

Your email address will not be published. Required fields are marked *