Enhance FreeBSD Sylve to run backups
In my previous post Migrate TrueNAS Core to Sylve I ended with an exercise for the reader to "Configure Samba and ZFS send-receive".
Well, I succeeded in adding this and even added some more backup options.
All my backup types
- ZFS send/receive over SSH
- Time Machine of Apple MacOS on a Samba share
- Rsync of UFS filesystem
ZFS send/receive over SSH
I have a couple of FreeBSD machines, ranging from laptops to desktops to Raspberry Pi's. Most of these run ZFS and I just want to send/receive the complete ZFS pool to my backup server.
TrueNAS had this feature integrated using zrepl. In Sylve I only found a feature to backup the Sylve server itself, not to backup other hosts to the Sylve server.
I didn't want to write a custom script, so I tried some existing ones. I ended up with sysutils/sanoid (pkg install sanoid). This package contains an application syncoid which is very flexible with only command line switches. I now have this in cron on the Sylve server:
SYNCOID_ARGS="--no-privilege-elevation --compress none --no-sync-snap --sendoptions=Lce -r"
1 0 * * * syncoid $SYNCOID_ARGS backup@rpi4.thuis.klop.ws:zrpi4 freenas-data/backup-rpi4 2>&1 | ts | tee /var/tmp/backup-rpi4.log
2 0 * * * syncoid $SYNCOID_ARGS backup@rpi4.thuis.klop.ws:zdata4 freenas-data/backup-rpi4-zdata4 2>&1 | ts | tee /var/tmp/backup-rpi4-zdata4.log
3 0 * * * syncoid $SYNCOID_ARGS root@rpi5.thuis.klop.ws:zroot freenas-data/backup-rpi5 2>&1 | ts | tee /var/tmp/backup-rpi5.log
This pulls the ZFS snapshots from my rpi4 and rpi5 and stores them on the local disk. Access is managed via ssh.
On rpi4 I set "zfs allow backup send zrpi4" so I can use an unprivileged user "backup" to send the backups. Unfortunately this didn't work on rpi5 because I have some jailed zfs filesystems which need the "root" user for the sending. Something to investigate for the future.
Snapshots are taken locally on the machines. I don't want the tools that sends/receives mixed with my snapshot strategy.
Time Machine of Apple MacOS on a Samba share
Sylve has support for Samba and MacOS can use that for Time Machine. But Samba needs some extra settings for Time Machine to work.
Fortunately the Sylve developer is pretty active and open for suggestions. This future was added quickly: [Feature] Let Samba share support Apple Time Machine #113.
Rsync of UFS filesystem
I have one rpi3 which uses UFS as filesystem. It can create snapshots, but does not have a send/receive feature like ZFS does. Luckily net/rsync (pkg install rsync) exists.
In TrueNAS Core it was possible to start an rsync daemon with some basic configuration. The GUI was pretty much a free form text field so you could make up your own configuration. Sylve doesn't have this. But it is very easy to setup rsync for this purpose.
An overview of my setup.
Enable rsyncd_enable="YES" in /etc/rc.conf.
In Sylve configure a filesystem /freenas-data/Rsync.
Add these files to your system:# cat /usr/local/etc/rsync/rsyncd.conf
use chroot = yes
max connections = 4
pid file = /var/run/rsyncd.pid
[RsyncBackup]
path = /freenas-data/Rsync
max connections = 0
uid = root
gid = nobody
write only = true
read only = false
auth users = ronald
secrets file = /usr/local/etc/rsync/secrets.RsyncBackup
# cat /usr/local/etc/rsync/secrets.RsyncBackup
ronald:<mypassword>
The client calls "rsync <options> / ronald@sylve.host::RsyncBackup/rpi3-root/".
This starts a daemon that chroots to a filesystem and the client can rsync anything into it. The connection is authenticated by user + password, but it is not encrypted. So use only in your trusted network or enhance this with ssh or some tunnelling. For my use case this is fine.
Conclusion
With these three backup options I implemented all backup options I needed. It uses Sylve to manage the filesystems and Samba.
I didn't boot back into TrueNAS Core for a couple of weeks now.
Comments
Post a Comment