2025-09-28 15:51:05 +02:00
2025-09-28 15:51:05 +02:00
2025-09-28 15:04:01 +02:00
2025-09-28 15:04:01 +02:00

Technitium Zone Exporter

This tool watches a directory for changes in Technitium DNS Server zone files.
When a change is detected, it:

  1. Exports zones via the Technitium DNS API.
  2. Writes the exported zones into a Git repository.
  3. Commits (and optionally pushes) the changes.

Useful for keeping DNS zones under version control automatically.


Features

  • Watches any directory (using watchdog) and debounces rapid changes.
  • Can export all zones or just the zone corresponding to the changed file.
  • Commits with timestamp and changed file info.
  • Reads config from environment variables.
  • Runs continuously as a systemd service.

Requirements

  • Python 3.8+
  • watchdog
  • requests
  • Git installed and repo initialized at the target directory

Install dependencies:

pip install watchdog requests

Environment Variables

Variable Default Description
TECHNITIUM_ZONE_DIR (none) Directory where Technitium stores the zone files.
TECHNITIUM_API_BASE (none) Technitium URL with protocol and port
TECHNITIUM_API_TOKEN (none) API token for Technitium DNS.
GIT_REPO_DIR (none) Zone Git repository path
GIT_AUTHOR_NAME (none) Author name of the git commits
GIT_AUTHOR_EMAIL (none) Mail address of the autor of git commits
GIT_PUSH (none) Boolean (True/False) to enable commits push
LOG_LEVEL INFO Logging verbosity (DEBUG, INFO, WARNING, ERROR).

Running Manually

Export all zones immediately:

TECHNITIUM_API_TOKEN="yourtoken" LOG_LEVEL=DEBUG python3 technitium_zone_exporter.py

Running as a Systemd Service

1. Service file

Create /etc/systemd/system/technitium-zone-exporter.service:

[Unit]
Description=Technitium DNS zone auto-exporter
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/python3 /opt/technitium_zone_exporter/src/technitium_zone_exporter.py
WorkingDirectory=/opt/technitium_zone_exporter
EnvironmentFile=/etc/technitium-zone-exporter.env
Restart=always
RestartSec=5s
User=root

[Install]
WantedBy=multi-user.target

2. Environment file

Create /etc/technitium-zone-exporter.env:

TECHNITIUM_ZONE_DIR=technitium_zone_dir
TECHNITIUM_API_BASE=technitium_url
TECHNITIUM_API_TOKEN=technitium_token

GIT_REPO_DIR=git_repo_dir
GIT_AUTHOR_NAME=technitium_git_user
GIT_AUTHOR_EMAIL=technitium_git_user_mail
GIT_PUSH=True

LOG_LEVEL=INFO

3. Enable & start

sudo systemctl daemon-reload
sudo systemctl enable technitium-zone-exporter
sudo systemctl start technitium-zone-exporter
sudo systemctl status technitium-zone-exporter

Logs:

journalctl -u technitium-zone-exporter -f

Git Workflow

  • The script automatically runs:
    git add -A
    git commit -m "Technitium zone export: <timestamp>"
    git push
    
  • Make sure the service user has push access to the remote repo.
Description
A script to export zones via API whenever a change is made
Readme 54 KiB
Languages
Python 100%