# Technitium Zone Exporter This tool watches a directory for changes in [Technitium DNS Server](https://technitium.com/dns/) 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](https://pypi.org/project/watchdog/) - [requests](https://pypi.org/project/requests/) - Git installed and repo initialized at the target directory Install dependencies: ```bash 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: ```bash 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`: ```ini [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`: ```bash 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 ```bash sudo systemctl daemon-reload sudo systemctl enable technitium-zone-exporter sudo systemctl start technitium-zone-exporter sudo systemctl status technitium-zone-exporter ``` Logs: ```bash journalctl -u technitium-zone-exporter -f ``` --- ## Git Workflow - The script automatically runs: ```bash git add -A git commit -m "Technitium zone export: " git push ``` - Make sure the service user has push access to the remote repo.