More tmpfs impermanence fixes.

This commit is contained in:
2025-10-28 16:49:39 +00:00
parent ac34f029ed
commit 37aad7d951
3 changed files with 25 additions and 13 deletions

View File

@@ -19,6 +19,8 @@
enable = true; enable = true;
cache = { cache = {
hostName = config.networking.hostName; hostName = config.networking.hostName;
# NOTE: These paths are hardcoded to /persist (not using config.custom.impermanence.persistPath)
# This is acceptable since this service is only enabled on btrfs-based hosts
dataPath = "/persist/ncps/data"; dataPath = "/persist/ncps/data";
tempPath = "/persist/ncps/tmp"; tempPath = "/persist/ncps/tmp";
databaseURL = "sqlite:/persist/ncps/db/db.sqlite"; databaseURL = "sqlite:/persist/ncps/db/db.sqlite";

View File

@@ -6,8 +6,7 @@ let
btrfs = "${btrfsPkg}/bin/btrfs"; btrfs = "${btrfsPkg}/bin/btrfs";
snapshotBackup = pkgs.writeScript "kopia-snapshot-backup" (builtins.readFile ./kopia-snapshot-backup.sh); snapshotBackup = pkgs.writeScript "kopia-snapshot-backup" (builtins.readFile ./kopia-snapshot-backup.sh);
backupScript = pkgs.writeShellScript "backup-persist" '' backupScript = pkgs.writeShellScript "backup-persist" ''
target_path="/persist" target_path="${config.custom.impermanence.persistPath}"
snapshot_path="$target_path/kopia-backup-snapshot"
KOPIA_CHECK_FOR_UPDATES=false KOPIA_CHECK_FOR_UPDATES=false
${kopia} repository connect server \ ${kopia} repository connect server \
@@ -16,18 +15,29 @@ let
-p "$(cat ${config.sops.secrets.kopia.path})" \ -p "$(cat ${config.sops.secrets.kopia.path})" \
|| exit 1 || exit 1
[ -e "$snapshot_path" ] && ${btrfs} subvolume delete "$snapshot_path" # Check if target_path is on btrfs filesystem
fs_type=$(stat -f -c %T "$target_path")
${btrfs} subvolume snapshot -r "$target_path" "$snapshot_path" if [ "$fs_type" = "btrfs" ]; then
# On btrfs: use snapshot for consistency
snapshot_path="$target_path/kopia-backup-snapshot"
[ -e "$snapshot_path" ] && ${btrfs} subvolume delete "$snapshot_path"
${btrfs} subvolume snapshot -r "$target_path" "$snapshot_path"
# --no-send-snapshot-path due to https://github.com/kopia/kopia/issues/4402 # --no-send-snapshot-path due to https://github.com/kopia/kopia/issues/4402
# Exclude btrfs replication snapshots (they appear as empty dirs in the snapshot anyway) # Exclude btrfs replication snapshots (they appear as empty dirs in the snapshot anyway)
${kopia} snapshot create --no-send-snapshot-report --override-source "$target_path" \ ${kopia} snapshot create --no-send-snapshot-report --override-source "$target_path" \
--ignore "services@*" \ --ignore "services@*" \
--ignore "services-standby/services@*" \ --ignore "services-standby/services@*" \
-- "$snapshot_path" -- "$snapshot_path"
${btrfs} subvolume delete "$snapshot_path"
else
# On non-btrfs (e.g., ext4): backup directly without snapshot
${kopia} snapshot create --no-send-snapshot-report --override-source "$target_path" \
-- "$target_path"
fi
${btrfs} subvolume delete "$snapshot_path"
${kopia} repository disconnect ${kopia} repository disconnect
''; '';
in in

View File

@@ -3,8 +3,8 @@
sops = { sops = {
# sometimes the impermanence bind mount is stopped when sops needs these # sometimes the impermanence bind mount is stopped when sops needs these
age.sshKeyPaths = [ age.sshKeyPaths = [
"/persist/etc/ssh/ssh_host_ed25519_key" "${config.custom.impermanence.persistPath}/etc/ssh/ssh_host_ed25519_key"
"/persist/etc/ssh/ssh_host_rsa_key" "${config.custom.impermanence.persistPath}/etc/ssh/ssh_host_rsa_key"
]; ];
defaultSopsFile = ./../../secrets/common.yaml; defaultSopsFile = ./../../secrets/common.yaml;
secrets = { secrets = {