Syncing Two Pi-Holes with Bash Scripting

Since gravity sync current has some issues, I wrote a simple script to copy over your key files

You can automate this with cron if you like, but I like to run it manually after any dns updates

You will need 3 files, although 2 are just some ascii art to indicate when the script starts and finishes. paste these into your 3 files (dnsreplicate.sh, banner.txt, and banner2.txt) then run the bash script when you want to copy over your dns records. Also note, your IPs should reflect your two different piholes, in this instance, .30 is my secondary pi, and this script lives on the primary on .33.

sshpass is a pre-requisite for this setup. if you do not have it, install it with your linux package manager. you may also need to setup some sudo permissions to each server, since the script is basically sshing from one server to the other and copying files.

#!/bin/bash
cat banner.txt
sshpass -f '/home/yourusername/dnsreppw/pw' scp /etc/dnsmasq.d/05-custom.conf yourusername@192.168.1.30:/etc/dnsmasq.d/05-custom.conf
sshpass -f '/home/yourusername/dnsreppw/pw' scp /etc/dnsmasq.d/05-pihole-custom-cname.conf yourusername@192.168.1.30:/etc/dnsmasq.d/05-pihole-custom-cname.conf
sshpass -f '/home/yourusername/dnsreppw/pw' ssh yourusername@192.168.1.30 'sudo systemctl restart pihole-FTL.service'
echo "."
echo "."
echo "."
echo "."
echo "."
echo "."
echo "."
echo "."
cat banner2.txt

banner.text


▓█████▄  ███▄    █   ██████     █    ██  ██▓███  ▓█████▄  ▄▄▄     ▄▄▄█████▓▓█████  ██▀███
▒██▀ ██▌ ██ ▀█   █ ▒██    ▒     ██  ▓██▒▓██░  ██▒▒██▀ ██▌▒████▄   ▓  ██▒ ▓▒▓█   ▀ ▓██ ▒ ██▒
░██   █▌▓██  ▀█ ██▒░ ▓██▄      ▓██  ▒██░▓██░ ██▓▒░██   █▌▒██  ▀█▄ ▒ ▓██░ ▒░▒███   ▓██ ░▄█ ▒
░▓█▄   ▌▓██▒  ▐▌██▒  ▒   ██▒   ▓▓█  ░██░▒██▄█▓▒ ▒░▓█▄   ▌░██▄▄▄▄██░ ▓██▓ ░ ▒▓█  ▄ ▒██▀▀█▄
░▒████▓ ▒██░   ▓██░▒██████▒▒   ▒▒█████▓ ▒██▒ ░  ░░▒████▓  ▓█   ▓██▒ ▒██▒ ░ ░▒████▒░██▓ ▒██▒
 ▒▒▓  ▒ ░ ▒░   ▒ ▒ ▒ ▒▓▒ ▒ ░   ░▒▓▒ ▒ ▒ ▒▓▒░ ░  ░ ▒▒▓  ▒  ▒▒   ▓▒█░ ▒ ░░   ░░ ▒░ ░░ ▒▓ ░▒▓░
 ░ ▒  ▒ ░ ░░   ░ ▒░░ ░▒  ░ ░   ░░▒░ ░ ░ ░▒ ░      ░ ▒  ▒   ▒   ▒▒ ░   ░     ░ ░  ░  ░▒ ░ ▒░
 ░ ░  ░    ░   ░ ░ ░  ░  ░      ░░░ ░ ░ ░░        ░ ░  ░   ░   ▒    ░         ░     ░░   ░
   ░             ░       ░        ░                 ░          ░  ░           ░  ░   ░
 ░                                                ░


banner2.text

___  _  _ ____    _  _ ___  ___  ____ ___ ____ ___     ____ ____ _  _
|  \ |\ | [__     |  | |__] |  \ |__|  |  |___ |  \    |___ |__| |\/|
|__/ | \| ___]    |__| |    |__/ |  |  |  |___ |__/    |    |  | |  |


Discussion

Enter your comment. Wiki syntax is allowed:
 
Last modified: le 2022/01/22 00:30