commit bd0f7c4c76224e3ecf08f51448436c2780134836 Author: iRaven Date: Thu Nov 23 00:48:27 2023 -0600 initial server diff --git a/phtransfer-server.sh b/phtransfer-server.sh new file mode 100644 index 0000000..9d55bc4 --- /dev/null +++ b/phtransfer-server.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +## Script for NH-Opti160 to take a backup of pihole configuration, for nanopineo (or other alternate pihole servers) to pick up over SSH on a scheduled task. +## Author: iRaven + +## CONFIGURATION OPTIONS BELOW ## + +# low-privileged user info +PHTRANSUSR=phtrans +PHTRANSPWD=nope! + +## END configuration options ## + +if [[ $EUID > 0 ]]; then + echo "Not running as root, exiting" + exit +fi + +## Make the user if it doesc't exist. +## We're assuming you have a low-privileged user set up for other pihole systems to retrieve the backup file. +## This gets configured automatically the first time you run this (below), or you can configure this yourself. Don't give it any permissions. +if [ ! -d "/home/${PHTRANSUSR}" ]; then + useradd -m -p ${PHTRANSPWD} ${PHTRANSUSR} + ssh-keygen -C "piholetransfer" -f /home/${PHTRANSUSR}/.ssh/id_rsa + chown -R ${PHTRANSUSR} /home/${PHTRANSUSR}/ +fi + +## Backup pi-hole FTL DB +pihole -a -t /home/${PHTRANSUSR}/phbackup.tar.gz + +## Copy any custom shit in dnsmasq's config directory to the user, too. +cp -v /etc/dnsmasq.d/* /home/${PHTRANSUSR}