Skip to content

Instantly share code, notes, and snippets.

@natterstefan
Created May 1, 2019 05:41
Show Gist options
  • Save natterstefan/45a79301937026d4df0e12b4a1095ea4 to your computer and use it in GitHub Desktop.
Save natterstefan/45a79301937026d4df0e12b4a1095ea4 to your computer and use it in GitHub Desktop.
Raspberry Pi | Backup and Sync Pi-hole and UniFi data from a Raspberry Pi to Google Drive
#!/bin/bash
# create backup folders (if they do not exist yet)
mkdir -p ~/backups
mkdir -p ~/backups/unifi
mkdir -p ~/backups/pihole
# backup pi-hole
(cd ~/backups/pihole && pihole -a teleporter)
# and delete all oldest files and keep only 10
# - https://www.ostechnix.com/find-delete-oldest-file-x-files-directory/
(cd ~/backups/pihole && ls -1t | tail -n +11 | xargs rm)
# backup unifi controller (/usr/lib/unifi/data/backup)
# - https://help.ubnt.com/hc/en-us/articles/204952144-UniFi-How-can-I-restore-a-backup-configuration-#2 ==> see Method 3
sudo rsync -av /usr/lib/unifi/data/backup/ ~/backups/unifi
# change permissions of all files (because some of them are owned by root)
sudo find ~/backups -exec chown -R pi:pi {} \;
# sync backups folder with google drive (see setup.sh https://gist.github.com/natterstefan/7565c1de6c21ee982bd69942de579292)
./gdrive sync upload --delete-extraneous ~/backups 45678
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment