summary refs log tree commit diff
path: root/nixos/modules/services/backup/tarsnap.nix
diff options
context:
space:
mode:
authorAustin Seipp <aseipp@pobox.com>2016-01-07 04:53:32 -0600
committerAustin Seipp <aseipp@pobox.com>2016-01-07 05:54:36 -0600
commitec70f64ecd3030192a4c31573da8f6e883621700 (patch)
tree2e4ec0f90c012ccaf09298d350895c69d927f49b /nixos/modules/services/backup/tarsnap.nix
parentad796f155bc2e44d6944f002ad95596e39711670 (diff)
downloadnixlib-ec70f64ecd3030192a4c31573da8f6e883621700.tar
nixlib-ec70f64ecd3030192a4c31573da8f6e883621700.tar.gz
nixlib-ec70f64ecd3030192a4c31573da8f6e883621700.tar.bz2
nixlib-ec70f64ecd3030192a4c31573da8f6e883621700.tar.lz
nixlib-ec70f64ecd3030192a4c31573da8f6e883621700.tar.xz
nixlib-ec70f64ecd3030192a4c31573da8f6e883621700.tar.zst
nixlib-ec70f64ecd3030192a4c31573da8f6e883621700.zip
nixos: tarsnap - separate archive cachedirs
Tarsnap locks the cachedir during backup, meaning if you specify
multiple backups with a shared cache that might overlap (for example,
one backup may take an hour), secondary backups will fail. This isn't
very nice behavior for the obvious reasons.

This splits the cache dirs for each archive appropriately. Note that
this will require a rebuild of your archive caches (although if you were
only using one archive for your whole system, you can just move the
directory).

Signed-off-by: Austin Seipp <aseipp@pobox.com>
Diffstat (limited to 'nixos/modules/services/backup/tarsnap.nix')
-rw-r--r--nixos/modules/services/backup/tarsnap.nix13
1 files changed, 10 insertions, 3 deletions
diff --git a/nixos/modules/services/backup/tarsnap.nix b/nixos/modules/services/backup/tarsnap.nix
index 3a51e6b7aa6c..d9a57eedc9ba 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
           <command>tarsnap --fsck</command>.
 
+          Note that each individual archive (specified below) has its own cache
+          directory specified under <literal>cachedir</literal>; 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 <literal>null</literal> to disable caching.
         '';
       };
@@ -258,6 +264,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
       '';
@@ -280,7 +287,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;