Skip to content

Automate your Pi-hole backups to a destination device of your choice. Keeps only the last four "Teleporter" backup files.

License

Notifications You must be signed in to change notification settings

jlar0che/Pi-hole-Automated-Backup-Solution

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Pi-hole Automated Backup Solution

Automate your Pi-hole backups with this workflow. The script uses the command-line version of Pi-hole's built-in 'Teleporter' to create a configuration backup, which is then transferred to your chosen destination (e.g., a NAS) via rsync. A log of the transfer is also saved to the destination directory. To conserve space, only the four most recent Teleporter backups are kept and synced, ensuring efficient use of storage.

Contributors Forks Stargazers Issues MIT License LinkedIn


Table of Contents
  1. About The Project
  2. Getting Started
  3. Release History
  4. Roadmap
  5. Contact and Info
  6. Acknowledgements
  7. Contributing

About The Project

After finally setting up a Pi-hole instance in my Home Lab to see what all the fuss what about I was thoroughly impressed. But, as with many things Home Lab, one project quickly begets another: now I had to setup some sort of reliable backup solution.

At first I began looking for a good solution to backup my entire Raspberry Pi. The thought process was "if my SD card on the Pi, or the Pi itself dies, I'll be able to quickly swap out the broken hardware and restore the entire system to it's previous state."

Since I use Active Backup for Business on my Synology NAS this was the first thing I tried. Unfortunately, Synology has not ported Active Backup for Business for ARM processors so this is a no-go solution for a Raspberry Pi.

In the end I opted to use "Teleporter" -- the built-in configuration backup solution for Pi-hole.

The next problem was "how do I automate this?". Teleporter works fine, but the joys of a successful Home Lab architecture is not having a ton of things that require manual handling. Hence, this project was born!

NOTE:
In addition to the automated Teleporter backups provided by this solution, I setup a secondary Pi-hole DNS server and synced it with my primary Pi-hole instance using Orbital Sync. Therefore for my setup to fail my Primary Pi-hole instance on my Raspberry Pi plus my backups of that instance on my NAS plus my secondary Pi-hole instance running in Docker would all have to fail.

Built With

Below are all the parts, tools, libraries, frameworks, etc. applicable to and used in this project. Additional details can be found in the acknowledgements section.

(back to top)

Getting Started

Prerequisites

This repo assumes that you have a Pi-hole instance setup on a physical Raspberry Pi with Raspbian / Raspberry Pi OS. This is my particular setup, but could easily be used if your Pi-hole is running on a virtualized instance via Proxmox, Hyper-V, etc. or a containerized instance via Docker.

The other assumptions made here are that you will be able to follow the logic of the installation to suit your specific conditions in regards to your destination device. In my case I am using a Synology NAS. For this gear the configuration of shares (e.g. CIFS, NFS, etc.) are quite specific. Instead of giving all the details regarding that I leave it up to the reader / implementer to understand how to do this on their own hardware.

Installation

  1. Put the script on your Pi-hole:
    Make a directory for the backup_pihole.sh script to live (e.g. mkdir pihole_backups), then place it there.

  2. Make sure the Script is executable:
    sudo chmod -x backup_pihole.sh

  3. Make sure Rsync is installed on your system running Pi-hole (install if it isn't):
    rsync --version

  4. Mount your destination directory onto your Pi-hole:
    sudo mkdir -p /mnt/backup_destination

  5. Setup the mount so it persists on the Pi-hole after a reboot:
    Edit /etc/fstab with your preferred editor:
    sudo nano /etc/fstab

    Add the command to enable the mount:
    //192.168.1.100/Backups/Pi-hole /mnt/backup_destination cifs vers=1.0,user=your-admin-username,password=your-admin-password,x-systemd.automount 0 0

  6. Verify that the Mount persists on Pi-hole reboot:
    sudo reboot now
    Then, check if mountpoint is still available at ls /mnt/

  7. Setup Password-less SSH connection via SSH Keys This is done so the script can run without prompting for any passwords.
    ssh-keygen -t rsa -b 4096
    Then copy the SSH Public Key to the destination device. Note that after being generated the SSH Key files will be placed in the .ssh directory under your home directory (e.g. ~/.ssh).

    You can do this by SCP'ing into your Pi and copying the SSH Public Key (id_rsa.pub) to the appropriate location on your backup device as the appropriate user. For me, this was something like:
    ssh-copy-id -p 22 [email protected]

    Note that to complete the process you will need to enter the password for the specified user once.

  8. Test if Password-less SSH to your destination device is working:
    ssh -p 22 [email protected]

  9. Test the Rsync Command Manually to make sure everything is functioning as expected:
    sudo rsync -avvv -e 'ssh -p 22' /home/pi/Pihole_Backups/ [email protected]:/volume1/Backups/Pi-hole/

  10. Check the Log Files on your destination directory:
    Open logfile.log in your destination directory and inspect the entries to make sure all operations executed as expected.

  11. Setup the script to run automatically (with Cron):
    crontab -e

    For me, I set it to run on the first of every month by adding the following line to my crontab file:
    0 0 1 * * /path/to/the_script/name_of_script.sh

  12. Verify that the Cron Job was added correctly:
    crontab -l

Release History

  • 0.6.2
    • Set rsync to keep number of backups the same on both source and destination.
  • 0.6.0
    • Tested and finalized.
  • 0.5.0
    • The first proper release.
  • 0.4.0
    • Testing and tweaks.
  • 0.3.0
    • Testing and bugfixes.
  • 0.2.0
    • Added Logs.
  • 0.1.0
    • Work in progress.

(back to top)

Roadmap

  • Add Logs
  • Add dialog system for moderate level of automation on setup

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contact and Info

Jacques Laroche – Twitter @jlar0che

Project Link: https://github.com/jlar0che/Pi-hole-Automated-Backup-Solution

Distributed under the GPLV3 license. See GPLV3 LICENSE DETAILS for more information.

(back to top)

Acknowledgments

Big thanks to the following makers, resources and tools.

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork it (https://github.com/jlar0che/Pi-hole-Automated-Backup-Solution)
  2. Create your feature branch (git checkout -b feature/Branchname)
  3. Commit your changes (git commit -am 'Add a message')
  4. Push to the branch (git push origin feature/Branchname)
  5. Create a new Pull Request

(back to top)

About

Automate your Pi-hole backups to a destination device of your choice. Keeps only the last four "Teleporter" backup files.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages