blackmagic: trigger early b52->AWS clones on large immich backups #893

Merged
JakeHillion merged 1 commits from jj/uqpsvzqxyutr into main 2026-02-10 01:40:08 +00:00
3 changed files with 59 additions and 10 deletions

No files matched your search

@@ -11,6 +11,7 @@ let
libraries = with pkgs.python3Packages; [ inotify-simple requests ];
}
(builtins.readFile ./blackmagic-cam-importer.py);
in
{
options.custom.services.blackmagic-cam-importer = {
+54
View File
@@ -42,5 +42,59 @@ in
services.immich = {
enable = true;
};
systemd.services.immich-restic-clone-trigger = {
description = "Trigger early b52->AWS restic clones on large Immich backups";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
ExecStart = pkgs.writeShellScript "immich-restic-clone-trigger" ''
set -euo pipefail
THRESHOLD_GIB=4
${pkgs.systemd}/bin/journalctl -f -u restic-backups-immich.service -o cat \
| ${pkgs.gnugrep}/bin/grep --line-buffered 'Added to the repository:' \
| while IFS= read -r line; do
size=$(echo "$line" | ${pkgs.gawk}/bin/awk '{
for (i=1; i<=NF; i++) {
if ($i == "repository:") {
print $(i+1), $(i+2)
exit
}
}
}')
value=$(echo "$size" | ${pkgs.gawk}/bin/awk '{print $1}')
unit=$(echo "$size" | ${pkgs.gawk}/bin/awk '{print $2}')
gib_value=$(${pkgs.gawk}/bin/awk -v val="$value" -v unit="$unit" 'BEGIN {
if (unit == "TiB") printf "%.6f", val * 1024
else if (unit == "GiB") printf "%.6f", val
else if (unit == "MiB") printf "%.6f", val / 1024
else if (unit == "KiB") printf "%.6f", val / 1048576
else if (unit == "B") printf "%.6f", val / 1073741824
else printf "0"
}')
exceeds=$(${pkgs.gawk}/bin/awk -v gib="$gib_value" -v threshold="$THRESHOLD_GIB" 'BEGIN {
print (gib > threshold) ? "1" : "0"
}')
if [ "$exceeds" = "1" ]; then
echo "Detected large backup: ''${value} ''${unit} (''${gib_value} GiB) exceeds ''${THRESHOLD_GIB} GiB threshold"
echo "Starting early b52->AWS clone services"
${pkgs.systemd}/bin/systemctl start restic-clone-b52-aws-eu-central-2.service || echo "Failed to start aws-eu-central-2 clone"
${pkgs.systemd}/bin/systemctl start restic-clone-b52-aws-us-east-1.service || echo "Failed to start aws-us-east-1 clone"
else
echo "Backup size: ''${value} ''${unit} (''${gib_value} GiB) below ''${THRESHOLD_GIB} GiB threshold"
fi
done
'';
Restart = "always";
RestartSec = "60s";
};
};
};
}
+4 -10
View File
@@ -140,23 +140,17 @@ in
clones = [
{
repo = "aws-eu-central-2";
# delibarately rare uploads to makes packs more likely to be full
# as we can't repack on this data storage. timed to suit the
# cutoff for the deep archive move.
timerConfig = {
OnCalendar = "23:00 UTC";
RandomizedDelaySec = "30m";
OnUnitInactiveSec = "24h";
RandomizedDelaySec = "2h";
Persistent = true;
};
}
{
repo = "aws-us-east-1";
# delibarately rare uploads to makes packs more likely to be full
# as we can't repack on this data storage. timed to suit the
# cutoff for the deep archive move.
timerConfig = {
OnCalendar = "23:00 UTC";
RandomizedDelaySec = "30m";
OnUnitInactiveSec = "24h";
RandomizedDelaySec = "2h";
Persistent = true;
};
}