I wrote a small CLI tool to replicate the restore function available on the Web UI. Not sure if this is part of the road map or not, but for me, the motivation was to write something to automate a multiple pi-hole scenario in the home network.
I've tested with all the config that can be restored, however I don't have enough edge cases to be 100% confident that this won't break your existing setup. That's why the version is still v0.x.x.
If you run multiple pi-holes and want to automate config synchronisation, see if this fits your use case. It doesn't have a --dry-run
flag yet, so maybe test it on a secondary node first?
Couple of disclaimers:
- Not sure if there are other tools out there. If there are, chances are that they are better tested mostly because more people may have used them. This doesn't come with a warrenty unfortunately, so backup before you use.
- I used
pihole
in the name because this is specifically related to pi-hole. Hope it's according to community and branding guidelines. If not, please let me know.
Also, couple of excerpts from the blog post I wrote.
What I do is to use it along side syncthing and perform the task of creating a backup as a manual step. While I would still keep on introducing more changes to my local setup, for the time being I want to have some control over when the changes are propagated. This would probably change to a cron job in the future.
When I’d perform a change in the “primary” Pi-hole server, I perform a
pihole -a teleporter
on it. This produces the backup archive I need. I havesyncthing
synching this directory across to the two secondary Pi-hole servers. This usually happens within the minute.
On the secondary nodes, I have a
systemd
service that keeps watching the target directories for incoming files (technically, forinotify
moved_to
events, sincesyncthing
first starts copying contents to a.tmp
file and then renames it). Once a file is detected, it runspihole_restore
with the new file as the input.systemd-journal
logs help me debug if things don’t go according to plan.
inotifywait -q -m -e moved_to --format '%f' "${WATCH_DIR}" | while read f; do
if [[ $f == *.tar.gz ]]; then
RUST_LOG=debug /usr/bin/pihole-restore -f ${WATCH_DIR}/${f} -c
else
echo "not using this file: ${f}"
fi
done