From 12affc76f7aa9f22b529813bd4e7fb482a95cd77 Mon Sep 17 00:00:00 2001 From: Daniele Fucini Date: Sun, 25 Oct 2026 12:40:38 +0100 Subject: [PATCH] Add an xmobar indicator and daily reminder for overdue backups backup.sh shows the days since the last simple_backup (orange from 7, red from 14); backup-reminder.timer notifies daily once it is overdue. --- .config/systemd/user/backup-reminder.service | 11 ++++ .config/systemd/user/backup-reminder.timer | 9 +++ .config/xmobar/backup.sh | 63 ++++++++++++++++++++ .config/xmobar/xmobarrc_hdmi | 3 +- .config/xmobar/xmobarrc_laptop | 3 +- 5 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 .config/systemd/user/backup-reminder.service create mode 100644 .config/systemd/user/backup-reminder.timer create mode 100755 .config/xmobar/backup.sh diff --git a/.config/systemd/user/backup-reminder.service b/.config/systemd/user/backup-reminder.service new file mode 100644 index 0000000..de8ccc1 --- /dev/null +++ b/.config/systemd/user/backup-reminder.service @@ -0,0 +1,11 @@ +[Unit] +Description=Notify when the last simple_backup is 14 days old or more +StartLimitIntervalSec=2h +StartLimitBurst=4 + +[Service] +Type=oneshot +ExecStart=%h/.config/xmobar/backup.sh remind +# no notification daemon yet (e.g. caught up right after login)? retry a few times +Restart=on-failure +RestartSec=5min diff --git a/.config/systemd/user/backup-reminder.timer b/.config/systemd/user/backup-reminder.timer new file mode 100644 index 0000000..6bd603f --- /dev/null +++ b/.config/systemd/user/backup-reminder.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Check daily whether a backup is overdue + +[Timer] +OnCalendar=*-*-* 10:00:00 +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/.config/xmobar/backup.sh b/.config/xmobar/backup.sh new file mode 100755 index 0000000..91fd99f --- /dev/null +++ b/.config/xmobar/backup.sh @@ -0,0 +1,63 @@ +#!/bin/bash +# Days since the last simple_backup for xmobar, e.g. " 9d | ": hidden under 7 days, orange from 7, red from 14 +# Reads simple_backup's state file and the journal (versions before the state file only log there), whichever is newer. +# With "list": show the date in a notification (for a click on the bar) +# With "remind": notify only when a backup is overdue (run daily by backup-reminder.timer) + +warn=7 overdue=14 +state="${XDG_STATE_HOME:-$HOME/.local/state}/simple_backup/last_backup" + +last=0 dir="" +if [[ -r $state ]]; then + { read -r time; read -r dir; } < "$state" + last=$(date -d "$time" +%s 2>/dev/null) || last=0 +fi + +# The journal drops old entries, so after a long gap there may be nothing left to find +line=$(journalctl -q -t /usr/bin/simple_backup -r -o short-unix 2>/dev/null | grep -m1 'Backup completed') +jlast=${line%%.*} +if [[ $jlast =~ ^[0-9]+$ ]] && (( jlast > last )); then + last=$jlast dir="" +fi + +days=$(( ($(date +%s) - last) / 86400 )) + +age() { + case $days in + 0) echo "today" ;; + 1) echo "1 day ago" ;; + *) echo "$days days ago" ;; + esac +} + +case ${1:-} in + list) + if (( last )); then + body="$(date -d "@$last" '+%Y-%m-%d %H:%M') ($(age))" + [[ -n $dir ]] && body+=$'\n'"$dir" + else + body="No backup found" + fi + notify-send "Last backup" "$body" + exit ;; + remind) + (( last && days < overdue )) && exit 0 + if (( last )); then + body="Last backup $(age) ($(date -d "@$last" '+%Y-%m-%d'))" + else + body="No backup found" + fi + # A failure (e.g. no notification daemon yet) makes the service retry + exec notify-send "Backup overdue" "$body. Plug in the backup disk." ;; +esac + +(( last && days < warn )) && exit 0 +icon=$'\xef\x82\xa0' # nf-fa-hdd_o, as UTF-8 bytes so the locale doesn't matter +if (( ! last )); then + text="$icon ?" +elif (( days >= overdue )); then + text="$icon ${days}d" +else + text="$icon ${days}d" +fi +echo "$text | " diff --git a/.config/xmobar/xmobarrc_hdmi b/.config/xmobar/xmobarrc_hdmi index 58af4fd..6b0a770 100644 --- a/.config/xmobar/xmobarrc_hdmi +++ b/.config/xmobar/xmobarrc_hdmi @@ -52,9 +52,10 @@ Config { overrideRedirect = True , Run Com "/home/fuxino/.config/xmobar/pactl_volume.sh" [] "pactl_volume" 10 , Run Com "/home/fuxino/.config/xmobar/ens_brief.sh" [] "ens_brief" 18000 , Run Com "/home/fuxino/.config/xmobar/updates.sh" [] "updates" 600 + , Run Com "/home/fuxino/.config/xmobar/backup.sh" [] "backup" 3600 , Run UnsafeXMonadLog ] , sepChar = "%" , alignSep = "}{" - , template = "  | %UnsafeXMonadLog% } %uptime% | %multicpu% %coretemp% | %memory% |  %kbd% { %updates%%LZIB% · %ens_brief% | %pactl_volume% | %date% " + , template = "  | %UnsafeXMonadLog% } %uptime% | %multicpu% %coretemp% | %memory% |  %kbd% { %backup%%updates%%LZIB% · %ens_brief% | %pactl_volume% | %date% " } diff --git a/.config/xmobar/xmobarrc_laptop b/.config/xmobar/xmobarrc_laptop index 81f9c5b..aa40a5d 100644 --- a/.config/xmobar/xmobarrc_laptop +++ b/.config/xmobar/xmobarrc_laptop @@ -53,9 +53,10 @@ Config { overrideRedirect = True , Run Com "/home/fuxino/.config/xmobar/pactl_volume.sh" [] "pactl_volume" 10 , Run Com "/home/fuxino/.config/xmobar/ens_brief.sh" [] "ens_brief" 18000 , Run Com "/home/fuxino/.config/xmobar/updates.sh" [] "updates" 600 + , Run Com "/home/fuxino/.config/xmobar/backup.sh" [] "backup" 3600 , Run UnsafeXMonadLog ] , sepChar = "%" , alignSep = "}{" - , template = "  | %UnsafeXMonadLog% } %uptime% | %multicpu% %coretemp% | %memory% |  %kbd% { %updates%%LZIB% · %ens_brief% | %pactl_volume% | %date% %_XMONAD_TRAYPAD% " + , template = "  | %UnsafeXMonadLog% } %uptime% | %multicpu% %coretemp% | %memory% |  %kbd% { %backup%%updates%%LZIB% · %ens_brief% | %pactl_volume% | %date% %_XMONAD_TRAYPAD% " }