fix(backups): fix & improve ripgrep matching
This commit is contained in:
parent
68d499f5cf
commit
d20b90ecb9
|
@ -8,7 +8,8 @@ with lib;
|
|||
with builtins;
|
||||
let hasAnyAttr = flip (attrset: any (flip hasAttr attrset));
|
||||
in {
|
||||
resticConfig = args@{ name, extraPruneOpts ? [ ], ... }:
|
||||
resticConfig = args@{ name, ripgrep ? false, paths ? [ ], ignorePatterns ? [ ]
|
||||
, extraPruneOpts ? [ ], ... }:
|
||||
assert !hasAnyAttr [
|
||||
"initialize"
|
||||
"repository"
|
||||
|
@ -16,21 +17,39 @@ in {
|
|||
"passwordFile"
|
||||
"pruneOpts"
|
||||
] args;
|
||||
(removeAttrs args [ "name" "extraPruneOpts" ]) // {
|
||||
assert (args ? paths);
|
||||
assert (ripgrep || (!ripgrep && !(args ? ignorePatterns)));
|
||||
{
|
||||
initialize = true;
|
||||
repository = "b2:felschr-backups:/${name}";
|
||||
environmentFile = "/etc/nixos/secrets/restic/b2";
|
||||
passwordFile = "/etc/nixos/secrets/restic/password";
|
||||
timerConfig = if (args ? timerConfig) then
|
||||
args.timerConfig
|
||||
else {
|
||||
OnCalendar = "daily";
|
||||
};
|
||||
timerConfig.OnCalendar = "daily";
|
||||
paths = if ripgrep then null else paths;
|
||||
dynamicFilesFrom = if ripgrep then
|
||||
let
|
||||
files = foldl (a: b: "${a} ${b}") "" paths;
|
||||
ignoreFile = builtins.toFile "ignore"
|
||||
(foldl (a: b: a + "\n" + b) "" ignorePatterns);
|
||||
in ''
|
||||
${pkgs.ripgrep}/bin/rg \
|
||||
--files ${files} \
|
||||
--ignore-file ${ignoreFile} \
|
||||
| sed "s/\[/\\\[/" | sed "s/\]/\\\]/"
|
||||
''
|
||||
else
|
||||
null;
|
||||
pruneOpts = [
|
||||
"--keep-daily 7"
|
||||
"--keep-weekly 4"
|
||||
"--keep-monthly 3"
|
||||
"--keep-yearly 1"
|
||||
] ++ extraPruneOpts;
|
||||
};
|
||||
} // (removeAttrs args [
|
||||
"name"
|
||||
"ripgrep"
|
||||
"paths"
|
||||
"ignorePatterns"
|
||||
"extraPruneOpts"
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -12,27 +12,25 @@ in {
|
|||
|
||||
services.restic.backups.full = common.resticConfig {
|
||||
name = "home-pc";
|
||||
dynamicFilesFrom = let
|
||||
ignore = builtins.toFile "excludes" ''
|
||||
/var/lib/lxcfs
|
||||
/var/lib/docker
|
||||
/home/*/.local/share/Trash
|
||||
/home/*/.cache
|
||||
/home/*/Downloads
|
||||
/home/*/.npm
|
||||
/home/*/Games
|
||||
/home/*/.steam
|
||||
/home/*/.local/share/Steam
|
||||
/home/*/.local/share/lutris
|
||||
/home/felschr/media
|
||||
/home/felschr/sync
|
||||
/home/felschr/keybase
|
||||
'';
|
||||
in ''
|
||||
${pkgs.ripgrep}/bin/rg \
|
||||
--files /etc/nixos /var/lib /home \
|
||||
--ignore-file ${ignore}
|
||||
'';
|
||||
ripgrep = true;
|
||||
paths = [ "/etc/nixos" "/var/lib" "/home" ];
|
||||
ignorePatterns = [
|
||||
"/var/lib/systemd"
|
||||
"/var/lib/lxcfs"
|
||||
"/var/lib/docker"
|
||||
"/var/lib/flatpak"
|
||||
"/home/*/.local/share/Trash"
|
||||
"/home/*/.cache"
|
||||
"/home/*/Downloads"
|
||||
"/home/*/.npm"
|
||||
"/home/*/Games"
|
||||
"/home/*/.steam"
|
||||
"/home/*/.local/share/Steam"
|
||||
"/home/*/.local/share/lutris"
|
||||
"/home/felschr/media"
|
||||
"/home/felschr/sync"
|
||||
"/home/felschr/keybase"
|
||||
];
|
||||
timerConfig.OnCalendar = "0/4:00:00";
|
||||
extraPruneOpts = [ "--keep-last 6" ];
|
||||
};
|
||||
|
|
|
@ -12,17 +12,18 @@ in {
|
|||
|
||||
services.restic.backups.full = common.resticConfig {
|
||||
name = "rpi4";
|
||||
ripgrep = true;
|
||||
paths = [ "/etc/nixos" "/var/lib" "/home" ];
|
||||
ignorePatterns = [
|
||||
"/var/lib/lxcfs"
|
||||
"/var/lib/docker"
|
||||
"/var/lib/flatpak"
|
||||
"/var/lib/systemd"
|
||||
"/home/*/.local/share/Trash"
|
||||
"/home/*/.cache"
|
||||
"/var/lib/jellyfin/transcodes"
|
||||
];
|
||||
timerConfig.OnCalendar = "0/4:00:00";
|
||||
extraPruneOpts = [ "--keep-last 6" ];
|
||||
extraOptions = let
|
||||
exclude = ''
|
||||
/var/lib/lxcfs
|
||||
/var/lib/docker
|
||||
/home/*/.local/share/Trash
|
||||
/home/*/.cache
|
||||
/var/lib/jellyfin/transcodes
|
||||
'';
|
||||
in [ "--exclude=/var/lib/jellyfin/transcodes" ];
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue