OS‐X‐specific stuff - xenophon61/Znapzend-recipes-for-mixed-MacOS-Linux-environment GitHub Wiki

Installing the wake-on-lan shell command This is necessary, in order to wake remote servers

  • opted for wakeonlan which has an easy syntax and can be installed by Homebrew:
wakeonlan [MAC address]

In scripts running under MacOS, including the znapzend setups, this is the command to add:

/usr/local/bin/wakeonlan [target MAC address]

updated rsync using Homebrew

  • the native rsync provided by MacOS is a 2.6.x version
  • one should use Homebrew to install a modern 3.x version (now located at /usr/local/bin/rsync)
  • include that in rsync commands run at the source machine (both MacOS and Linux)

allow Full Disk Access for all components

  • this includes the shell (bash, sh and zsh), along with the znapzend executables but also the Homebrew version of rsync

Caffeinating the commands (znapzend and rsync) if necessary

  • this is not strictly necessary
  • if the ssh connection (initiated by znapzend) times out for any reason, one can simply edit the .ssh/config file and include (under Host *), as per here

PermitLocalCommand yes

LocalCommand caffeinate -w $PPID &

Applescript to automate clone creation The rationale for this is as follows: znapzend can only update readonly zfs datasets on a live MacOS target (i.e. not strictly a backup server). To allow for actual editing, one must first create a clone.

The easiest way to do this is via an Applescript, with an embedded shell script.

❯ cat ~/Desktop/Clone-executable.sh
#!/bin/bash
#
# Prepare for work on the target dataset!
# name of zpool = "Kenya"
# (runs as root)
#

#osascript -e 'tell app "Finder" to display dialog "Cloning zfs datasets"'

/usr/local/zfs/bin/zfs destroy kenya/eAtreio-clone
/usr/local/zfs/bin/zfs destroy kenya/PACS-clone
/usr/local/zfs/bin/zfs destroy kenya/darkroom-clone

exit_code=$?
#echo $exit_code

#
# first, parse the zfs snapshot list to find the most recent one
#
	cmd="$(/usr/local/zfs/bin/zfs list -t snapshot kenya/eAtreio | tail -n 1 )"
		result=$(echo $cmd)
		snappy=${result%% *}
	echo $snappy ": created clone"

#
# create a clone
#
	/usr/local/zfs/bin/zfs clone $snappy kenya/eAtreio-clone


        cmd="$(/usr/local/zfs/bin/zfs list -t snapshot kenya/PACS | tail -n 1 )"
                result=$(echo $cmd)
                snappy=${result%% *}
        echo $snappy ": created clone"
        /usr/local/zfs/bin/zfs clone $snappy kenya/PACS-clone

        cmd="$(/usr/local/zfs/bin/zfs list -t snapshot kenya/darkroom | tail -n 1 )"
                result=$(echo $cmd)
                snappy=${result%% *}
        echo $snappy ": created clone"
        /usr/local/zfs/bin/zfs clone $snappy kenya/darkroom-clone