feat: added main script
This commit is contained in:
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: $0 <config_file.env>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f "$1" ]; then
|
||||
. "$1"
|
||||
else
|
||||
echo "Error: Config file $1 not found!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -d "$SOURCE" ]; then
|
||||
curl -u "$AUTH" -H "Priority: urgent" -H "Tags: no_entry" \
|
||||
-d "Source directory $SOURCE not found" "$NTFY_URL"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "$(date '+%Y/%m/%d %H:%M:%S') Cloning $SERVICE" >> "$LOG_FILE"
|
||||
|
||||
rclone sync "$SOURCE" "$REMOTE" --include "$FILTER" --max-age "$MAX_AGE" \
|
||||
--bwlimit "$BW_LIMIT" --delete-before --delete-excluded --checksum -q 2>> "$LOG_FILE"
|
||||
|
||||
CHECK_OUT=$(rclone check "$SOURCE" "$REMOTE" --include "$FILTER" --max-age "$MAX_AGE" --one-way 2>&1)
|
||||
|
||||
echo "$CHECK_OUT" >> "$LOG_FILE"
|
||||
|
||||
DIFFS=$(echo "$CHECK_OUT" | grep -oE '[0-9]+ differences found' | awk '{print $1}')
|
||||
MATCH=$(echo "$CHECK_OUT" | grep -oE '[0-9]+ matching files' | awk '{print $1}')
|
||||
|
||||
DIFFS=${DIFFS:-0}
|
||||
MATCH=${MATCH:-0}
|
||||
|
||||
STATUS="WARNING"
|
||||
TAGS="warning"
|
||||
PRIORITY="high"
|
||||
MSG_PREFIX="Check failed"
|
||||
|
||||
if [ "$DIFFS" = "0" ] && ! echo "$CHECK_OUT" | grep -iq "error"; then
|
||||
STATUS="SUCCESS"
|
||||
TAGS="white_check_mark"
|
||||
PRIORITY="default"
|
||||
MSG_PREFIX="Integrity verified"
|
||||
fi
|
||||
|
||||
MESSAGE="$MSG_PREFIX
|
||||
Matching: $MATCH
|
||||
Differences: $DIFFS
|
||||
Storage: $REMOTE"
|
||||
|
||||
curl -s -u "$AUTH" \
|
||||
-H "Title: $SERVICE Backup: $STATUS" \
|
||||
-H "Priority: $PRIORITY" \
|
||||
-H "Tags: $TAGS" \
|
||||
-d "$MESSAGE" \
|
||||
"$NTFY_URL" > /dev/null
|
||||
Reference in New Issue
Block a user