2021-03-21 15:55:57 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
2021-08-04 22:27:47 +02:00
|
|
|
# using the restic cli:
|
|
|
|
# load credentials into shell via: export $(cat /path/to/credentials/file | xargs)
|
|
|
|
# useful commands for analysing restic stats [snapshot-id], restic diff [s1] [s2],
|
|
|
|
|
2021-03-21 15:55:57 +01:00
|
|
|
with lib;
|
|
|
|
with builtins;
|
2021-03-21 15:39:11 +01:00
|
|
|
let
|
2021-03-21 15:55:57 +01:00
|
|
|
hasAnyAttr = flip (attrset: any (flip hasAttr attrset));
|
|
|
|
|
2021-03-21 15:39:11 +01:00
|
|
|
resticConfig = args@{ name, extraPruneOpts ? [ ], ... }:
|
|
|
|
assert !hasAnyAttr [
|
|
|
|
"initialize"
|
|
|
|
"repository"
|
|
|
|
"s3CredentialsFile"
|
|
|
|
"passwordFile"
|
|
|
|
"pruneOpts"
|
|
|
|
] args;
|
2021-03-21 15:55:57 +01:00
|
|
|
(removeAttrs args [ "name" "extraPruneOpts" ]) // {
|
2021-03-21 15:39:11 +01:00
|
|
|
initialize = true;
|
|
|
|
repository = "b2:felschr-rpi4-backup:/${name}";
|
|
|
|
s3CredentialsFile = "/etc/nixos/secrets/restic/b2";
|
|
|
|
passwordFile = "/etc/nixos/secrets/restic/password";
|
|
|
|
timerConfig = if (args ? timerConfig) then
|
|
|
|
args.timerConfig
|
|
|
|
else {
|
|
|
|
OnCalendar = "daily";
|
|
|
|
};
|
|
|
|
pruneOpts = [
|
|
|
|
"--keep-daily 7"
|
|
|
|
"--keep-weekly 4"
|
|
|
|
"--keep-monthly 3"
|
|
|
|
"--keep-yearly 1"
|
|
|
|
] ++ extraPruneOpts;
|
|
|
|
};
|
|
|
|
in {
|
2021-05-12 23:22:52 +02:00
|
|
|
environment.systemPackages = with pkgs; [ restic ];
|
|
|
|
|
2021-03-21 15:39:11 +01:00
|
|
|
services.restic.backups.full = resticConfig {
|
|
|
|
name = "full";
|
|
|
|
paths = [ "/home" "/var" "/etc" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
services.restic.backups.data = resticConfig {
|
|
|
|
name = "data";
|
2021-03-21 14:24:35 +01:00
|
|
|
paths = [
|
|
|
|
"/etc/nixos"
|
|
|
|
"/home/felschr/.config/syncthing"
|
|
|
|
"/home/felschr/sync/backups"
|
|
|
|
"/var/lib/etebase-server"
|
|
|
|
"/var/lib/hass"
|
|
|
|
"/var/lib/mosquitto"
|
2021-04-04 18:49:39 +02:00
|
|
|
"/var/lib/photoprism"
|
2021-03-21 14:24:35 +01:00
|
|
|
"/var/lib/syncthing"
|
|
|
|
"/var/lib/jellyfin"
|
|
|
|
"/var/lib/owntracks"
|
|
|
|
];
|
|
|
|
timerConfig = { OnCalendar = "hourly"; };
|
2021-03-21 15:39:11 +01:00
|
|
|
extraPruneOpts = [ "--keep-hourly 24" ];
|
2021-08-04 22:27:47 +02:00
|
|
|
extraOptions = [ "--exclude=/var/lib/jellyfin/transcodes" ];
|
2021-03-21 14:24:35 +01:00
|
|
|
};
|
|
|
|
}
|