My setup: DIY NAS, Kodi & backup system with a bunch of raspberry pi 4s: part 2
This is part two of my setup with home streaming. Don’t forget to read part one.
In the last part I gave an overview of all the parts and functionality and I wrote about my setup using Kodi, PiNAS and Wireguard. Now I’ll write a bit about configuring my laptop and mobile with Nextcloud, and the backup system.
For clarity I’ve created a diagram of the overall system that I described in part one:
Diagram
Laptop setup
Functions:
- Wireguard VPN to personal network
- Contact and calendar sync
- File sync and automatic backups of important directories
wg-quick
I used wg-quick for my Wireguard setup. It’s able to setup the VPN including routes and DNS from a configuration file. And you can easily have multiple profiles.
For wg-quick I have two profiles:
- no-tunnel mode: only PiNAS traffic goes through VPN (default)
- tunnel mode: all network traffic goes through VPN
no-tunnel mode setup:
[Interface]
PrivateKey = <private>
Address=192.168.99.3/24
[Peer]
PublicKey = <public>
Endpoint = <ip>:443
AllowedIPs = 192.168.99.1/32
tunnel mode setup:
[Interface]
PrivateKey = <private>
Address=192.168.99.3/24
DNS=192.168.99.1
[Peer]
PublicKey = <public>
Endpoint = <ip>:443
AllowedIPs = 0.0.0.0/0
The above config files are saved as wgq0.conf and wgq1.conf in /etc/wireguard. They can be activated through systemctl start wg-quick@wgq0
or systemctl start wg-quick@wgq1
. They can be enabled on startup with systemctl enable wg-quick@wgq0
. More about systemctl process management: DigitalOcean systemctl tutorial.
wg-quick understands from the AllowedIps = 0.0.0.0/0 in tunnel-mode to setup routes so all traffic flows through Wireguard.
contact and calendar sync
On laptop I use thunderbird for email and calendar. To synchronize email contacts I use Cardbook, which supports CardDAV.
Add a new address book, choose remote -> CardDAV, I use this url https://nas.thomasvanderberg.nl/remote.php/dav/addressbooks/users/thomas/contacts/
and my Nextcloud credentials. Periodic sync once per 60 minutes.
Then I use this address book for all my email contacts. Using the same CardDAV URL for mobile (setup later in this article) I’ll be able to share the same addresses on mobile and laptop, without an external cloud service.
To synchronize events, I use Lightning which supports CalDAV by default. Just new calendar -> remote -> CalDAV with URL https://nas.thomasvanderberg.nl/remote.php/dav/calendars/thomas/personal-1/
.
file sync
For file sync I use the Nextcloud app which works like Dropbox. It synchronizes one or more directories. I have one directory on my laptop, ~/Nextcloud, which is shared. A lot of subdirectories of ~/Documents and some other directories like ~/Pictures are simply symbolic links to a directory in ~/Nextcloud (like ~/Pictures links to ~/Nextcloud/Photos) to make sure they are automatically synchronized.
To make a symbolic link I use the command line tool ln. Example: ln -rs ~/Nextcloud/Photos ~/Pictures
.
Mobile setup
Functions:
- Wireguard VPN to personal network
- Contact and calendar sync
- Access to Nextcloud files
Wireguard VPN on Android
The Wireguard Android app is an excellent, easy to use interface to Wireguard. The only somewhat tricky thing required is copying the Wireguard public key to Android. A possibility without even exposing the public key is generating a QR-code of it with qrencode.
Example: ssh -t pinas sudo wg show wg0 public-key | qrencode -o /tmp/out.png; xdg-open /tmp/out.png
Example output:
In the above command we:
- log into PiNAS using SSH and allocate a TTY (-t)
- use sudo to start a superuser session (might require entering the sudo password)
- get the public-key for the Wireguard network
wg0
(replace with the name of your Wireguard network) - locally use
qrencode
to generate a QR code and display it with xdg-open
This QR-code can be scanned with an app such as SecScanQR and then copypasted into your Wireguard config.
I have the Wireguard VPN always enabled on my mobile phone.
Contact and calendar sync on Android
For CalDAV and CardDAV on Android I used DAVx5 and the Nextcloud app. Using the guide for DAVx5 and Nextcloud it was easy to set up.
Though the setup is easy that there is little to say about, calendar and contact sync on Android was basically one of the killer features for me. My Android doesn’t have a Google account attached to it, so contact and calendar sync was always an issue before. Having to manually back them up, and not being able to see events to my mobile calendar when I accepted them from my email client has caused me some issues in the past.
Really happy with DAVx5 making this possible for me, so I also donated to show my support.
Nextcloud files on Android
Basically installing the Nextcloud app and authenticating to it allows me access to all my Nextcloud files. One issue I had is streaming music from my Nextcloud. It’s possible to stream a single song through the Nextcloud app, but not an entire album. I found out about the possibility to do this with Nextcloud Music and Power Ampache later through this guide.
Backups
My backup system is another Raspberry Pi 4 with 2 TB HDD attached over USB-3. I use rsnapshot to make backups of PiNAS on it. Basically pinas-backup logs into PiNAS as root, makes a database dump, and copies all important files to its own system every night. Actually it only copies files which were changed since the last backup. Using hard links, it keeps only a single copy of each file if it’s not changed. My rsnapshot setup keeps:
- 3 daily backups
- 2 weekly backups
- 2 monthly backups
Because of the hard link method, this barely takes up more space than a single backup.
Outro
So that’s what I did to setup my personal data synchronization system over my devices. I’m sure I’ll make future changes and build on it. It’s a fun learning project and already gave me a lot of value. I hope if you read this you got some value out of it as well. If you have any questions about it feel free to email me.
Finally, some pictures:
The humble PiNAS.
Kodi box connected to TV and network.