nixos/btrbk: allow instances without timers
This allows btrbk instances without a triggering timer by setting `onCalendar` to `null`. This is useful for manual-starting only btrbk backup settings.
This commit is contained in:
parent
e304f2f2b0
commit
60e13131b6
3 changed files with 47 additions and 3 deletions
|
@ -51,6 +51,8 @@ let
|
|||
'';
|
||||
in
|
||||
{
|
||||
meta.maintainers = with lib.maintainers; [ oxalica ];
|
||||
|
||||
options = {
|
||||
services.btrbk = {
|
||||
extraPackages = lib.mkOption {
|
||||
|
@ -76,9 +78,12 @@ in
|
|||
submodule {
|
||||
options = {
|
||||
onCalendar = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = "daily";
|
||||
description = "How often this btrbk instance is started. See systemd.time(7) for more information about the format.";
|
||||
description = ''
|
||||
How often this btrbk instance is started. See systemd.time(7) for more information about the format.
|
||||
Setting it to null disables the timer, thus this instance can only be started manually.
|
||||
'';
|
||||
};
|
||||
settings = lib.mkOption {
|
||||
type = let t = lib.types.attrsOf (lib.types.either lib.types.str (t // { description = "instances of this type recursively"; })); in t;
|
||||
|
@ -214,7 +219,8 @@ in
|
|||
};
|
||||
}
|
||||
)
|
||||
cfg.instances;
|
||||
(lib.filterAttrs (name: instance: instance.onCalendar != null)
|
||||
cfg.instances);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ in
|
|||
breitbandmessung = handleTest ./breitbandmessung.nix {};
|
||||
brscan5 = handleTest ./brscan5.nix {};
|
||||
btrbk = handleTest ./btrbk.nix {};
|
||||
btrbk-no-timer = handleTest ./btrbk-no-timer.nix {};
|
||||
buildbot = handleTest ./buildbot.nix {};
|
||||
buildkite-agents = handleTest ./buildkite-agents.nix {};
|
||||
caddy = handleTest ./caddy.nix {};
|
||||
|
|
37
nixos/tests/btrbk-no-timer.nix
Normal file
37
nixos/tests/btrbk-no-timer.nix
Normal file
|
@ -0,0 +1,37 @@
|
|||
import ./make-test-python.nix ({ lib, pkgs, ... }:
|
||||
{
|
||||
name = "btrbk-no-timer";
|
||||
meta.maintainers = with lib.maintainers; [ oxalica ];
|
||||
|
||||
nodes.machine = { ... }: {
|
||||
environment.systemPackages = with pkgs; [ btrfs-progs ];
|
||||
services.btrbk.instances.local = {
|
||||
onCalendar = null;
|
||||
settings.volume."/mnt" = {
|
||||
snapshot_dir = "btrbk/local";
|
||||
subvolume = "to_backup";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
start_all()
|
||||
|
||||
# Create btrfs partition at /mnt
|
||||
machine.succeed("truncate --size=128M /data_fs")
|
||||
machine.succeed("mkfs.btrfs /data_fs")
|
||||
machine.succeed("mkdir /mnt")
|
||||
machine.succeed("mount /data_fs /mnt")
|
||||
machine.succeed("btrfs subvolume create /mnt/to_backup")
|
||||
machine.succeed("mkdir -p /mnt/btrbk/local")
|
||||
|
||||
# The service should not have any triggering timer.
|
||||
unit = machine.get_unit_info('btrbk-local.service')
|
||||
assert "TriggeredBy" not in unit
|
||||
|
||||
# Manually starting the service should still work.
|
||||
machine.succeed("echo foo > /mnt/to_backup/bar")
|
||||
machine.start_job("btrbk-local.service")
|
||||
machine.wait_until_succeeds("cat /mnt/btrbk/local/*/bar | grep foo")
|
||||
'';
|
||||
})
|
Loading…
Reference in a new issue