Make message backups coverage-driven

This commit is contained in:
2026-07-12 15:11:29 -07:00
parent ef81c601b0
commit 674b413b4b
2 changed files with 22 additions and 11 deletions

12
nixos/flake.lock generated
View File

@@ -720,11 +720,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1783888080, "lastModified": 1783892979,
"narHash": "sha256-1vLrhj0rLtzAdl4ZhZQvPbkfDTecpiajIi+aELuJy7k=", "narHash": "sha256-6uwkCVzjTxBweTCZ4CNfwYWNZlL7ri7fe8igy0Fd/ec=",
"owner": "colonelpanic8", "owner": "colonelpanic8",
"repo": "gmcli", "repo": "gmcli",
"rev": "b85f1671eb5eeaedafdbd88c418451ed1ecbd0b3", "rev": "f4f3424091377bddf2359b3f5510a65fcc150e29",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -1417,11 +1417,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1783748403, "lastModified": 1783886947,
"narHash": "sha256-q+GrnWK5GO4vaTsOrCMQR2Cze7nrgUnGyF8V6x3hGr0=", "narHash": "sha256-qItwicCUOoUJy/mrGvIgsMe31H3qlkL0n8I1F3s8qR4=",
"owner": "colonelpanic8", "owner": "colonelpanic8",
"repo": "keepbook", "repo": "keepbook",
"rev": "d2d666e967048b2478476aeb9e3f6f8b0c034a36", "rev": "093a3bd76a524b8f3096c5fcdcd6c7ee41c53acb",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@@ -14,12 +14,21 @@
gmcliPackage = inputs.gmcli.packages.${pkgs.stdenv.hostPlatform.system}.default; gmcliPackage = inputs.gmcli.packages.${pkgs.stdenv.hostPlatform.system}.default;
gmcliArchiveRoot = "/home/imalison/Backups/gmcli/git-sync"; gmcliArchiveRoot = "/home/imalison/Backups/gmcli/git-sync";
gmcliArchiveOutput = "${gmcliArchiveRoot}/archive"; gmcliArchiveOutput = "${gmcliArchiveRoot}/archive";
gmcliTelephonyOutput = "${gmcliArchiveRoot}/telephony";
gmcliBackupLock = "/home/imalison/.local/state/gmcli/backup.lock"; gmcliBackupLock = "/home/imalison/.local/state/gmcli/backup.lock";
exportGmcliArchive = pkgs.writeShellScript "export-gmcli-archive" '' exportGmcliArchive = pkgs.writeShellScript "export-gmcli-archive" ''
set -euo pipefail set -euo pipefail
${gmcliPackage}/bin/gmcli export jsonl --out ${lib.escapeShellArg gmcliArchiveOutput} --force ${gmcliPackage}/bin/gmcli export jsonl --out ${lib.escapeShellArg gmcliArchiveOutput} --force
${gmcliPackage}/bin/gmcli export verify --dir ${lib.escapeShellArg gmcliArchiveOutput} ${gmcliPackage}/bin/gmcli export verify --dir ${lib.escapeShellArg gmcliArchiveOutput}
''; '';
exportGmcliTelephonyArchive = pkgs.writeShellScript "export-gmcli-telephony-archive" ''
set -euo pipefail
${gmcliPackage}/bin/gmcli android export-telephony \
--adb ${pkgs.android-tools}/bin/adb \
--out ${lib.escapeShellArg gmcliTelephonyOutput} \
--force --include-part-data=false
${gmcliPackage}/bin/gmcli android verify-telephony --dir ${lib.escapeShellArg gmcliTelephonyOutput}
'';
refreshGmcliArchiveUnlocked = pkgs.writeShellScript "refresh-gmcli-archive-unlocked" '' refreshGmcliArchiveUnlocked = pkgs.writeShellScript "refresh-gmcli-archive-unlocked" ''
set -uo pipefail set -uo pipefail
status=0 status=0
@@ -65,15 +74,17 @@
status=1 status=1
fi fi
${exportGmcliArchive} || status=1 ${exportGmcliArchive} || status=1
${exportGmcliTelephonyArchive} || status=1
${gmcliPackage}/bin/gmcli coverage verify || status=1
exit "$status" exit "$status"
''; '';
withGmcliBackupLock = name: command: withGmcliBackupLock = name: command:
pkgs.writeShellScript name '' pkgs.writeShellScript name ''
set -euo pipefail set -euo pipefail
exec 9>${lib.escapeShellArg gmcliBackupLock} exec 9>${lib.escapeShellArg gmcliBackupLock}
if ! ${pkgs.util-linux}/bin/flock --nonblock 9; then if ! ${pkgs.util-linux}/bin/flock --wait 1200 9; then
echo "Another gmcli backup job is already running; skipping." echo "Timed out waiting 20 minutes for another gmcli backup job" >&2
exit 0 exit 1
fi fi
exec ${command} exec ${command}
''; '';
@@ -185,9 +196,9 @@ in {
}; };
systemd.user.timers.gmcli-archive-backfill = { systemd.user.timers.gmcli-archive-backfill = {
Unit.Description = "Weekly deep Google Messages history backfill"; Unit.Description = "Daily deep Google Messages history backfill";
Timer = { Timer = {
OnCalendar = "Sun *-*-* 04:00:00"; OnCalendar = "*-*-* 04:00:00";
Persistent = true; Persistent = true;
RandomizedDelaySec = "2h"; RandomizedDelaySec = "2h";
}; };