It has been a while, busy building clouds and stuff. In the Christmas spirit of sharing, today I wanted to share this bash script for ZFS backups, it will basically snapshot the ZFS share, RSYNC new files over and the delete the old ZFS snaps.
Simple, yes, but somehow a wheel that keeps being reinvented over and over again, so here’s my version of it. Hope it helps someone save some time.
For this script, the backup server is one of our own TerraNas servers (basically, Ubuntu 14 with Native ZFS and NFS/4) the client is a Ubuntu14 LTS server, the SSH keys have been imported to the client so we can SSH across without passwords and such.
On the ZFS/NFS server side, we disable ID mapping to have usernames cross the wire instead of ID’s
echo N > /sys/module/nfs/parameters/nfs4_disable_idmapping
share the ZFS drive with:
zfs set email@example.com/24,insecure,no_root_squash pool1/backup
Where 192.168.33.0/24 is your subnet or host of course.
Then we share it our with
zfs share -a and service nfs-kernel-server restart.
We do have one export to the localhost in the /etc/exports file, because NFS will complain if this file is empty, but the rest of the exports come from ZFS
On the client we have this little script: