backup-warning.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/sh
  2. max_age="$(expr 60 \* 60 \* 24 \* 7)"
  3. max_age_text="eine Woche"
  4. dialog_timeout_ms=60000
  5. text_summary="Datensicherung ist alt"
  6. text_body="Die Datensicherung ist älter als $max_age_text.\nBitte JETZT eine Datensicherung durchführen."
  7. ####
  8. die()
  9. {
  10. echo "$*" >&2
  11. exit 1
  12. }
  13. # Check if the backup is too old
  14. stamp=/var/lib/simplebackup/stamp
  15. too_old=0
  16. if [ -r "$stamp" ]; then
  17. backup_time="$(cat "$stamp")"
  18. now="$(date --utc '+%s')"
  19. if [ -z "$backup_time" ] || [ -z "$now" ]; then
  20. echo "Simplebackup: Failed to get time stamps." >&2
  21. too_old=1
  22. else
  23. diff="$(expr "$now" - "$backup_time")"
  24. if [ -z "$diff" ]; then
  25. echo "Simplebackup: Failed to calculate age." >&2
  26. too_old=1
  27. elif [ "$diff" -gt "$max_age" ]; then
  28. echo "Simplebackup: Backup is outdated!"
  29. too_old=1
  30. fi
  31. fi
  32. else
  33. echo "Simplebackup: Time stamp not found." >&2
  34. too_old=1
  35. fi
  36. # Display a desktop notification, if the backup is too old.
  37. if [ "$too_old" -ne 0 ]; then
  38. [ -n "$DISPLAY" ] || export DISPLAY=:0.0
  39. [ -n "$XDG_RUNTIME_DIR" ] || export XDG_RUNTIME_DIR="/run/user/$(id -u)"
  40. [ -n "$HOME" ] || export HOME="/home/$(id -un)"
  41. [ -n "$XAUTHORITY" ] || export XAUTHORITY="$HOME/.Xauthority"
  42. export PATH="/usr/bin:$PATH"
  43. notify-send \
  44. -t "$dialog_timeout_ms" \
  45. -a "Backup" \
  46. -u normal \
  47. -i dialog-warning \
  48. "$text_summary" \
  49. "$text_body" \
  50. || die "Failed to run notify-send"
  51. fi
  52. exit 0