diff --git a/nixos/modules/services/backup/tarsnap.nix b/nixos/modules/services/backup/tarsnap.nix
index 57121e238553..f0b250689494 100644
--- a/nixos/modules/services/backup/tarsnap.nix
+++ b/nixos/modules/services/backup/tarsnap.nix
@@ -5,8 +5,8 @@ with lib;
let
cfg = config.services.tarsnap;
- configFile = cfg: ''
- cachedir ${config.services.tarsnap.cachedir}
+ configFile = name: cfg: ''
+ cachedir ${config.services.tarsnap.cachedir}/${name}
keyfile ${config.services.tarsnap.keyfile}
${optionalString cfg.nodump "nodump"}
${optionalString cfg.printStats "print-stats"}
@@ -57,6 +57,12 @@ in
will refuse to run until you manually rebuild the cache with
tarsnap --fsck.
+ Note that each individual archive (specified below) has its own cache
+ directory specified under cachedir; this is because
+ tarsnap locks the cache during backups, meaning multiple services
+ archives cannot be backed up concurrently or overlap with a shared
+ cache.
+
Set to null to disable caching.
'';
};
@@ -251,6 +257,7 @@ in
mkdir -p -m 0700 ${cfg.cachedir}
chown root:root ${cfg.cachedir}
chmod 0700 ${cfg.cachedir}
+ mkdir -p -m 0700 ${cfg.cachedir}/$1
DIRS=`cat /etc/tarsnap/$1.dirs`
exec tarsnap --configfile /etc/tarsnap/$1.conf -c -f $1-$(date +"%Y%m%d%H%M%S") $DIRS
'';
@@ -269,7 +276,7 @@ in
environment.etc =
(mapAttrs' (name: cfg: nameValuePair "tarsnap/${name}.conf"
- { text = configFile cfg;
+ { text = configFile name cfg;
}) cfg.archives) //
(mapAttrs' (name: cfg: nameValuePair "tarsnap/${name}.dirs"
{ text = concatStringsSep " " cfg.directories;