• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Import and Export DNS zone files

WimPlesk

New Pleskian
Hi,

Does anyone know how I can export DNS zone files from a running Plesk 11.5 server.
(It is a DNS master with a 4PSA slave)

I want to export those zones so that I can import in another Plesk server and after that
I want to change the NS servers so that there is no downtime. After this I want to migrate.
This because I need to change every record manualy because our servers behind NAT.

Best regards,
 
Not sure that it is easy or even possible.

You try to can write some script like

# for i in `mysql -uadmin -p\`cat /etc/psa/.psa.shadow\` psa -Ns -e "select name from domains"`; do /usr/local/psa/bin/dns --info $i; done > list.txt

and then modify list.txt file as you want. But I haven't got a clue about import procedure.

I think that simple Plesk migration with modification zones on destination server would be more effective method.
Also look at API RPC method. Something like

<packet version="1.6.3.0">
<dns>
<get_rec>
<filter>
<site-id>1</site-id>
</filter>
</get_rec>
</dns>
</packet>

More details - http://download1.parallels.net/Plesk/PP10/10.1.1/Doc/en-US/online/plesk-api-rpc/34841.htm
 
Last edited:
Below is a script that will export the DNS records for a domain within Plesk. You could run this against all your domains to generate the commands needed to import the DNS info on the new server. It's easily adaptable to issue the domain creation commands as well. Script was originally provided by Parallels but hacked up (dirtyly, by me) to fix TXT records (dns utility has a bug that cannot accept ; in TXT records when using the -list command) and also SRV records which have multiple parameters stored in one field in the PSA database.

YMMV - good luck!

Code:
#!/bin/bash
if [ -z "$1" ] ; then
	echo "Usage: $0 <domain_name>"
	exit 1
fi

export domain_name
printf "/usr/local/psa/bin/dns --set $domain_name -list \'"

while IFS=\| read type host val opt ; do
	host=${host%%$domain_name.}
	host=${host%%.}

	case "$type" in
		"A"|"NS"|"CNAME")
			printf "%s,%s,%s;" "$type" "$host" "$val"
			;;
		"MX")
			printf "%s,%s,%s,%s;" "$type" "$host" "$val" "$opt"
			;;
		"PTR")
			# ignore PTR records
			;;
		"TXT")
			txt_r+="/usr/local/psa/bin/dns --add $domain_name -txt '$val' -domain '$host'\n"
			;;
		"SRV")
			# SRV
		        serv=`echo $host|cut -f1 -d'.'`
		        serv=${serv##_}
		        t_host=${val%%.}
		        proto=`echo $host|cut -f2 -d'.'`
		        proto=${proto##_}
		        sub=`echo $host|cut -f3 -d'.'`
		        sub=${sub%% }
		        if [ -z "$sub" ]; then
		                sub=\'\'
		        fi
			prio=`echo $opt|cut -f1 -d' '`
		        weig=`echo $opt|cut -f2 -d' '`
		        port=`echo $opt|cut -f3 -d' '`
		        srv_r+="/usr/local/psa/bin/dns --add $domain_name -srv $sub -srv-priority $prio -srv-weight $weig -srv-port $port -srv-target-host $t_host -srv-protocol $proto -srv-service $serv\n"
			;;
		*)
			echo "Unknown type of record: $type" >&2
			exit
			;;
	esac
done< <( echo "SELECT CONCAT_WS('|', type, host, val, opt) FROM dns_recs WHERE dns_zone_id = (SELECT id FROM dns_zone WHERE name = '$domain_name')" | mysql -Ns -uadmin -p`cat /etc/psa/.psa.shadow` -Dpsa )

printf "\'\n"
if [ -n "$srv_r" ]; then
	echo -e ${srv_r%%\\n}
fi
if [ -n "$txt_r" ]; then
	echo -e ${txt_r%%\\n}
fi
 
Hi Tim,

But I have more than 200 domains at one server, is it also possible with this script to select all the domains?

Best regards,
 
Code:
for i in `mysql -uadmin -p\`cat /etc/psa/.psa.shadow\` psa -Ns -e "select name from domains"`; do echo $i; done >> /tmp/dom_list

...

Code:
for i in `cat /tmp/dom_list`; do ./the_script_from_above.sh $i; done >> /tmp/exported_dns_commands
 
Code:
for i in `mysql -uadmin -p\`cat /etc/psa/.psa.shadow\` psa -Ns -e "select name from domains"`; do echo $i; done >> /tmp/dom_list

...

Code:
for i in `cat /tmp/dom_list`; do ./the_script_from_above.sh $i; done >> /tmp/exported_dns_commands

Hi Tim,

Sorry, but I doesn't have so much script knowledge but where must I put this rule?
 
Hi Tim,

Did you if there also a script the can change by bulk DNS.
And then not the main IP because our servers behind NAT.

A script like this changed the main IP and the DNS, but the main IP needs to be the internal IP only the DNS needs to be changed.
Hope you can help me.

mysql -Ns -uadmin -p`cat /etc/psa/.psa.shadow` -D psa -e 'select name from domains' | awk '{print "/usr/local/psa/bin/domain --update " $1 " -ip 000.000.000.000 "}' | sh

Script above change only the main IP's.

Best regards,
 
Back
Top