How to change TTL value for SOA records on all domains

Created:

2016-11-16 13:20:55 UTC

Modified:

2017-08-16 18:35:41 UTC

2

Was this article helpful?


Have more questions?

Submit a request

How to change TTL value for SOA records on all domains

Applicable to:

  • Plesk 12.5 for Linux
  • Plesk Onyx for Windows
  • Plesk 11.x for Linux
  • Plesk 11.x for Windows
  • Plesk 12.0 for Windows
  • Plesk 12.0 for Linux
  • Plesk 12.5 for Windows

Question

It is required to change SOA record value (TTL) for all domains. How to do it in bulk for all domains?

Answer

This can be performed by the following script:

For Linux:

Before executing the script create Plesk database backup:

# MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysqldump -uadmin psa > /root/psa_db_backup`date +%F`.sql

Script content:

#/bin/sh
MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -uadmin psa -sNe "select name from dns_zone;" > /root/domains_list

while read domain
do
MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -uadmin psa -sNe "update dns_zone set ttl='900', ttl_unit='60' where name='$domain';"
done < /root/domains_list

while read domain
do
/usr/local/psa/admin/bin/dnsmng --update $domain
done < /root/domains_list

For Windows:

Before executing the script create Plesk database backup by the following command:

"%plesk_dir%\\MySQL\\bin\\mysqldump.exe" -uadmin -p<admin_password> -P8306 psa > C:\\psa_backup.sql

Replace the parameter <admin_password> with your actual admin password. It can be found by executing the following command in command prompt:

"%plesk_bin%"\\plesksrvclient.exe -get

Script content:

@echo off

"%plesk_dir%\\MySQL\\bin\\mysql.exe" -uadmin -p<admin_password> -P8306 psa -sNe "select name from dns_zone;" > "C:\\domains_list.txt"

for /f "tokens=*" %%a in (C:\\domains_list.txt) do (
"%plesk_dir%\\MySQL\\bin\\mysql.exe" -uadmin -p<admin_password> -P8306 psa -sNe "update dns_zone set ttl='900', ttl_unit='60' where name='%%a';"
"%plesk_dir%\\admin\\bin\\DNSMng.exe" UPDATE %%a
echo Update of domain %%a finished.
)

For Plesk Onyx on Windows

NOTE: commands should be run in Power Shell.

  1. Create $DB variable with the path to the mysql.exe utility

     $DB = "$env:plesk_dir\MySQL\bin\mysql.exe"
    
  2. Create $DBPASS variable with password of admin user

    $DBPASS = $( -Split ( &"$env:plesk_bin\plesksrvclient.exe" -get -nogui | `echo ))[3] 2>>$output
    
  3. Create C:\list.txt file with list of domains

    & "$DB" "-uadmin" "-P8306" $("-p" + $DBPASS) "psa" -Nse "select name from dns_zone" > C:\list.txt
    
  4. Create loop, which set the needed TTL value for the SOA record of the DNS zone for domain from C:\list.txt file

    foreach ($dom in get-content  C:\list.txt) {plesk bin dns --update-soa $dom -soa-ttl 7H;  echo "$dom  - finished"}
    
Have more questions? Submit a request

2 Comments

Please sign in to leave a comment.