2026-04-17 01:49:47 +04:00
|
|
|
#!/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
|
|
|
|
|
|
2026-04-17 02:27:59 +04:00
|
|
|
echo "$(date '+%Y/%m/%d %H:%M:%S') Starting backup: $SERVICE" >> "$LOG_FILE"
|
2026-04-17 01:49:47 +04:00
|
|
|
|
2026-04-17 02:27:59 +04:00
|
|
|
SYNC_ERROR=$(rclone sync "$SOURCE" "$REMOTE" \
|
|
|
|
|
--include "$FILTER" \
|
|
|
|
|
--max-age "$MAX_AGE" \
|
|
|
|
|
--bwlimit "$BW_LIMIT" \
|
|
|
|
|
--delete-before \
|
|
|
|
|
--delete-excluded \
|
2026-04-18 10:54:08 +04:00
|
|
|
--checksum \
|
|
|
|
|
$ADVANCED_CLOUD_FLAG \
|
2026-04-17 02:27:59 +04:00
|
|
|
-q 2>&1)
|
2026-04-17 01:49:47 +04:00
|
|
|
|
2026-04-17 02:27:59 +04:00
|
|
|
if [ -n "$SYNC_ERROR" ]; then
|
2026-04-17 02:56:11 +04:00
|
|
|
COUNT_ERROR=$(echo "$SYNC_ERROR" | wc -l)
|
|
|
|
|
if [ "$COUNT_ERROR" -gt 15 ]; then
|
|
|
|
|
TOP=3
|
|
|
|
|
BOTTOM=3
|
|
|
|
|
SYNC_ERROR_TRUNCATED=$(echo "$SYNC_ERROR" | head -n $TOP)
|
|
|
|
|
SKIPPED=$(($COUNT_ERROR - $TOP - $BOTTOM))
|
|
|
|
|
SYNC_ERROR_TRUNCATED="$SYNC_ERROR_TRUNCATED
|
|
|
|
|
... skipped $SKIPPED lines ...
|
|
|
|
|
$(echo "$SYNC_ERROR" | tail -n $BOTTOM)"
|
|
|
|
|
SYNC_ERROR="$SYNC_ERROR_TRUNCATED"
|
|
|
|
|
fi
|
2026-04-17 02:27:59 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
CHECK_OUT=$(rclone check "$SOURCE" "$REMOTE" \
|
|
|
|
|
--include "$FILTER" \
|
|
|
|
|
--max-age "$MAX_AGE" \
|
|
|
|
|
--one-way 2>&1)
|
2026-04-17 01:49:47 +04:00
|
|
|
|
|
|
|
|
echo "$CHECK_OUT" >> "$LOG_FILE"
|
|
|
|
|
|
2026-04-17 03:39:43 +04:00
|
|
|
DIFFS=$(echo "$CHECK_OUT" | grep -oE '[0-9]+ differences found' | awk '{print $1}' | tail -n 1)
|
2026-04-17 01:49:47 +04:00
|
|
|
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"
|
|
|
|
|
|
2026-04-17 02:27:59 +04:00
|
|
|
if [ -z "$SYNC_ERROR" ] && [ "$DIFFS" = "0" ] && ! echo "$CHECK_OUT" | grep -iq "error"; then
|
2026-04-17 01:49:47 +04:00
|
|
|
STATUS="SUCCESS"
|
|
|
|
|
TAGS="white_check_mark"
|
|
|
|
|
PRIORITY="default"
|
|
|
|
|
MSG_PREFIX="Integrity verified"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
MESSAGE="$MSG_PREFIX
|
|
|
|
|
Matching: $MATCH
|
|
|
|
|
Differences: $DIFFS
|
|
|
|
|
Storage: $REMOTE"
|
|
|
|
|
|
2026-04-17 02:27:59 +04:00
|
|
|
if [ -n "$SYNC_ERROR" ]; then
|
|
|
|
|
MESSAGE="$MESSAGE
|
|
|
|
|
$SYNC_ERROR"
|
|
|
|
|
fi
|
|
|
|
|
|
2026-04-17 01:49:47 +04:00
|
|
|
curl -s -u "$AUTH" \
|
|
|
|
|
-H "Title: $SERVICE Backup: $STATUS" \
|
|
|
|
|
-H "Priority: $PRIORITY" \
|
|
|
|
|
-H "Tags: $TAGS" \
|
|
|
|
|
-d "$MESSAGE" \
|
2026-04-18 10:54:08 +04:00
|
|
|
"$NTFY_URL" > /dev/null
|