Now when you have your homelab more or less setup, you can get a good idea to backup services. Actually there are different solutions and approaches to this task. Install specific software, run custom docker containers, replicate data folders…

This blog is just one of the options, using rsync. Frankly speaking, it is not a complete backup, but just a replica of data folders. Do not use it if you can miss the failure state for several days. In that case replica can be overriden with “broken” version of data. There is no historical versions stored.

Prerequisites Link to heading

  • Raspberry Pi 4 setup and updated
  • Some stacks started (to have something to backup)
  • Destination for replica. I will you Synology NAS with enabled rsync service

Step 0 - Create config files Link to heading

Create folder that will keep rsync configuration files: /ssd/rsync-conf

Create file that will define what folders and files should be included/excluded /ssd/rsync-conf/include.list. Content of the file looks like:

+ /

+ flame/***

+ gitea/***

- hass/config/backups/
- hass/config/home-assistant.log*
+ hass/***

- iot/mosquitto/log/
+ iot/***

- proxy/data/logs/
+ proxy/***

- rsync-config/secret
+ rsync-config/***

- seafile/data/logs/
- seafile/data/seafile/logs/
+ seafile/***

- vaultwarden/tmp/
+ vaultwarden/***

- *

+ denotes item that should be included into replica

- denotes item that should be excluded from replica

As mentioned in Prerequisites section, I will use Synology NAS with rsync service enabled as destination. It requires specifying on source side secret value to authenticate against destination.

Create file /ssd/rsync-conf/secret. This file should contain only secret string. Another requirement is that this file is accessible by user from which rsync command is started. For example, if it is started as a root:

sudo chmod 600 /ssd/rsync-conf/secret
sudo chown root:root /ssd/rsync-conf/secret

Step 1 - Defining cron job Link to heading

Use crontab to define scheduled task to run rsync:

sudo crontab -l

And add there line

0 16 * * * rsync -rvzh --password-file=/ssd/rsync-conf/secret --include-from=/ssd/rsync-conf/include.list /ssd/ rsync://<user>@<dest_ip>/backups/homelab/

This config will run rsync every day at 16:00 (0 16 * * *). Secret for authentication against destination rsync service will be taken from /ssd/rsync-conf/secret, list of includes from /ssd/rsync-conf/include.list. Paths for include/exclude will be calculated relatively to /ssd/. Destination is located on IP <dest_ip>, that has user configured. Replica will be created under /backups/homelab/

Conclusion Link to heading

As it was written before - it is not a complete backup solution, as not historical backups are created. But just a replica of data folders from homelab services. I personally use it in case if I spoil something while re-configuring homelab. So, broke something - immediately restored.