mirror of
https://github.com/RWejlgaard/pez-infra.git
synced 2026-05-06 04:14:43 +00:00
only send email if something went wrong with backups (#60)
This commit is contained in:
parent
4c7ea76d81
commit
1ab278e47a
1 changed files with 22 additions and 8 deletions
|
|
@ -9,13 +9,19 @@ SUBJECT="HDD Backup Report - $(date '+%Y-%m-%d %H:%M')"
|
||||||
|
|
||||||
failures=()
|
failures=()
|
||||||
report=""
|
report=""
|
||||||
|
size_error=""
|
||||||
|
|
||||||
for dir in "${DIRS[@]}"; do
|
for dir in "${DIRS[@]}"; do
|
||||||
src="/hdd/$dir"
|
src="/hdd/$dir"
|
||||||
dst="$BUCKET/$dir"
|
dst="$BUCKET/$dir"
|
||||||
echo "Syncing $src -> $dst"
|
echo "Syncing $src -> $dst"
|
||||||
|
|
||||||
output=$(rclone sync "$src" "$dst" -v 2>&1); rc=$?
|
if output=$(rclone sync "$src" "$dst" -v 2>&1); then
|
||||||
|
rc=0
|
||||||
|
else
|
||||||
|
rc=$?
|
||||||
|
fi
|
||||||
|
|
||||||
output=$(grep -v "Can't follow symlink without -L/--copy-links" <<< "$output")
|
output=$(grep -v "Can't follow symlink without -L/--copy-links" <<< "$output")
|
||||||
[[ $rc -ne 0 ]] && failures+=("$dir")
|
[[ $rc -ne 0 ]] && failures+=("$dir")
|
||||||
|
|
||||||
|
|
@ -23,7 +29,13 @@ for dir in "${DIRS[@]}"; do
|
||||||
done
|
done
|
||||||
|
|
||||||
# Get bucket storage usage
|
# Get bucket storage usage
|
||||||
bucket_usage=$(rclone size "$BUCKET" 2>&1) || bucket_usage="(failed to retrieve bucket size)"
|
if bucket_usage=$(rclone size "$BUCKET" 2>&1); then
|
||||||
|
:
|
||||||
|
else
|
||||||
|
size_error="failed to retrieve bucket size"
|
||||||
|
report+="=== Bucket Usage Error ===\n$bucket_usage\n\n"
|
||||||
|
bucket_usage="($size_error)"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ${#failures[@]} -gt 0 ]]; then
|
if [[ ${#failures[@]} -gt 0 ]]; then
|
||||||
failure_summary="FAILURES: ${failures[*]}"
|
failure_summary="FAILURES: ${failures[*]}"
|
||||||
|
|
@ -31,9 +43,11 @@ else
|
||||||
failure_summary="All syncs completed successfully."
|
failure_summary="All syncs completed successfully."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
{
|
if [[ ${#failures[@]} -gt 0 || -n "$size_error" ]]; then
|
||||||
echo -e "Backup completed: $(date '+%Y-%m-%d %H:%M:%S')"
|
{
|
||||||
echo -e "$failure_summary\n"
|
echo -e "Backup completed: $(date '+%Y-%m-%d %H:%M:%S')"
|
||||||
echo -e "=== Bucket Usage ===\n$bucket_usage\n"
|
echo -e "$failure_summary\n"
|
||||||
#echo -e "=== Sync Output ===\n$report"
|
echo -e "=== Bucket Usage ===\n$bucket_usage\n"
|
||||||
} | mutt -s "$SUBJECT" "$EMAIL"
|
echo -e "=== Sync Output ===\n$report"
|
||||||
|
} | mutt -s "$SUBJECT" "$EMAIL"
|
||||||
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue