update all documentation and tests

This commit is contained in:
ibizaman 2024-11-11 00:20:03 +01:00 committed by Pierre Penninckx
parent 54d7059aa7
commit 64d337e1a6
19 changed files with 129 additions and 107 deletions

View file

@ -95,7 +95,7 @@ in
}; };
backup = lib.mkOption { backup = lib.mkOption {
type = contracts.backup; type = contracts.backup.request;
description = '' description = ''
Backup configuration. This is an output option. Backup configuration. This is an output option.
@ -104,10 +104,11 @@ in
``` ```
shb.restic.instances."lldap" = { shb.restic.instances."lldap" = {
enable = true; request = config.shb.lldap.backup;
settings = {
# Options specific to Restic. enable = true;
} // config.shb.lldap.backup; };
};
``` ```
''; '';
readOnly = true; readOnly = true;

View file

@ -60,10 +60,11 @@ in
``` ```
shb.restic.instances."postgresql" = { shb.restic.instances."postgresql" = {
enable = true; request = config.shb.postgresl.backup;
settings = {
# Options specific to Restic. enable = true;
} // config.shb.postgresl.backup; };
};
``` ```
''; '';
readOnly = true; readOnly = true;

View file

@ -22,30 +22,34 @@ We assume that the folder is used by the `myservice` service and is owned by a u
```nix ```nix
shb.restic.instances.myservice = { shb.restic.instances.myservice = {
enable = true; request = {
user = "myservice";
user = "myservice"; sourceDirectories = [
"/var/lib/myfolder"
];
};
passphraseFile = "<path/to/passphrase>"; settings = {
enable = true;
repositories = [{ passphraseFile = "<path/to/passphrase>";
path = "/srv/backups/myservice";
timerConfig = { repository = {
OnCalendar = "00:00:00"; path = "/srv/backups/myservice";
RandomizedDelaySec = "3h"; timerConfig = {
OnCalendar = "00:00:00";
RandomizedDelaySec = "3h";
};
}; };
}];
sourceDirectories = [ retention = {
"/var/lib/myfolder" keep_within = "1d";
]; keep_hourly = 24;
keep_daily = 7;
retention = { keep_weekly = 4;
keep_within = "1d"; keep_monthly = 6;
keep_hourly = 24; };
keep_daily = 7;
keep_weekly = 4;
keep_monthly = 6;
}; };
}; };
``` ```
@ -59,7 +63,7 @@ This assumes you have access to such a remote S3 store, for example by using [Ba
```diff ```diff
shb.backup.instances.myservice = { shb.backup.instances.myservice = {
repositories = [{ repository = {
- path = "/srv/pool1/backups/myfolder"; - path = "/srv/pool1/backups/myfolder";
+ path = "s3:s3.us-west-000.backblazeb2.com/backups/myfolder"; + path = "s3:s3.us-west-000.backblazeb2.com/backups/myfolder";
timerConfig = { timerConfig = {
@ -71,7 +75,7 @@ This assumes you have access to such a remote S3 store, for example by using [Ba
+ AWS_ACCESS_KEY_ID.source="<path/to/access_key_id>"; + AWS_ACCESS_KEY_ID.source="<path/to/access_key_id>";
+ AWS_SECRET_ACCESS_KEY.source="<path/to/secret_access_key>"; + AWS_SECRET_ACCESS_KEY.source="<path/to/secret_access_key>";
+ }; + };
}]; };
} }
``` ```
@ -84,15 +88,13 @@ The code to backup to Backblaze with secrets stored in Sops would look like so:
```nix ```nix
shb.restic.instances.myfolder.passphraseFile = config.sops.secrets."myservice/backup/passphrase".path; shb.restic.instances.myfolder.passphraseFile = config.sops.secrets."myservice/backup/passphrase".path;
shb.restic.instances.myfolder.repositories = [ shb.restic.instances.myfolder.repository = {
{ path = "s3:s3.us-west-000.backblazeb2.com/<mybucket>";
path = "s3:s3.us-west-000.backblazeb2.com/<mybucket>"; secrets = {
secrets = { AWS_ACCESS_KEY_ID.source = config.sops.secrets."backup/b2/access_key_id".path;
AWS_ACCESS_KEY_ID.source = config.sops.secrets."backup/b2/access_key_id".path; AWS_SECRET_ACCESS_KEY.source = config.sops.secrets."backup/b2/secret_access_key".path;
AWS_SECRET_ACCESS_KEY.source = config.sops.secrets."backup/b2/secret_access_key".path; };
}; };
}
];
sops.secrets."myservice/backup/passphrase" = { sops.secrets."myservice/backup/passphrase" = {
sopsFile = ./secrets.yaml; sopsFile = ./secrets.yaml;
@ -231,7 +233,7 @@ Discovering those is easy thanks to tab-completion.
One can then restore a backup with: One can then restore a backup with:
```bash ```bash
restic-myfolder1_srv_pool1_backups restore latest -t / restic-myfolder1_srv_pool1_backups restore latest
``` ```
### Troubleshooting {#blocks-restic-maintenance-troubleshooting} ### Troubleshooting {#blocks-restic-maintenance-troubleshooting}

View file

@ -6,8 +6,6 @@ at a regular schedule.
It is a contract between a service that has files to be backed up It is a contract between a service that has files to be backed up
and a service that backs up files. and a service that backs up files.
All options in this contract should be set by the former.
The latter will then use the values of those options to know what to backup.
## Contract Reference {#backup-contract-options} ## Contract Reference {#backup-contract-options}
@ -33,7 +31,7 @@ Here is an example module defining such a `backup` option:
{ {
options = { options = {
myservice.backup = lib.mkOption { myservice.backup = lib.mkOption {
type = contracts.backup; type = contracts.backup.request;
readOnly = true; readOnly = true;
default = { default = {
user = "myservice"; user = "myservice";

View file

@ -5,6 +5,6 @@ in
{ {
options.shb.contracts.backup = lib.mkOption { options.shb.contracts.backup = lib.mkOption {
description = "Contract for backups."; description = "Contract for backups.";
type = contracts.backup; type = contracts.backup.request;
}; };
} }

View file

@ -316,7 +316,7 @@ let
}; };
backup = lib.mkOption { backup = lib.mkOption {
type = contracts.backup; type = contracts.backup.request;
description = '' description = ''
Backup configuration. This is an output option. Backup configuration. This is an output option.
@ -325,10 +325,11 @@ let
``` ```
shb.restic.instances."${name}" = { shb.restic.instances."${name}" = {
enable = true; request = config.shb.${name}.backup;
settings = {
# Options specific to Restic. enable = true;
} // config.shb.${name}.backup; };
}
``` ```
''; '';
readOnly = true; readOnly = true;

View file

@ -83,7 +83,7 @@ in
}; };
backup = lib.mkOption { backup = lib.mkOption {
type = contracts.backup; type = contracts.backup.request;
description = '' description = ''
Backup configuration. This is an output option. Backup configuration. This is an output option.
@ -92,10 +92,11 @@ in
``` ```
shb.restic.instances."audiobookshelf" = { shb.restic.instances."audiobookshelf" = {
enable = true; request = config.shb.audiobookshelf.backup;
settings = {
# Options specific to Restic. enable = true;
} // config.shb.audiobookshelf.backup; };
};
``` ```
''; '';
readOnly = true; readOnly = true;

View file

@ -234,7 +234,7 @@ in
}; };
backup = lib.mkOption { backup = lib.mkOption {
type = contracts.backup; type = contracts.backup.request;
description = '' description = ''
Backup configuration. This is an output option. Backup configuration. This is an output option.
@ -243,10 +243,11 @@ in
``` ```
shb.restic.instances."vaultwarden" = { shb.restic.instances."vaultwarden" = {
enable = true; request = config.shb.vaultwarden.backup;
settings = {
# Options specific to Restic. enable = true;
} // config.shb.vaultwarden.backup; };
};
``` ```
''; '';
readOnly = true; readOnly = true;

View file

@ -218,7 +218,7 @@ in
}; };
backup = lib.mkOption { backup = lib.mkOption {
type = contracts.backup; type = contracts.backup.request;
description = '' description = ''
Backup configuration. This is an output option. Backup configuration. This is an output option.
@ -227,10 +227,11 @@ in
``` ```
shb.restic.instances."forgejo" = { shb.restic.instances."forgejo" = {
enable = true; request = config.shb.forgejo.backup;
settings = {
# Options specific to Restic. enable = true;
} // config.shb.forgejo.backup; };
};
``` ```
''; '';
readOnly = true; readOnly = true;

View file

@ -213,8 +213,11 @@ twice with a future secrets SHB block.
Backing up Forgejo using the [Restic block](blocks-restic.html) is done like so: Backing up Forgejo using the [Restic block](blocks-restic.html) is done like so:
```nix ```nix
shb.restic.instances."forgejo" = config.shb.forgejo.backup // { shb.restic.instances."forgejo" = {
enable = true; request = config.shb.forgejo.backup;
settings = {
enable = true;
};
}; };
``` ```

View file

@ -63,7 +63,7 @@ in
}; };
backup = lib.mkOption { backup = lib.mkOption {
type = contracts.backup; type = contracts.backup.request;
description = '' description = ''
Backup configuration. This is an output option. Backup configuration. This is an output option.
@ -72,10 +72,11 @@ in
``` ```
shb.restic.instances."grocy" = { shb.restic.instances."grocy" = {
enable = true; request = config.shb.grocy.backup;
settings = {
# Options specific to Restic. enable = true;
} // config.shb.grocy.backup; };
};
``` ```
''; '';
readOnly = true; readOnly = true;

View file

@ -55,7 +55,7 @@ in
}; };
backup = lib.mkOption { backup = lib.mkOption {
type = contracts.backup; type = contracts.backup.request;
description = '' description = ''
Backup configuration. This is an output option. Backup configuration. This is an output option.
@ -64,10 +64,11 @@ in
``` ```
shb.restic.instances."hledger" = { shb.restic.instances."hledger" = {
enable = true; request = config.shb.hledger.backup;
settings = {
# Options specific to Restic. enable = true;
} // config.shb.hledger.backup; };
};
``` ```
''; '';
readOnly = true; readOnly = true;

View file

@ -137,7 +137,7 @@ in
}; };
backup = lib.mkOption { backup = lib.mkOption {
type = contracts.backup; type = contracts.backup.request;
description = '' description = ''
Backup configuration. This is an output option. Backup configuration. This is an output option.
@ -146,10 +146,11 @@ in
``` ```
shb.restic.instances."home-assistant" = { shb.restic.instances."home-assistant" = {
enable = true; request = config.shb.home-assistant.backup;
settings = {
# Options specific to Restic. enable = true;
} // config.shb.home-assistant.backup; };
};
``` ```
''; '';
readOnly = true; readOnly = true;

View file

@ -139,7 +139,7 @@ in
}; };
backup = lib.mkOption { backup = lib.mkOption {
type = contracts.backup; type = contracts.backup.request;
description = '' description = ''
Backup configuration. This is an output option. Backup configuration. This is an output option.
@ -148,10 +148,11 @@ in
``` ```
shb.restic.instances."jellyfin" = { shb.restic.instances."jellyfin" = {
enable = true; request = config.shb.jellyfin.backup;
settings = {
# Options specific to Restic. enable = true;
} // config.shb.jellyfin.backup; };
};
``` ```
''; '';
readOnly = true; readOnly = true;

View file

@ -498,7 +498,7 @@ in
backup = lib.mkOption { backup = lib.mkOption {
type = contracts.backup; type = contracts.backup.request;
description = '' description = ''
Backup configuration. This is an output option. Backup configuration. This is an output option.
@ -507,10 +507,11 @@ in
``` ```
shb.restic.instances."nextcloud" = { shb.restic.instances."nextcloud" = {
enable = true; request = config.shb.nextcloud.backup;
settings = {
# Options specific to Restic. enable = true;
} // config.shb.nextcloud.backup; };
};
``` ```
''; '';
readOnly = true; readOnly = true;

View file

@ -281,8 +281,11 @@ shb.nextcloud.postgresSettings = {
Backing up Nextcloud using the [Restic block](blocks-restic.html) is done like so: Backing up Nextcloud using the [Restic block](blocks-restic.html) is done like so:
```nix ```nix
shb.restic.instances."nextcloud" = config.shb.nextcloud.backup // { shb.restic.instances."nextcloud" = {
enable = true; request = config.shb.nextcloud.backup;
settings = {
enable = true;
};
}; };
``` ```

View file

@ -115,7 +115,7 @@ in
}; };
backup = lib.mkOption { backup = lib.mkOption {
type = contracts.backup; type = contracts.backup.request;
description = '' description = ''
Backup configuration. This is an output option. Backup configuration. This is an output option.
@ -124,10 +124,11 @@ in
``` ```
shb.restic.instances."vaultwarden" = { shb.restic.instances."vaultwarden" = {
enable = true; request = config.shb.vaultwarden.backup;
settings = {
# Options specific to Restic. enable = true;
} // config.shb.vaultwarden.backup; };
};
``` ```
''; '';
readOnly = true; readOnly = true;

View file

@ -97,8 +97,11 @@ shb.zfs.datasets."postgresql".path = "/var/lib/postgresql";
Backing up Vaultwarden using the [Restic block](blocks-restic.html) is done like so: Backing up Vaultwarden using the [Restic block](blocks-restic.html) is done like so:
```nix ```nix
shb.restic.instances."vaultwarden" = config.shb.vaultwarden.backup // { shb.restic.instances."vaultwarden" = {
enable = true; request = config.shb.vaultwarden.backup;
settings = {
enable = true;
};
}; };
``` ```

View file

@ -93,18 +93,19 @@ let
imports = [ imports = [
../../modules/blocks/restic.nix ../../modules/blocks/restic.nix
]; ];
shb.restic.instances."testinstance" = config.shb.vaultwarden.backup // { shb.restic.instances."testinstance" = {
enable = true; request = config.shb.vaultwarden.backup;
passphraseFile = toString (pkgs.writeText "passphrase" "PassPhrase"); settings = {
repositories = [ enable = true;
{ passphraseFile = toString (pkgs.writeText "passphrase" "PassPhrase");
repository = {
path = "/opt/repos/A"; path = "/opt/repos/A";
timerConfig = { timerConfig = {
OnCalendar = "00:00:00"; OnCalendar = "00:00:00";
RandomizedDelaySec = "5h"; RandomizedDelaySec = "5h";
}; };
} };
]; };
}; };
}; };
in in