2024-05-26 16:45:38 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2022-05-06 03:16:17 +02:00
|
|
|
|
|
|
|
# using the restic cli:
|
2022-07-04 17:12:39 +02:00
|
|
|
# load credentials into shell by adding B2 secrets to .env (see .env.example).
|
2022-05-06 03:16:17 +02:00
|
|
|
# useful commands for analysing restic stats [snapshot-id], restic diff [s1] [s2],
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
with builtins;
|
2024-05-26 16:45:38 +02:00
|
|
|
let
|
|
|
|
hasAnyAttr = flip (attrset: any (flip hasAttr attrset));
|
|
|
|
in
|
|
|
|
{
|
|
|
|
resticConfig =
|
|
|
|
args@{
|
|
|
|
name,
|
|
|
|
paths ? [ ],
|
|
|
|
ignorePatterns ? [ ],
|
|
|
|
extraBackupArgs ? [ ],
|
|
|
|
extraPruneOpts ? [ ],
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
assert
|
|
|
|
!hasAnyAttr [
|
|
|
|
"initialize"
|
|
|
|
"repository"
|
|
|
|
"s3CredentialsFile"
|
|
|
|
"passwordFile"
|
|
|
|
"pruneOpts"
|
|
|
|
] args;
|
2022-05-06 03:16:17 +02:00
|
|
|
assert (args ? paths);
|
|
|
|
{
|
|
|
|
initialize = true;
|
|
|
|
repository = "b2:felschr-backups:/${name}";
|
|
|
|
environmentFile = config.age.secrets.restic-b2.path;
|
|
|
|
passwordFile = config.age.secrets.restic-password.path;
|
|
|
|
timerConfig.OnCalendar = "daily";
|
2022-09-28 15:27:19 +02:00
|
|
|
inherit paths;
|
2024-05-26 16:45:38 +02:00
|
|
|
extraBackupArgs =
|
|
|
|
let
|
|
|
|
ignoreFile = builtins.toFile "ignore" (foldl (a: b: a + "\n" + b) "" ignorePatterns);
|
|
|
|
in
|
|
|
|
[ "--exclude-file=${ignoreFile}" ] ++ extraBackupArgs;
|
2022-05-06 03:16:17 +02:00
|
|
|
pruneOpts = [
|
|
|
|
"--keep-daily 7"
|
|
|
|
"--keep-weekly 4"
|
|
|
|
"--keep-monthly 3"
|
|
|
|
"--keep-yearly 1"
|
2022-08-11 19:35:44 +02:00
|
|
|
# reduce download bandwidth
|
|
|
|
"--max-unused 10%"
|
|
|
|
"--repack-cacheable-only"
|
2022-05-06 03:16:17 +02:00
|
|
|
] ++ extraPruneOpts;
|
2024-05-26 16:45:38 +02:00
|
|
|
}
|
|
|
|
// (removeAttrs args [
|
2022-05-06 03:16:17 +02:00
|
|
|
"name"
|
|
|
|
"paths"
|
|
|
|
"ignorePatterns"
|
2022-07-04 17:12:39 +02:00
|
|
|
"extraBackupArgs"
|
2022-05-06 03:16:17 +02:00
|
|
|
"extraPruneOpts"
|
|
|
|
]);
|
|
|
|
}
|