BetterZFSReplication
Do ZFS replication in a better way than the TrueNAS UI
Because the UI abstracts away the raw CLI options and I don't know what it's really doing
autoBackup
autoBackup
is a nice script that boots another TrueNAS machine, runs some ZFS replication tasks,
and then turns itself off again.
The script consists of a master
TrueNAS and a slave
TrueNAS. It is assumed that the master
TrueNAS is already
on when this script is executed. The slave
TrueNAS is switched on with the use of a Tasmota-flashed power plug, like this, using MQTT.
The script waits until the slave TrueNAS can recieve API requests, then runs a number of named ZFS replication tasks, as configured in the UI.
Therefore these tasks should not be set to run automatically in the TrueNAS UI. The tasks can be both on the master
TrueNAS (push tasks),
and on the slave
TrueNAS (pull tasks). Once all the replication tasks are completed, if the slave
TrueNAS was switched on by this script,
it is shut down, and once the plug is pulling 0w, which implies the TrueNAS has fully shut down, the Tasmota plug is switched off.
If the Tasmota MQTT plug was already on when the script starts, it implies that the slave
TrueNAS was started manually, so it won't automatically
be switched off.
It is recommended to run ZFS scrub tasks manually occasionally, since they probably won't be run automatically by TrueNAS.
A Dockerfile is provided so you can automatically run this script as a cronjob.
The MQTT Tasmota stuff is pretty specific to my setup so might not be too useful to others; but the TrueNAS API stuff might be useful to other people. It probably wouldn't be too hard to make this work with wake-on-lan instead. We are using the HTTP API instead of the sockets API, since the sockets API seems to change quite a lot. We use standard TrueNAS API keys.