Skip to content

Commit

Permalink
Revert "Merge patch-staging into master"
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronhurt committed Aug 23, 2024
1 parent 892c929 commit 544b474
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 59 deletions.
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions config.sample.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 9 additions & 12 deletions get-last-status.sh
Original file line number Diff line number Diff line change
@@ -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 "----------"
Expand Down
29 changes: 0 additions & 29 deletions zfs-replicate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 544b474

Please sign in to comment.