Skip to content

Instantly share code, notes, and snippets.

@Diegus83
Last active August 24, 2019 22:58
Show Gist options
  • Save Diegus83/4e26d077a0bc4d5698906c41ccc6bcd2 to your computer and use it in GitHub Desktop.
Save Diegus83/4e26d077a0bc4d5698906c41ccc6bcd2 to your computer and use it in GitHub Desktop.
Simple pihole backup via SCP
#!/bin/bash
####################################
#
# Backup via SCP
#
# Executes daily as defined by crontab -e
# 0 0 * * * bash /home/pi/scripts/backup.sh
#
# Don't forget to generate an ssh key and add it to the mac mini
#
####################################
#Create empty exclusion list
touch /home/pi/scripts/exclude.txt
# What to backup
backup_files="/etc/pihole/blacklist.txt /etc/pihole/whitelist.txt /etc/hostname /etc/hosts /home/pi"
# Where to backup to.
#dest="/home/pi/backups/"
remote_user="####"
remote_machine="####"
# Create archive filename.
day=$(date +%A)
hostname=$(hostname -s)
archive_file="$hostname-$day.tgz"
# Backup and skip local storage to save SD life.
sudo tar -cz --exclude-from=/home/pi/scripts/exclude.txt $backup_files | ssh -l $remote_user $remote_machine "cat >/Users/####/etc/backups_pihole/$archive_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment