ZFS Replication Script (zfs-replicate)

Yes, yes TrueNAS has a built in GUI to manage replication tasks. But what if you want to have a different ZFS based OS in the mix…

zfs-replicate was last updated in 2022 and only supports PUSH or local replication.

I have forked the script, and coded it to include both PUSH and PULL replication via a simple config file and bash script.

It can be called on any schedule via a cron job.

Let me know if it can be improved or features added.

2 Likes

FEATURE:

You could possibly offer a configure script (I just added something similar to this in my “BSD Pot template”)?

  • touch configure
  • Copy below to the file.
  • chmod +x ./configure

NOTE: coded quickly (one pass over).

#!/bin/sh

#: configure --
#  Reads 

# Establish some default values.
REMOTE_SERVER="192.168.1.250"
MODE="PULL"

# Find the name of the config file.
_cfg_name="$(find . -type f -name 'config.sh')"

# Check to see if file exists.
[ "$_cfg_name" ] || echo "*ERROR* Unable to locate config.sh, exiting..." && exit

# Allow the user to specify the values by calling this script.
for arg in "$@"; do
    case "$arg" in
    --REMOTE_SERVER=*)
        REMOTE_SERVER=`echo \"$arg\" | sed 's/--REMOTE_SERVER=//'`
        ;;
    --MODE=*)
        MODE=`echo \"$arg\" | sed 's/--MODE=//'`
        ;;
    --help)
        echo 'usage: ./configure [options]'
        echo 'options:'
        echo '  --REMOTE_SERVER=<ip number>: IP number of remote server'
        echo '  --MODE=<PULL/PUSH>'
        echo 'all invalid options are silently ignored'
        exit 0
        ;;
    esac
done

sed -i '' "s/^REMOTE_SERVER.*/REMOTE_SERVER=$REMOTE_SERVER/g" $_cfg_name
sed -i '' "s/^MODE.*/MODE=$MODE/g" $_cfg_name
echo 'configuration complete.'

I’ll play around with this, thanks.

I’d like to keep it simple enough for it to be run in a straightforward manner.

There are many tools, sure, but they come with some baggage.

  1. Dependancies that have to be installed (most require python or go or some build instructions)
  2. Some do only snapshots
  3. Some, like Zrepl require it to be installed on both source and destination.

For now I’ll leave it as is.

I have now also included some checks to exit the script under certain conditions, including absence of snapshots on source and destination and mismatch of snapshots.

I’ve also included a small script that will check the latest log file for the status (which is always listed at the bottom of the log file) and in the case of XigmaNAS, can be called via email task and sent to your email.

Log directory now also defaults to script directory.

Now allows you to set ALLOW_REPLICATE_FROM_SCRATCH variable to start the replication from scratch upon errors regarding snapshots.

Note supports TYPE=LOCAL or TYPE=REMOTE if someone wants to do only local dataset replication.

PR now merged into the main repo!

I’m thinking it should appear in the BSD ports tree soon.

2 Likes

http://bugs.freebsd.org/280987

Now in the ports tree!

2 Likes

This port has been heavily modified and rewritten. More functionality has been added as well as documentation.
Port has been pushed with version 1.0