17 Aug 2022 Running restic on TrueNAS Core (FreeBSD)

I will use SSH to set up everything instead of using TrueNAS UI. I wouldn’t say I like it and want to make this guide applicable to every FreeBSD-based system. Make sure that you have a root SSH login in your TrueNAS settings.

In my case, my ZFS pool is named “storage”.

Create ZFS dataset for restic and download it. I will start by creating a “storage/tools” dataset for restic binary, cache (and maybe more tools in future). It will be automatically mounted at /mnt/storage/tools

root@truenas[~]# zfs create storage/tools
root@truenas[~]# cd /mnt/storage/tools

Now go to https://github.com/restic/restic/releases and get the latest restic release for FreeBSD (0.13.1 in my case)

root@truenas[/mnt/storage/tools]# wget https://github.com/restic/restic/releases/download/v0.13.1/restic_0.13.1_freebsd_amd64.bz2
root@truenas[/mnt/storage/tools]# bzip2 -d restic_0.13.1_freebsd_amd64.bz2 
root@truenas[/mnt/storage/tools]# mv restic_0.13.1_freebsd_amd64 restic
root@truenas[/mnt/storage/tools]# chmod +x restic

As you see, I unpacked the bz2 file (-d flag deletes source archive after unpacking), renamed the file to “restic” and make it executable.

I also decided to write a simple bash script to make managing multiple “restic repos” easier.

export RESTIC_REPOSITORY=s3://s3.filebase.com/homelab-restic/$1
export XDG_CACHE_HOME=/mnt/storage/tools/cache/restic
/mnt/storage/tools/restic ${@:2}

As you can see, I use an external S3-compatible service to store my snapshots (https://filebase.com in this case). All files are stored in one bucket named “homelab-restic” (you will have to change that) and have subfolders for each restic repository. This script accepts the first argument as the repository name (in my case “mariadb”), so let’s init the repository first.

root@truenas[/mnt/storage/tools]# bash restic.sh mariadb init

Now you can use backup subcommand to make a snapshot of your files

root@truenas[/mnt/storage/tools]# bash restic.sh mariadb backup /mnt/storage/apps/mariadb

And snapshots subcommand to list snapshots

root@truenas[/mnt/storage/tools]# bash restic.sh mariadb snapshots
repository 5be896f7 opened successfully, password is correct
ID        Time                 Host        Tags        Paths
c031c4a8  2022-05-17 08:35:59  homelab                 /mnt/storage/apps/mariadb
1 snapshots

Rest of the commands you can see in the restic manual at https://restic.readthedocs.io/en/latest/manual_rest.html

In the end, add backup command to crontab and forget about it.

root@truenas[/mnt/storage/tools]# EDITOR=nano crontab -e

and add

0 3 * * * bash /mnt/storage/tools/restic.sh mariadb backup /mnt/storage/apps/mariadb

It will make a backup at 3:00 local system time every day. Use CTRL+X to exit nano, and type Y to save the file.