Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ignore logic #104

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions script-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ HOOK_NOTIFICATION=""
DEL_THRESHOLD=500
UP_THRESHOLD=500

# Allows setting a pattern to ignore files for computing the counts of changed
# files by snapraid diff.
# The pattern are based around this regular expression:
# ^(?!.*(?:$IGNORE_PATTERN).*$).*$
# It will exclude any file which includes the pattern IGNORE_PATTERN.
# Examples:
# IGNORE_PATTERN="Hello" -> all files including Hello will be ignored
# IGNORE_PATTERN="Backup/kopia" -> all files including Backup/kopia will be ignored
# in this case it will be all files containing any path with Backup/kopia
# IGNORE_PATTERN="(Backup/kopia)|(Hello)" -> all files containing either Backup/kopia
# or Hello will be ignored
# This is probably a rather strange approach to file filtering, please test
# your pattern using https://regex101.com/r/Igs4kX/1 (the quotes used in the
# configuration are not part of the pattern)
IGNORE_PATTERN=""

# Allow a sync that would otherwise violate the delete threshold, but only
# if the ratio of added to deleted files is greater than the value set.
# Set to 0 to disable this option.
Expand Down Expand Up @@ -129,7 +145,7 @@ VERBOSITY=0
RETENTION_DAYS=0
SNAPRAID_LOG_DIR="$HOME"

# Set the option to log SMART info collected by SnapRAID.
# Set the option to log SMART info collected by SnapRAID.
# Use SMART_LOG_NOTIFY to send the output to Telegram/Discord
# 1 to enable, any other value to disable.
SMART_LOG=1
Expand Down Expand Up @@ -240,7 +256,7 @@ SNAPRAID_CONF_LINES=$(grep -E '^[^#;]' $SNAPRAID_CONF)
IFS=$'\n'
# Build an array of content files
CONTENT_FILES=(
$(echo "$SNAPRAID_CONF_LINES" | grep snapraid.content | cut -d ' ' -f2)
$(echo "$SNAPRAID_CONF_LINES" | grep snapraid.content | cut -d ' ' -f2)
)

# Build an array of parity all files...
Expand Down
41 changes: 33 additions & 8 deletions snapraid-aio-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,13 @@ function main(){
fi
exit 1;
fi
echo "**SUMMARY: Equal [$EQ_COUNT] - Added [$ADD_COUNT] - Deleted [$DEL_COUNT] - Moved [$MOVE_COUNT] - Copied [$COPY_COUNT] - Updated [$UPDATE_COUNT]**"
mklog "INFO: SUMMARY: Equal [$EQ_COUNT] - Added [$ADD_COUNT] - Deleted [$DEL_COUNT] - Moved [$MOVE_COUNT] - Copied [$COPY_COUNT] - Updated [$UPDATE_COUNT]"
if [ $IGNORE_PATTERN ]; then
echo "**SUMMARY: Equal [$EQ_COUNT] - Added [$ADD_COUNT] - Deleted [$DEL_COUNT] - Moved [$MOVE_COUNT] - Copied [$COPY_COUNT] - Updated [$UPDATE_COUNT] - Ignored [$IGNORE_COUNT]**"
mklog "INFO: SUMMARY: Equal [$EQ_COUNT] - Added [$ADD_COUNT] - Deleted [$DEL_COUNT] - Moved [$MOVE_COUNT] - Copied [$COPY_COUNT] - Updated [$UPDATE_COUNT] - Ignored [$IGNORE_COUNT]"
else
echo "**SUMMARY: Equal [$EQ_COUNT] - Added [$ADD_COUNT] - Deleted [$DEL_COUNT] - Moved [$MOVE_COUNT] - Copied [$COPY_COUNT] - Updated [$UPDATE_COUNT]**"
mklog "INFO: SUMMARY: Equal [$EQ_COUNT] - Added [$ADD_COUNT] - Deleted [$DEL_COUNT] - Moved [$MOVE_COUNT] - Copied [$COPY_COUNT] - Updated [$UPDATE_COUNT]"
fi

# check if the conditions to run SYNC are met
# CHK 1 - if files have changed
Expand Down Expand Up @@ -431,10 +436,18 @@ function sanity_check() {

function get_counts() {
EQ_COUNT=$(grep -w '^ \{1,\}[0-9]* equal' "$TMP_OUTPUT" | sed 's/^ *//g' | cut -d ' ' -f1)
ADD_COUNT=$(grep -w '^ \{1,\}[0-9]* added' "$TMP_OUTPUT" | sed 's/^ *//g' | cut -d ' ' -f1)
DEL_COUNT=$(grep -w '^ \{1,\}[0-9]* removed' "$TMP_OUTPUT" | sed 's/^ *//g' | cut -d ' ' -f1)
UPDATE_COUNT=$(grep -w '^ \{1,\}[0-9]* updated' "$TMP_OUTPUT" | sed 's/^ *//g' | cut -d ' ' -f1)
MOVE_COUNT=$(grep -w '^ \{1,\}[0-9]* moved' "$TMP_OUTPUT" | sed 's/^ *//g' | cut -d ' ' -f1)
if [ $IGNORE_PATTERN ]; then
ADD_COUNT=$(grep -c -P "^add (?!.*(?:$IGNORE_PATTERN).*$).*$" "$TMP_OUTPUT")
UPDATE_COUNT=$(grep -c -P "^update (?!.*(?:$IGNORE_PATTERN).*$).*$" "$TMP_OUTPUT")
DEL_COUNT=$(grep -c -P "^remove (?!.*(?:$IGNORE_PATTERN).*$).*$" "$TMP_OUTPUT")
MOVE_COUNT=$(grep -c -P "^move (?!.*(?:$IGNORE_PATTERN).*$).*$" "$TMP_OUTPUT")
IGNORE_COUNT=$(grep -c -P ".*(?:$IGNORE_PATTERN).*" "$TMP_OUTPUT")
else
ADD_COUNT=$(grep -c -P '^add .+$' "$TMP_OUTPUT")
UPDATE_COUNT=$(grep -c -P '^update .+$' "$TMP_OUTPUT")
DEL_COUNT=$(grep -c -P '^remove .+$' "$TMP_OUTPUT")
MOVE_COUNT=$(grep -c -P '^move .+$' "$TMP_OUTPUT")
fi
COPY_COUNT=$(grep -w '^ \{1,\}[0-9]* copied' "$TMP_OUTPUT" | sed 's/^ *//g' | cut -d ' ' -f1)
# REST_COUNT=$(grep -w '^ \{1,\}[0-9]* restored' $TMP_OUTPUT | sed 's/^ *//g' | cut -d ' ' -f1)
}
Expand Down Expand Up @@ -760,10 +773,17 @@ This is a severe warning, check your logs immediately."
elif [ -z "${JOBS_DONE##*"SCRUB"*}" ] && ! grep -qw "$SCRUB_MARKER" "$TMP_OUTPUT"; then
# Scrub ran but did not complete successfully so lets warn the user
SUBJECT="[SEVERE WARNING] SCRUB job ran but did not complete successfully $EMAIL_SUBJECT_PREFIX"
NOTIFY_OUTPUT="$SUBJECT
if [ $IGNORE_PATTERN ]; then
NOTIFY_OUTPUT="$SUBJECT

This is a severe warning, check your logs immediately.
SUMMARY: Equal [$EQ_COUNT] - Added [$ADD_COUNT] - Deleted [$DEL_COUNT] - Moved [$MOVE_COUNT] - Copied [$COPY_COUNT] - Updated [$UPDATE_COUNT] - Ignored [$IGNORE_COUNT]"
else
NOTIFY_OUTPUT="$SUBJECT

This is a severe warning, check your logs immediately.
SUMMARY: Equal [$EQ_COUNT] - Added [$ADD_COUNT] - Deleted [$DEL_COUNT] - Moved [$MOVE_COUNT] - Copied [$COPY_COUNT] - Updated [$UPDATE_COUNT]"
fi
notify_warning

# minor warnings, less critical
Expand Down Expand Up @@ -813,8 +833,13 @@ SUMMARY: Equal [$EQ_COUNT] - Added [$ADD_COUNT] - Deleted [$DEL_COUNT] - Moved [
# else a good run, no warnings
else
SUBJECT="[COMPLETED] $JOBS_DONE Jobs $EMAIL_SUBJECT_PREFIX"
NOTIFY_OUTPUT="$SUBJECT
if [ $IGNORE_PATTERN ]; then
NOTIFY_OUTPUT="$SUBJECT
SUMMARY: Equal [$EQ_COUNT] - Added [$ADD_COUNT] - Deleted [$DEL_COUNT] - Moved [$MOVE_COUNT] - Copied [$COPY_COUNT] - Updated [$UPDATE_COUNT] - Ignored [$IGNORE_COUNT]"
else
NOTIFY_OUTPUT="$SUBJECT
SUMMARY: Equal [$EQ_COUNT] - Added [$ADD_COUNT] - Deleted [$DEL_COUNT] - Moved [$MOVE_COUNT] - Copied [$COPY_COUNT] - Updated [$UPDATE_COUNT]"
fi
notify_success
fi
}
Expand Down