diff --git a/hosts/yodaNas/configuration.nix b/hosts/yodaNas/configuration.nix index 31f8f61..46ccc0d 100644 --- a/hosts/yodaNas/configuration.nix +++ b/hosts/yodaNas/configuration.nix @@ -56,7 +56,8 @@ in ../../modules/journalwatch.nix #../../modules/waydroid.nix #../../modules/ntfs.nix - #../../modules/veracrypt.nix + #../../modules/veracrypt.nix + ../../modules/btrbk ]; networking.hostName = "yodaNas"; diff --git a/hosts/yodaTab/configuration.nix b/hosts/yodaTab/configuration.nix index faf5c1d..12bffe4 100644 --- a/hosts/yodaTab/configuration.nix +++ b/hosts/yodaTab/configuration.nix @@ -55,6 +55,7 @@ in #../../modules/waydroid.nix ../../modules/ntfs.nix #../../modules/veracrypt.nix + #../../modules/btrbk ]; networking.hostName = "yodaTab"; diff --git a/hosts/yodaTux/configuration.nix b/hosts/yodaTux/configuration.nix index ce9b451..85523fd 100644 --- a/hosts/yodaTux/configuration.nix +++ b/hosts/yodaTux/configuration.nix @@ -54,7 +54,8 @@ in #../../modules/journalwatch.nix #../../modules/waydroid.nix ../../modules/ntfs.nix - #../../modules/veracrypt.nix + #../../modules/veracrypt.nix + #../../modules/btrbk ]; networking.hostName = "yodaTux"; diff --git a/hosts/yodaYoga/configuration.nix b/hosts/yodaYoga/configuration.nix index 9b6dc98..b33e4f0 100644 --- a/hosts/yodaYoga/configuration.nix +++ b/hosts/yodaYoga/configuration.nix @@ -56,7 +56,8 @@ in ../../modules/journalwatch.nix #../../modules/waydroid.nix #../../modules/ntfs.nix - #../../modules/veracrypt.nix + #../../modules/veracrypt.nix + #../../modules/btrbk ]; networking.hostName = "yodaYoga"; diff --git a/modules/btrbk/default.nix b/modules/btrbk/default.nix new file mode 100644 index 0000000..8afb8aa --- /dev/null +++ b/modules/btrbk/default.nix @@ -0,0 +1,108 @@ +{ config, pkgs, ... }: + +{ + # For each instance, a service and timer will be created: + # systemctl list-unit-files | grep btrbk + # #=> btrbk-.service + # #=> btrbk-.timer + # + # If onCalendar is set to null, one can manually execute btrbk with + # sudo systemctl start btrbk-.service + + # Print generated systemd unit file + # cat "$(systemctl show -P FragmentPath btrbk-.service)" + + # TODO: Maybe the following is not necessary if using hd-idle anyways (!) + # TODO: Mount/Unmount backup drive + # Example1: + # - https://github.com/oxalica/nixos-config/blob/1b18628afda9cecca0bc8c348b91e3ae6ab56905/nixos/invar/btrbk.nix#L55 + # - https://github.com/oxalica/nixos-config/blob/1b18628afda9cecca0bc8c348b91e3ae6ab56905/nixos/invar/btrbk.nix#L64 + # Example2: + # - https://github.com/emmanuelrosa/erosanix/blob/master/modules/btrbk.nix#L35-L42C7 + + # Spin down (unmounted/inactive) HDD disk. + # Inspired by https://www.reddit.com/r/NixOS/comments/751i5t/comment/do3f3l7/ + # +# environment.systemPackages = with pkgs; [ +# hd-idle +# ]; +# systemd.services.hd-idle = { +# description = "Spin down inactive HDD"; +# wantedBy = [ "multi-user.target" ]; +# serviceConfig = { +# Type = "simple"; +# # Options: +# # -a : Select disk for subsequent parameters. +# # -i 180: Spin down after 2 minutes (180 seconds) of inactivity. +# ExecStart = "${pkgs.hd-idle}/bin/hd-idle -a /dev/disk/by-id/XXX-XXX-XXX -i 180"; # TODO make disk id configurable +# }; +# }; + + services.btrbk = { + extraPackages = [ pkgs.lz4 ]; + # Lowest scheduling priority. + niceness = 19; + # Set of btrbk instances. The instance named btrbk is the default one. + instances = { + +# # This is the configuration equivalent to +# # README.md section "Testing on Local Host". +# "testing-on-local-host" = { +# # The timer is disabled. The service has to be invoked manually. +# onCalendar = null; +# #onCalendar = "hourly"; +# #onCalendar = "*:0/15"; # Every 15min +# # Configuration options for btrbk. Nested attrsets translate to subsections. +# settings = { +# timestamp_format = "long"; +# stream_compress = "lz4"; +# +# snapshot_preserve_min = "2d"; +# snapshot_preserve = "24h 7d 4w 6m"; +# +# target_preserve_min = "no"; +# target_preserve = "7d 4w 6m"; +# +# volume."/mnt/top-level" = { +# snapshot_dir = "@snap"; +# target = "/mnt/usb-top-level/@snap"; +# subvolume = "@foo"; +# }; +# }; +# }; + + "local-snapshots" = { + onCalendar = "hourly"; + #onCalendar = "*:0/15"; # Every 15min + + settings = { + timestamp_format = "long"; + stream_compress = "lz4"; + + snapshot_preserve_min = "2d"; + snapshot_preserve = "24h 7d 4w 6m"; + + volume."/mnt/data/data" = { + snapshot_dir = "/mnt/data/snap"; + subvolume = { + "arch.p1st.de" = {}; + "blogger.privacy1st.de" = {}; + "changedetection.p1st.de" = {}; + "cloud.media-kollektiv.eu" = {}; + "cloud.privacy1st.de" = {}; + "git.privacy1st.de" = {}; + #"mastodon-toot-follower.privacy1st.de" = {}; + "money.p1st.de" = {}; + "music.privacy1st.de" = {}; + #"paste.p1st.de" = {}; + "proxy" = {}; + "recipe.privacy1st.de" = {}; + "traggo.privacy1st.de" = {}; + }; + }; + }; + }; + + }; + }; +}