feat: offline backups using btrbk

feat/kile-v2
Ricard Illa 2023-03-26 17:00:32 +02:00
parent 388a657a22
commit 449a2f02fe
No known key found for this signature in database
GPG Key ID: F69A672B72E54902
2 changed files with 86 additions and 14 deletions

View File

@ -4,7 +4,23 @@
{ config, pkgs, stablePkgs, impermanence, ... }: { config, pkgs, stablePkgs, impermanence, ... }:
let home = "/home/rilla"; let
home = "/home/rilla";
run-offline-backups = pkgs.writeScriptBin "run-offline-backups" ''
#!${pkgs.dash}/bin/dash
set -xe
for x in 0 1 2; do
${pkgs.systemd}/bin/systemctl start "mnt-backups-''${x}.mount"
done && \
/run/wrappers/bin/doas -u btrbk \
${pkgs.btrbk}/bin/btrbk \
-c /etc/btrbk/offline-backups.conf \
--progress \
--verbose \
run
'';
in { in {
imports = [ ./nixos/hardware-configuration/capibara.nix ./nixos/common.nix ]; imports = [ ./nixos/hardware-configuration/capibara.nix ./nixos/common.nix ];
@ -147,7 +163,7 @@ in {
# services.thermald.enable = true; # services.thermald.enable = true;
services.tlp.enable = true; services.tlp.enable = true;
services.power-profiles-daemon.enable = false; services.power-profiles-daemon.enable = false;
environment.systemPackages = with pkgs; [ powertop acpi ]; environment.systemPackages = with pkgs; [ powertop acpi run-offline-backups ];
#services.beesd.filesystems = { #services.beesd.filesystems = {
# root = { # root = {
@ -159,20 +175,73 @@ in {
#}; #};
# todo: target and/or archive # todo: target and/or archive
services.btrbk.instances.btrbk = { services.btrbk.instances = {
onCalendar = "*:0/30"; # every 30 minutes btrbk = {
settings = { onCalendar = "*:0/30"; # every 30 minutes
snapshot_preserve = "2d"; settings = {
snapshot_preserve_min = "latest"; snapshot_preserve = "2d";
snapshot_create = "onchange"; snapshot_preserve_min = "latest";
volume."/mnt/btr_root" = { snapshot_create = "onchange";
snapshot_dir = "btrbk_snapshots"; volume."/mnt/btr_root" = {
subvolume = { snapshot_dir = "btrbk_snapshots";
data = { }; subvolume = {
persist = { }; data = { };
persist = { };
};
}; };
}; };
}; };
# doas -u btrbk btrbk -c /etc/btrbk/offline-backups.conf --dry-run --progress --verbose run
offline-backups = {
onCalendar = null;
settings = {
ssh_user = "btrbk";
ssh_identity = "/etc/btrbk/id_ed25519";
backend_remote = "btrfs-progs-doas";
volume = {
"ssh://narwhal:22/mnt/btr_pool" = {
subvolume = {
backups = { };
books = { };
certs = { };
data = { };
docker_volumes = { };
home = { };
home-data = { };
http = { };
music = { };
secrets = { };
transmission = { };
videos = { };
};
target = {
"/mnt/backups/0/btr_backup/narwhal" = { };
"/mnt/backups/1/btr_backup/narwhal" = { };
"/mnt/backups/2/btr_backup/narwhal" = { };
};
};
"ssh://suricata:22/mnt/btr_pool" = {
compat_remote = "busybox";
subvolume = {
home = { };
rancher_config = { };
backups = { };
configs = { };
};
target = {
"/mnt/backups/0/btr_backup/suricata" = { };
"/mnt/backups/1/btr_backup/suricata" = { };
"/mnt/backups/2/btr_backup/suricata" = { };
};
};
};
};
};
}; };
services.xserver.deviceSection = '' services.xserver.deviceSection = ''

View File

@ -300,7 +300,10 @@
"/etc/ssh/user_ca.pub" "/etc/ssh/user_ca.pub"
]; ];
}; };
"/mnt/data" = { directories = [ "/etc/luks-keys" ]; }; "/mnt/data" = {
directories = [ "/etc/luks-keys" ];
files = [ "/etc/btrbk/id_ed25519" ];
};
"/mnt/logs" = { directories = [ "/var/log" ]; }; "/mnt/logs" = { directories = [ "/var/log" ]; };
}; };