#!/bin/bash # Author: Besmir Zanaj, 2024 # This is a very raw script to backup configs (no logs and no stats) from a technitium server # to another # ## 20250814 Stocker Modify to Set DHCP Delay Time to 2000MS rather than disable DHCP Scope ## 20250815 Stocker modify DNS Server Internal IP bind ########################################################################################### # first create two tokens: one on the source server and another one on the destination one # fill out the vars below # create a cronjob with this script on the destinaton host # eg: # 30 */6 * * * /path-to/technitium-sync.sh set -euxo pipefail src_dns_server='source.ip.address' dst_dns_server='dest.ip.address' src_dns_serverdomain='fqdn.of.source.server' dst_dns_serverdomain='fqdn.of.dest.server' src_dns_token='SOURCE_TECHNITIUM_TOKEN_HERE' dst_dns_token='DEST_TECHNITIUM_TOKEN_HERE' backup_file="/tmp/technitium-backup.zip" # update the dhcp scope as per your local settings dhcp_scope_name="local-home" # Ensure required tools are installed command -v curl >/dev/null 2>&1 || { echo "curl is not installed. Aborting." >&2; exit 1; } # Check the primary server's health before running the script echo "Checking primary Technitium server status" status_code=$(curl --write-out %{http_code} --silent --output /dev/null http://$src_dns_server:5380) if [[ "$status_code" -ne 200 ]] ; then echo "Primary DNS server is not available. Skipping backup" exit 1 else echo "Getting the backup archive from the primary server" curl -s "http://$src_dns_server:5380/api/settings/backup?token=$src_dns_token&blockLists=true&logs=false&scopes=true&stats=false&zones=true&allowedZones=true&blockedZones=true&dnsSettings=true&logSettings=true&authConfig=true&apps=true" -o $backup_file fi # restore_backup if [[ -f "$backup_file" ]]; then echo "Restoring the backup on $HOSTNAME" curl -s --form file="@$backup_file" "http://$dst_dns_server:5380/api/settings/restore?token=$dst_dns_token&blockLists=true&logs=true&scopes=true&stats=true&apps=true&zones=true&allowedZones=true&blockedZones=true&dnsSettings=true&logSettings=true&deleteExistingFiles=true&authConfig=true" --output /dev/null # wait for server to come back echo "Waiting for 10 seconds for the destination server to start up" sleep 10 # set dnsServerDomain on destination server echo "Updating DNS server Domain and IP in destination server" #curl -k -X POST "https://$dst_dns_server:53443/api/settings/set?token=$dst_dns_token&dnsServerDomain=$dst_dns_serverdomain&dnsServerLocalEndPoints=dst_dns_server curl -k -X POST "https://$dst_dns_server:53443/api/settings/set?token=$dst_dns_token&dnsServerDomain=$dst_dns_serverdomain&dnsServerLocalEndPoints=$dst_dns_server" # disable DHCP on the destination server #echo "disabling DHCP in destination server" #curl -X POST "http://$dst_dns_server:5380/api/dhcp/scopes/disable?token=$dst_dns_token&name=$dhcp_scope_name" # Set DHCP Response to really high on backup echo "Updating DHCP Offer Delay" curl -X POST "http://$dst_dns_server:5380/api/dhcp/scopes/set?token=$dst_dns_token&name=$dhcp_scope_name&offerDelayTime=2000" # cleanup echo "Cleaning up temporary files" rm -rf $backup_file fi