From c162b262abd11eb1e026250021efd7f9218c25a1 Mon Sep 17 00:00:00 2001 From: L-Nafaryus Date: Wed, 3 Apr 2024 22:24:18 +0500 Subject: [PATCH] catarina: backups and snapshots #1, fs description #3 --- nixosConfigurations/catarina/README.md | 31 +++++++++++++ nixosConfigurations/catarina/default.nix | 53 +++++++++++++++++------ nixosConfigurations/catarina/hardware.nix | 12 +++++ 3 files changed, 82 insertions(+), 14 deletions(-) create mode 100644 nixosConfigurations/catarina/README.md diff --git a/nixosConfigurations/catarina/README.md b/nixosConfigurations/catarina/README.md new file mode 100644 index 0000000..1425e9f --- /dev/null +++ b/nixosConfigurations/catarina/README.md @@ -0,0 +1,31 @@ +# catarina + +## Partitions +```sh +mkfs.fat -F 32 /dev/sda1 +fatlabel /dev/sda1 boot + +mkfs.btrfs /dev/sda2 +btrfs filesystem label /dev/sda2 nixos + +mkdir -p /mnt +mount /dev/sda2 /mnt +btrfs subvolume create /mnt/root +btrfs subvolume create /mnt/nix +btrfs subvolume create /mnt/home +btrfs subvolume create /mnt/persist +btrfs subvolume create /mnt/swap +umount /mnt + +mount -o compress=zstd,subvol=root /dev/sda2 /mnt +mkdir /mnt/{boot,nix,home,persist,swap} +mount /dev/sda1 /mnt/boot +mount -o compress=zstd,noatime,subvol=nix /dev/sda2 /mnt/nix +mount -o compress=zstd,subvol=home /dev/sda2 /mnt/home +mount -o compress=zstd,subvol=persist /dev/sda2 /mnt/persist +mount -o noatime,subvol=swap /dev/sda2 /mnt/swap + +btrfs filesystem mkswapfile --size 16g --uuid clear /swap/swapfile + +mkdir -p /media/{storage,btrbk-backups,btrbk-snapshots} +``` diff --git a/nixosConfigurations/catarina/default.nix b/nixosConfigurations/catarina/default.nix index e548710..20677b2 100644 --- a/nixosConfigurations/catarina/default.nix +++ b/nixosConfigurations/catarina/default.nix @@ -161,22 +161,46 @@ rec { services.spoofdpi.enable = true; - services.qbittorrent-nox = { - enable = false; - webuiPort = 8085; - openFirewall = true; + services.btrfs.autoScrub = { + enable = true; + interval = "monthly"; + fileSystems = [ "/" ]; }; - #services.btrbk = { - # instances."catarina" = { - # onCalendar = "weekly"; - # settings = { - # volume."/" = { - # - # }; - # }; - # }; - #}; + services.btrbk = { + instances."catarina" = { + onCalendar = "daily"; + + settings = { + snapshot_preserve_min = "2d"; + snapshot_preserve = "14d"; + snapshot_dir = "/media/btrbk-snapshots"; + target_preserve_min = "no"; + target_preserve = "14d 8w *m"; + + volume."/" = { + target = "/media/btrbk-backups"; + subvolume = { + "var/lib/gitea" = {}; + "var/lib/postgresql" = {}; + "var/lib/postfix" = {}; + "var/vmail" = {}; + }; + }; + }; + }; + }; + + services.transmission = { + enable = true; + openRPCPort = true; + settings = { + rpc-bind-address = "0.0.0.0"; + rpc-whitelist = "127.0.0.1,192.168.156.101"; + download-dir = "/media/storage/downloads"; + incomplete-dir = "/media/storage/downloads/incomplete"; + }; + }; # Packages environment.systemPackages = with pkgs; [ @@ -186,6 +210,7 @@ rec { sshfs exfat btrfs-progs + btrbk lm_sensors diff --git a/nixosConfigurations/catarina/hardware.nix b/nixosConfigurations/catarina/hardware.nix index 9581d8a..2c58c06 100644 --- a/nixosConfigurations/catarina/hardware.nix +++ b/nixosConfigurations/catarina/hardware.nix @@ -93,6 +93,18 @@ fsType = "btrfs"; options = [ "subvol=swap" "noatime" ]; }; + + "/media/storage" = { + device = "/dev/disk/by-label/storage"; + fsType = "btrfs"; + options = [ "subvol=storage" "nofail" "compress=zstd" ]; + }; + + "/media/btrbk-backups" = { + device = "/dev/disk/by-label/storage"; + fsType = "btrfs"; + options = [ "subvol=btrbk-backups" "nofail" "compress=zstd" ]; + }; }; swapDevices = [