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.
This commit is contained in:
@@ -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
|
||||
@@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Check daily whether a backup is overdue
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* 10:00:00
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
Executable
+63
@@ -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="<fc=#f7768e>$icon ?</fc>"
|
||||
elif (( days >= overdue )); then
|
||||
text="<fc=#f7768e>$icon ${days}d</fc>"
|
||||
else
|
||||
text="<fc=#ffb86c>$icon ${days}d</fc>"
|
||||
fi
|
||||
echo "$text | "
|
||||
@@ -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% { <action=`/home/fuxino/.config/xmobar/updates.sh list`>%updates%</action><action=`/home/fuxino/.config/xmobar/ens_brief.sh week`>%LZIB% <fc=#565f89>·</fc> %ens_brief%</action> | %pactl_volume% | %date% "
|
||||
, template = " | %UnsafeXMonadLog% } %uptime% | %multicpu% %coretemp% | %memory% | %kbd% { <action=`/home/fuxino/.config/xmobar/backup.sh list`>%backup%</action><action=`/home/fuxino/.config/xmobar/updates.sh list`>%updates%</action><action=`/home/fuxino/.config/xmobar/ens_brief.sh week`>%LZIB% <fc=#565f89>·</fc> %ens_brief%</action> | %pactl_volume% | %date% "
|
||||
}
|
||||
|
||||
@@ -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% { <action=`/home/fuxino/.config/xmobar/updates.sh list`>%updates%</action><action=`/home/fuxino/.config/xmobar/ens_brief.sh week`>%LZIB% <fc=#565f89>·</fc> %ens_brief%</action> | %pactl_volume% | %date% %_XMONAD_TRAYPAD% "
|
||||
, template = " | %UnsafeXMonadLog% } %uptime% | %multicpu% %coretemp% | %memory% | %kbd% { <action=`/home/fuxino/.config/xmobar/backup.sh list`>%backup%</action><action=`/home/fuxino/.config/xmobar/updates.sh list`>%updates%</action><action=`/home/fuxino/.config/xmobar/ens_brief.sh week`>%LZIB% <fc=#565f89>·</fc> %ens_brief%</action> | %pactl_volume% | %date% %_XMONAD_TRAYPAD% "
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user