forked from extern/zsync
107 lines
3.5 KiB
Bash
107 lines
3.5 KiB
Bash
#!/bin/bash
|
|
#
|
|
# bashclub zfs replication script config tool
|
|
# Author: (C) 2023 Thorsten Spille <thorsten@spille-edv.de>
|
|
|
|
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
|
|
|
|
prog="$(basename $0)"
|
|
|
|
#### default config file, can be changed with parameter -c
|
|
action=list
|
|
conf=/etc/bashclub/zsync.conf
|
|
recursive=0
|
|
key=
|
|
path=
|
|
value=
|
|
|
|
|
|
usage() {
|
|
cat >&2 <<-EOF
|
|
usage: $prog [-h] [-a ACTION] [-c CONFIG] [-p PATH] [-s KEY[=VALUE]] [-r]
|
|
manages the zfs-auto-snapshot and bashclub-zsync config on source
|
|
-a ACTION The action, this script shall execute
|
|
-c CONFIG Path to the bashclub-zsync config file
|
|
-p PATH Path of the zfs dataset on source
|
|
-s KEY=VALUE Set value for specified dataset
|
|
-r Recursive listing (in combination with -l and -p)
|
|
-h Show this help text
|
|
---------------------------------------------------------------------------
|
|
Details of Parameters:
|
|
ACTION: Script actions are 'list' (default), 'set', 'inherit'
|
|
CONFIG: Default is $conf
|
|
KEY: Following keys can be configured:
|
|
zsync => alias for bashclub:zsync
|
|
or user defined in bashclub-zsync config
|
|
zas => alias for com.sun:auto-snapshot
|
|
zasf => alias for com.sun:auto-snapshot:frequent
|
|
zash => alias for com.sun:auto-snapshot:hourly
|
|
zasd => alias for com.sun:auto-snapshot:daily
|
|
zasw => alias for com.sun:auto-snapshot:weekly
|
|
zasm => alias for com.sun:auto-snapshot:monthly
|
|
zasz => alias for com.sun:auto-snapshot:label
|
|
user defined auto-snapshot label in bashclub-zsync config
|
|
VALUE: Value can be 'all','subvols','exclude', 'true', 'false'
|
|
---------------------------------------------------------------------------
|
|
(C) 2023 by Spille IT Solutions for bashclub (github.com/bashclub)
|
|
Author: Thorsten Spille <thorsten@spille-edv.de>
|
|
---------------------------------------------------------------------------
|
|
EOF
|
|
exit $1
|
|
}
|
|
|
|
while getopts "hra:c:p:s:" opt; do
|
|
case $opt in
|
|
h) usage 0 ;;
|
|
a) action=$OPTARG ;;
|
|
c) conf=$OPTARG ;;
|
|
p) path=$OPTARG ;;
|
|
s) key=$(echo $OPTARG | cut -d'=' -f 1) value=$(echo $OPTARG | cut -d'=' -f 1) ;;
|
|
r) recursive=1 ;;
|
|
*) usage 1 ;;
|
|
esac
|
|
done
|
|
shift $((OPTIND-1))
|
|
|
|
source $conf
|
|
|
|
if [[ $source == "" ]]; then
|
|
ssh=
|
|
sshport=
|
|
else
|
|
sshport=-p$sshport
|
|
fi
|
|
|
|
local_os_id=$($grep -E "^ID=" /etc/os-release | $cut -d'=' -f2)
|
|
remote_os_id=$($ssh $source $sshport "grep -E \"^ID=\" /etc/os-release | cut -d'=' -f2")
|
|
|
|
if [[ $local_os_id == "freebsd" ]]; then
|
|
local_aes=$($grep -o AES /var/run/dmesg.boot | $uniq)
|
|
else
|
|
local_aes=$($grep -m1 -o aes /proc/cpuinfo | $uniq)
|
|
fi
|
|
|
|
if [[ $remote_os_id == "freebsd" ]]; then
|
|
remote_aes=$($ssh $source $sshport "grep -o AES /var/run/dmesg.boot | uniq")
|
|
else
|
|
remote_aes=$($ssh $source $sshport "grep -m1 -o aes /proc/cpuinfo | uniq")
|
|
fi
|
|
|
|
if [[ $local_aes == "aes" ]] && [[ $remote_aes == "aes" ]]; then
|
|
sshcipher=-caes256-gcm@openssh.com
|
|
else
|
|
sshcipher=-cchacha20-poly1305@openssh.com
|
|
fi
|
|
|
|
list (){
|
|
if [ $path != *"/"* ]; then
|
|
p=$path
|
|
if [ $recursive -gt0 ]; then
|
|
rec=-r
|
|
fi
|
|
fi
|
|
list=$($ssh $sshcipher $sshport $source "zfs get -H -t filesystem,volume $tag,com.sun:auto-snapshot,com.sun:auto-snapshot:frequent,com.sun:auto-snapshot:hourly,com.sun:auto-snapshot:daily,com.sun:auto-snapshot:weekly,com.sun:auto-snapshot:monthly,com.sun:auto-snapshot:$zfs_auto_snapshot_label $rec $p")
|
|
for line in $list; do
|
|
|
|
done
|
|
} |