diff --git a/configurations/server.nix b/configurations/server.nix index 4f20d94..38abdb6 100644 --- a/configurations/server.nix +++ b/configurations/server.nix @@ -3,6 +3,7 @@ # The host record lives in configurations/default.nix; this file is only the # module body. `xlib` (identity, dirs, helpers) arrives as a module argument. { + config, lib, pkgs, xlib, @@ -59,6 +60,14 @@ "noauto" "x-systemd.automount" ]; + # Владелец тома — postgres: с 2026-12-03 на этот диск пишутся дампы + # `postgresqlBackup` (modules/server/postgresql.nix), а сервис работает + # под пользователем postgres и на exFAT не может писать в каталоги, + # принадлежащие uid=1000 (права там задаются только при монтировании). + # Проверено на тестовом exFAT-образе: при uid/gid=postgres юнит создаёт + # каталог и пишет дамп; при uid=1000 — EACCES. + ownerUid = config.users.users.postgres.uid; + ownerGid = config.users.groups.postgres.gid; }) // (xlib.helpers.mkExfatMount { path = xlib.dirs.mobile-drive; diff --git a/lib/xlib/helpers.nix b/lib/xlib/helpers.nix index 480d49f..5475025 100644 --- a/lib/xlib/helpers.nix +++ b/lib/xlib/helpers.nix @@ -132,6 +132,11 @@ let uuid ? null, label ? null, options ? [ ], + # exFAT не хранит владельца: uid/gid задаются при монтировании и + # действуют на ВСЕ inode тома. Тому, который должен быть записываем + # сервисным пользователем (не владельцем консоли), нужен свой владелец. + ownerUid ? null, + ownerGid ? null, }: { "${path}" = { @@ -139,8 +144,8 @@ let fsType = "exfat"; options = [ "nofail" - "uid=${toString uid}" - "gid=${toString gid}" + "uid=${toString (if ownerUid != null then ownerUid else uid)}" + "gid=${toString (if ownerGid != null then ownerGid else gid)}" ] ++ options; }; diff --git a/modules/server/postgresql.nix b/modules/server/postgresql.nix index c134237..754479f 100644 --- a/modules/server/postgresql.nix +++ b/modules/server/postgresql.nix @@ -20,12 +20,35 @@ in enable = true; package = pkgs.postgresql_17; }; - # postgresqlBackup.enable = true; + # Дампы — на архивный диск, рядом с rsync-зеркалом (решение владельца + # 2026-12-03: «через postgresql бэкапы как дополнительная мера, на этот + # же диск, куда делается rsync зеркало»). Зеркало не выключается: это + # две независимые копии, а не замена одной другой. + # + # 03:20, а не «daily» как у rsync-archivesta (modules/server/systemd.nix, + # OnCalendar = "daily" = 00:00): дамп и зеркало не должны одновременно + # читать один и тот же живой PostgreSQL и писать на один и тот же диск. + postgresqlBackup = { + enable = true; + location = "${xlib.dirs.archive-drive}/postgresql"; + startAt = "*-*-* 03:20:00"; + compression = "zstd"; + }; }; systemd = storage.systemd // { # `unitConfig` → `[Unit]`: `ConditionPathIsMountPoint` is a unit-level # directive and is ignored by systemd in `[Service]` (T4/R1.2). services.postgresql.unitConfig = xlib.helpers.mkStorageGuard xlib; + + # Юнит дампов (имя задаёт nixpkgs: `postgresqlBackup` при backupAll). + # Якорь защиты — архивный диск, а не server-home: если /mnt/archive не + # смонтирован, дамп уйдёт в пустой каталог на корневой ФС и потеряется. + # mkStorageGuard берётся как есть (он же отключает guard на vds), якорь + # переопределяется на архивный том. + services.postgresqlBackup.unitConfig = (xlib.helpers.mkStorageGuard xlib) // { + ConditionPathIsMountPoint = [ xlib.dirs.archive-drive ]; + RequiresMountsFor = [ xlib.dirs.archive-drive ]; + }; }; }