Skip to content

Commit 500c92e

Browse files
authored
Merge pull request #5780 from Mic92/cert
tribuchet: bump
2 parents 8302766 + 01e59cf commit 500c92e

25 files changed

Lines changed: 105 additions & 167 deletions

File tree

flake.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

home-manager/coder.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ in
4141
};
4242

4343
home.packages = [
44-
self.packages.${pkgs.stdenv.hostPlatform.system}.bk-wait
4544
pkgs.atuin
4645
];
4746

machines/eva/modules/prometheus/rules.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
})
2828
)
2929
// {
30+
BorgbackupJobFailed = {
31+
expr = ''task_exit_status{name=~"borgbackup-job-.*"} != 0'';
32+
annotations.description = "{{$labels.name}} on {{$labels.host}} failed with exit status {{$value}}";
33+
};
3034

3135
Homeassistant = {
3236
expr = ''homeassistant_entity_available{domain="persistent_notification", entity!~"persistent_notification.http_login|persistent_notification.recorder_database_migration"} >= 0'';

nixosModules/borgbackup-zfs-snapshots.nix

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
config,
33
lib,
4+
pkgs,
45
...
56
}:
67
let
78
cfg = config.services.borgbackup-zfs-snapshots;
89
zfs = config.boot.zfs.package;
910

10-
# Get all ZFS filesystems
1111
zfsFileSystems = lib.filter (fs: fs.fsType == "zfs") (lib.attrValues config.fileSystems);
1212

1313
# Map paths to their ZFS datasets (find the most specific match)
@@ -20,30 +20,37 @@ let
2020
in
2121
if sorted != [ ] then lib.head sorted else null;
2222

23-
# Get all backup paths from clan.core.state
2423
allBackupPaths = lib.unique (
2524
lib.flatten (map (state: state.folders or [ ]) (lib.attrValues config.clan.core.state))
2625
);
2726

28-
# Get all unique ZFS datasets used for backups
2927
allBackupDatasets = lib.unique (lib.filter (d: d != null) (map pathToDataset allBackupPaths));
3028

29+
# Mount parents before children, unmount in reverse order
30+
datasetsByDepth = lib.sort (
31+
a: b: lib.stringLength a.mountPoint < lib.stringLength b.mountPoint
32+
) allBackupDatasets;
33+
3134
# Find root datasets (datasets that are not children of other datasets in our list)
3235
rootDatasets = lib.filter (
3336
ds: !lib.any (other: ds != other && lib.hasPrefix "${other.device}/" ds.device) allBackupDatasets
3437
) allBackupDatasets;
3538

36-
# Check if we have any ZFS datasets to backup
3739
hasZfsBackups = allBackupDatasets != [ ];
3840

39-
# Transform a backup path to use the snapshot directory
41+
# Snapshots are mounted explicitly under /run/borgbackup/<job> instead of
42+
# using the .zfs/snapshot automount, whose device/inode can change
43+
# mid-backup and make borg skip the tree with "file type or inode changed".
44+
snapshotMountPoint =
45+
name: dataset:
46+
"/run/borgbackup/${name}" + (if dataset.mountPoint == "/" then "" else dataset.mountPoint);
47+
4048
transformPathToSnapshot =
4149
name: path:
4250
let
4351
dataset = pathToDataset path;
4452
in
4553
if dataset != null then
46-
# Replace the mount point with the .zfs/snapshot path
4754
let
4855
relativePath = lib.removePrefix dataset.mountPoint path;
4956
# Ensure we have a leading slash for non-empty relative paths
@@ -55,7 +62,7 @@ let
5562
else
5663
"/${relativePath}";
5764
in
58-
"${dataset.mountPoint}/.zfs/snapshot/borg-${name}${relativePathWithSlash}"
65+
"${snapshotMountPoint name dataset}${relativePathWithSlash}"
5966
else
6067
path;
6168
in
@@ -81,50 +88,45 @@ in
8188
description = "Use ZFS snapshots for this backup job";
8289
};
8390

84-
# Override the paths option to add apply function
8591
paths = lib.mkOption {
8692
apply = paths: if config.useZfsSnapshots then map (transformPathToSnapshot name) paths else paths;
8793
};
8894
};
8995

90-
# Add hooks for snapshot management
9196
config = lib.mkIf config.useZfsSnapshots {
92-
# Add pre-hook to create recursive snapshots
9397
preHook = lib.mkBefore ''
94-
echo "Creating ZFS snapshots for borgbackup job ${name}"
9598
set -e
9699
97-
# Create recursive snapshots for root datasets only
100+
# clean up leftovers from a previous failed run
101+
${lib.concatMapStringsSep "\n" (fs: ''
102+
${pkgs.util-linux}/bin/umount "${snapshotMountPoint name fs}" 2>/dev/null || true
103+
'') (lib.reverseList datasetsByDepth)}
104+
${lib.concatMapStringsSep "\n" (fs: ''
105+
${zfs}/bin/zfs destroy -r "${fs.device}@borg-${name}" 2>/dev/null || true
106+
'') rootDatasets}
107+
98108
${lib.concatMapStringsSep "\n" (fs: ''
99109
if ${zfs}/bin/zfs list -H -o name "${fs.device}" >/dev/null 2>&1; then
100-
${zfs}/bin/zfs snapshot -r "${fs.device}@borg-${name}" || {
101-
echo "Failed to create recursive snapshot for ${fs.device}"
102-
exit 1
103-
}
104-
echo "Created recursive snapshot: ${fs.device}@borg-${name}"
110+
${zfs}/bin/zfs snapshot -r "${fs.device}@borg-${name}"
105111
fi
106112
'') rootDatasets}
107113
108-
# Ensure snapshot directories are accessible (trigger automount)
109-
echo "Ensuring snapshot directories are accessible..."
110114
${lib.concatMapStringsSep "\n" (fs: ''
111-
ls "${fs.mountPoint}/.zfs/snapshot/borg-${name}/" > /dev/null || {
112-
echo "Warning: Could not access snapshot directory ${fs.mountPoint}/.zfs/snapshot/borg-${name}/"
113-
}
114-
'') allBackupDatasets}
115+
mkdir -p "${snapshotMountPoint name fs}"
116+
${pkgs.util-linux}/bin/mount -t zfs -o ro "${fs.device}@borg-${name}" "${snapshotMountPoint name fs}"
117+
'') datasetsByDepth}
115118
116119
set +e
117120
'';
118121

119-
# Add post-hook to destroy recursive snapshots
120122
postHook = lib.mkAfter ''
121-
echo "Cleaning up ZFS snapshots for borgbackup job ${name}"
123+
${lib.concatMapStringsSep "\n" (fs: ''
124+
${pkgs.util-linux}/bin/umount "${snapshotMountPoint name fs}" || true
125+
'') (lib.reverseList datasetsByDepth)}
122126
123-
# Destroy recursive snapshots (only need to destroy root datasets)
127+
# only root datasets carry the recursive snapshot
124128
${lib.concatMapStringsSep "\n" (fs: ''
125-
if ${zfs}/bin/zfs list -H -o name "${fs.device}@borg-${name}" >/dev/null 2>&1; then
126-
${zfs}/bin/zfs destroy -r "${fs.device}@borg-${name}" || echo "Warning: Failed to destroy recursive snapshot ${fs.device}@borg-${name}"
127-
fi
129+
${zfs}/bin/zfs destroy -r "${fs.device}@borg-${name}" 2>/dev/null || true
128130
'') rootDatasets}
129131
'';
130132
};
@@ -134,13 +136,14 @@ in
134136
};
135137

136138
config = lib.mkIf cfg.enable {
137-
# Extend systemd services for borgbackup jobs that use ZFS snapshots
138139
systemd.services = lib.mapAttrs' (
139140
name: job:
140141
lib.nameValuePair "borgbackup-job-${name}" (
141142
lib.mkIf (job.useZfsSnapshots or false) {
142143
serviceConfig = {
143144
PrivateDevices = lib.mkForce false; # ZFS needs access to /dev/zfs
145+
# writable mountpoints for the ZFS snapshots (rest of /run is read-only)
146+
RuntimeDirectory = "borgbackup/${name}";
144147
};
145148

146149
path = [ zfs ];

nixosModules/borgbackup.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
'';
3232
postHook = ''
3333
cat > /var/log/telegraf/borgbackup-job-${config.networking.hostName}.service <<EOF
34-
task,frequency=daily last_run=$(date +%s)i,state="$([[ $exitStatus == 0 ]] && echo ok || echo fail)"
34+
task,frequency=daily last_run=$(date +%s)i,exit_status=''${exitStatus}i
3535
EOF
3636
'';
3737
exclude = [

openwrt/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ ignore_missing_imports = true
5252
line-length = 88
5353
lint.select = ["ALL"]
5454
lint.ignore = [
55+
"CPY",
5556
"T201",
5657
"S603",
5758
"TD003",

pkgs/bk-wait/bk-wait.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

pkgs/bk-wait/default.nix

Lines changed: 0 additions & 23 deletions
This file was deleted.

pkgs/cewe-fotowelt/update.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get_latest_version() -> str:
2020
affiliate_id = "x_x_x_x_6822_x_06822-BsEZQQWOPUVGg"
2121
api_url = f"https://dls.photoprintit.com/api/getClient/{KEY_ACCOUNT}-{LOCALE}/hps/{affiliate_id}/linux"
2222

23-
with urllib.request.urlopen(api_url) as response: # noqa: S310
23+
with urllib.request.urlopen(api_url) as response:
2424
compressed_data = response.read()
2525
data = gzip.decompress(compressed_data)
2626

@@ -41,7 +41,7 @@ def fetch_index(version: str) -> str:
4141
"""Fetch the index file from CEWE servers."""
4242
index_url = f"https://dls.photoprintit.com/download/Data/{KEY_ACCOUNT}-{LOCALE}/hps/{CLIENT_ID}-index-{version}.txt"
4343

44-
with urllib.request.urlopen(index_url) as response: # noqa: S310
44+
with urllib.request.urlopen(index_url) as response:
4545
content = response.read()
4646
for encoding in ["iso-8859-1", "windows-1252", "utf-8", "latin-1"]:
4747
try:

pkgs/crabfit-cli/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ line-length = 100
2020
[tool.ruff.lint]
2121
select = ["ALL"]
2222
ignore = [
23+
"CPY", # no copyright notices required
2324
"T201", # allow print()
2425
"D203", # incompatible with D211 (no-blank-line-before-class)
2526
"D213", # incompatible with D212 (multi-line-summary-first-line)

0 commit comments

Comments
 (0)