diff options
author | Robert Obryk <robryk@gmail.com> | 2022-12-04 00:00:58 +0100 |
---|---|---|
committer | Robert Obryk <robryk@gmail.com> | 2023-01-11 00:06:13 +0100 |
commit | 9dbdb059245ccdb8e7e8161c6a37301a5397ef6d (patch) | |
tree | a9a88d025b708f1f3058778e77cba133cce4cc20 /nixos/modules/services/backup | |
parent | 2a46ef4fff95d3ac23b65a97a1c9be54cca3ddb4 (diff) | |
download | nixlib-9dbdb059245ccdb8e7e8161c6a37301a5397ef6d.tar nixlib-9dbdb059245ccdb8e7e8161c6a37301a5397ef6d.tar.gz nixlib-9dbdb059245ccdb8e7e8161c6a37301a5397ef6d.tar.bz2 nixlib-9dbdb059245ccdb8e7e8161c6a37301a5397ef6d.tar.lz nixlib-9dbdb059245ccdb8e7e8161c6a37301a5397ef6d.tar.xz nixlib-9dbdb059245ccdb8e7e8161c6a37301a5397ef6d.tar.zst nixlib-9dbdb059245ccdb8e7e8161c6a37301a5397ef6d.zip |
nixos/restic: add exclude parameter
This provides an easy way to specify exclude patterns in config. It was already possible via extraBackupOptions; this change creates a simpler, similar to other backup services, way to specify them.
Diffstat (limited to 'nixos/modules/services/backup')
-rw-r--r-- | nixos/modules/services/backup/restic.nix | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/nixos/modules/services/backup/restic.nix b/nixos/modules/services/backup/restic.nix index 2b4188492e58..66bfc7abdb3a 100644 --- a/nixos/modules/services/backup/restic.nix +++ b/nixos/modules/services/backup/restic.nix @@ -126,6 +126,21 @@ in ]; }; + exclude = mkOption { + type = types.listOf types.str; + default = [ ]; + description = lib.mdDoc '' + Patterns to exclude when backing up. See + https://restic.readthedocs.io/en/latest/040_backup.html#excluding-files for + details on syntax. + ''; + example = [ + "/var/cache" + "/home/*/.cache" + ".git" + ]; + }; + timerConfig = mkOption { type = types.attrsOf unitOption; default = { @@ -249,6 +264,7 @@ in example = { localbackup = { paths = [ "/home" ]; + exclude = [ "/home/*/.cache" ]; repository = "/mnt/backup-hdd"; passwordFile = "/etc/nixos/secrets/restic-password"; initialize = true; @@ -280,6 +296,7 @@ in let extraOptions = concatMapStrings (arg: " -o ${arg}") backup.extraOptions; resticCmd = "${backup.package}/bin/restic${extraOptions}"; + excludeFlags = if (backup.exclude != []) then ["--exclude-file=${pkgs.writeText "exclude-patterns" (concatStringsSep "\n" backup.exclude)}"] else []; filesFromTmpFile = "/run/restic-backups-${name}/includes"; backupPaths = if (backup.dynamicFilesFrom == null) @@ -315,7 +332,7 @@ in restartIfChanged = false; serviceConfig = { Type = "oneshot"; - ExecStart = (optionals (backupPaths != "") [ "${resticCmd} backup --cache-dir=%C/restic-backups-${name} ${concatStringsSep " " backup.extraBackupArgs} ${backupPaths}" ]) + ExecStart = (optionals (backupPaths != "") [ "${resticCmd} backup --cache-dir=%C/restic-backups-${name} ${concatStringsSep " " (backup.extraBackupArgs ++ excludeFlags)} ${backupPaths}" ]) ++ pruneCmd; User = backup.user; RuntimeDirectory = "restic-backups-${name}"; |