From 544b4749d0d31e17a96c464a334ce1ee3a893b93 Mon Sep 17 00:00:00 2001 From: Aaron Hurt Date: Fri, 23 Aug 2024 11:39:07 -0500 Subject: [PATCH] Revert "Merge patch-staging into master" --- README.md | 15 +++++---------- config.sample.sh | 11 +++-------- get-last-status.sh | 21 +++++++++------------ zfs-replicate.sh | 29 ----------------------------- 4 files changed, 17 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index c8651a9..7a159bd 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Features - Everything is logged to `${SCRIPTPATH}/logs` by default (can be set to custom location using $LOGBASE variable) but its better to keep it together with the scripts - Runs off a well documented `config.sh` file (see below) - Can be run on any schedule using cron with `bash zfs-replicate.sh -config.sh` -- Includes a `get-last-status.sh` (for XigmaNAS) that can be used to email latest replication status, which will email the latest replication status at your preferred schedule. Simply add it as a custom script in the email settings under "System > Advanced > Email Reports" +- Includes a `status-report.sh` (for XigmaNAS) that can be used to email latest replication status, which will email the latest replication status at your preferred schedule. Simply add it as a custom script in the email settings under "System > Advanced > Email Reports" - Includes ALLOW_REPLICATE_FROM_SCRATCH option (see below, or `config.sh` file for details) Warning @@ -93,15 +93,10 @@ SNAP_KEEP=2 ## older logs will be deleted LOG_KEEP=5 -## log files directory (defaults to /var/log/zfs-replicate) -## for XigmaNAS users, uncomment the next 3 lines -## called SCRIPT SCRIPTPATH and LOGBASE -## and comment out the last line to make sure the -## log files stay in the script directory -#SCRIPT=$(readlink -f "$0") -#SCRIPTPATH=$(dirname "${SCRIPT}") -#LOGBASE="${SCRIPTPATH}/logs" -LOGBASE="/var/log/zfs-replicate" +## log files directory (defaults to script path) +SCRIPT=$(readlink -f "$0") +SCRIPTPATH=$(dirname "${SCRIPT}") +LOGBASE="${SCRIPTPATH}/logs" ## command to check health of remote host ## a return code of 0 will be considered OK diff --git a/config.sample.sh b/config.sample.sh index 6832c71..eb2ac76 100644 --- a/config.sample.sh +++ b/config.sample.sh @@ -57,14 +57,9 @@ SNAP_KEEP=2 LOG_KEEP=5 ## log files directory (defaults to script path) -## for XigmaNAS users, uncomment the next 3 lines -## called SCRIPT SCRIPTPATH and LOGBASE -## and comment out the last line to make sure the -## log files stay in the script directory -#SCRIPT=$(readlink -f "$0") -#SCRIPTPATH=$(dirname "${SCRIPT}") -#LOGBASE="${SCRIPTPATH}/logs" -LOGBASE="/var/log/zfs-replicate" +SCRIPT=$(readlink -f "$0") +SCRIPTPATH=$(dirname "${SCRIPT}") +LOGBASE="${SCRIPTPATH}/logs" ## command to check health of remote host ## a return code of 0 will be considered OK diff --git a/get-last-status.sh b/get-last-status.sh index 90cb2dc..386bc22 100755 --- a/get-last-status.sh +++ b/get-last-status.sh @@ -1,24 +1,21 @@ #!/bin/bash -# Set log directory (defaults to /var/log/zfs-replicate) -## for XigmaNAS users, uncomment the next 3 lines -## called SCRIPT SCRIPTPATH and LOGBASE -## and comment out the last line to make sure the -## log files stay in the script directory -#SCRIPT=$(readlink -f "$0") -#SCRIPTPATH=$(dirname "${SCRIPT}") -#LOGBASE="${SCRIPTPATH}/logs" -LOGBASE="/var/log/zfs-replicate" +# Set default script directory +SCRIPT=$(readlink -f "$0") +SCRIPTPATH=$(dirname "${SCRIPT}") # Check for existing logs -if ! [ -e ${LOGBASE} ]; then +if ! [ -e ${SCRIPTPATH}/logs ]; then echo "Log directory does not exist, can't check status." exit 0 fi +# Set log directory +LOGS="${SCRIPTPATH}/logs" + # Retrieve latest log status -RECENT_LOG_FILE=$(ls ${LOGBASE} | grep autorep- | tail -n 1) -STATUS=$(tail -n 1 ${LOGBASE}/${RECENT_LOG_FILE}) +RECENT_LOG_FILE=$(ls ${LOGS} | grep autorep- | tail -n 1) +STATUS=$(tail -n 1 ${LOGS}/${RECENT_LOG_FILE}) echo "Last Replication Status" echo "----------" diff --git a/zfs-replicate.sh b/zfs-replicate.sh index dad4e00..c331052 100755 --- a/zfs-replicate.sh +++ b/zfs-replicate.sh @@ -364,61 +364,36 @@ do_snap() { if [ $RECURSE_CHILDREN -ne 1 ]; then printf "RUNNING: %s snapshot %s@%s\n" "${ZFS}" "${local_set}" "${sname}" $ZFS snapshot ${local_set}@${sname} - if [[ $? -ne 0 ]]; then - exit_error - fi - fi else printf "RUNNING: %s snapshot -r %s@%s\n" "${ZFS}" "${local_set}" "${sname}" $ZFS snapshot -r ${local_set}@${sname} - if [[ $? -ne 0 ]]; then - exit_error - fi fi elif [ ${MODE} = PULL ] && [ ${TYPE} = REMOTE ]; then printf "Creating ZFS snapshot %s@%s\n" "${remote_set}" "${sname}" if [ $RECURSE_CHILDREN -ne 1 ]; then printf "RUNNING: %s snapshot %s@%s\n" "${ZFS}" "${remote_set}" "${sname}" ssh $REMOTE_SERVER $ZFS snapshot ${remote_set}@${sname} - if [[ $? -ne 0 ]]; then - exit_error - fi else printf "RUNNING: %s snapshot -r %s@%s\n" "${ZFS}" "${remote_set}" "${sname}" ssh $REMOTE_SERVER $ZFS snapshot -r ${remote_set}@${sname} - if [[ $? -ne 0 ]]; then - exit_error - fi fi elif [ ${MODE} = PUSH ] && [ ${TYPE} = LOCAL ]; then printf "Creating ZFS snapshot %s@%s\n" "${local_set}" "${sname}" if [ $RECURSE_CHILDREN -ne 1 ]; then printf "RUNNING: %s snapshot %s@%s\n" "${ZFS}" "${local_set}" "${sname}" $ZFS snapshot ${local_set}@${sname} - if [[ $? -ne 0 ]]; then - exit_error - fi else printf "RUNNING: %s snapshot -r %s@%s\n" "${ZFS}" "${local_set}" "${sname}" $ZFS snapshot -r ${local_set}@${sname} - if [[ $? -ne 0 ]]; then - exit_error - fi fi elif [ ${MODE} = PULL ] && [ ${TYPE} = LOCAL ]; then printf "Creating ZFS snapshot %s@%s\n" "${remote_set}" "${sname}" if [ $RECURSE_CHILDREN -ne 1 ]; then printf "RUNNING: %s snapshot %s@%s\n" "${ZFS}" "${remote_set}" "${sname}" ${ZFS} snapshot ${remote_set}@${sname} - if [[ $? -ne 0 ]]; then - exit_error - fi else printf "RUNNING: %s snapshot -r %s@%s\n" "${ZFS}" "${remote_set}" "${sname}" ${ZFS} snapshot -r ${remote_set}@${sname} - if [[ $? -ne 0 ]]; then - exit_error - fi fi fi @@ -504,10 +479,6 @@ init() { echo "Replication mode is not set. Please set the MODE variable to PUSH or PULL." exit_error fi - if [ -z "${REPLICATE_SETS}" ] || [ "${REPLICATE_SETS}" == "localpool/localdataset:remotepool/remotedataset" ]; then - echo "REPLICATE_SETS is not set properly. Please set it. See config.sample.sh file for examples." - exit_error - fi if [ $SNAP_KEEP -lt 2 ]; then printf "ERROR: You must keep at least 2 snaps for incremental sending.\n" printf "Please check the setting of 'SNAP_KEEP' in the script.\n"