]> Git — Sourcephile - julm/julm-nix.git/blob - hosts/patate/backup.nix
backup: add rsync on patate
[julm/julm-nix.git] / hosts / patate / backup.nix
1 { pkgs, lib, config, hostName, ... }:
2 with builtins;
3 {
4 imports = [
5 backup/zfs-backup.nix
6 backup/rsync-backup.nix
7 ];
8 # Take regular snapshots, and prune old ones
9 services.sanoid = {
10 enable = true;
11 extraArgs = [ "--verbose" ];
12 datasets = {
13 "${hostName}/home" = {
14 autosnap = true;
15 autoprune = true;
16 hourly = 12;
17 daily = 3;
18 monthly = 0;
19 yearly = 0;
20 recursive = true;
21 };
22 "${hostName}/home/Downloads" = {
23 autosnap = false;
24 autoprune = false;
25 };
26 "${hostName}/home/Videos" = {
27 autosnap = false;
28 autoprune = false;
29 };
30 };
31 };
32 # Trigger backups when disks are plugged
33 services.udev.extraRules = ''
34 ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd*", ENV{ID_SERIAL}=="WDC_WD10JPVT-22A1YT0_WD-WX21AC2F3987", ENV{SYSTEMD_WANTS}+="zfs-local-backup-home@WD10JPVT.service", ENV{SYSTEMD_ALIAS}="/sys/subsystem/usb/WD10JPVT"
35 # See https://github.com/systemd/systemd/issues/7587#issuecomment-381428545
36 ACTION=="remove", SUBSYSTEM=="block", KERNEL=="sd*", ENV{ID_SERIAL}=="WDC_WD10JPVT-22A1YT0_WD-WX21AC2F3987", TAG+="systemd"
37
38 ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd*", ENV{ID_FS_LABEL}=="GE_SP", ENV{SYSTEMD_USER_WANTS}+="rsync-backup@GE_SP.service", ENV{SYSTEMD_ALIAS}="/sys/subsystem/usb/GE_SP"
39 ACTION=="remove", SUBSYSTEM=="block", KERNEL=="sd*", ENV{ID_FS_LABEL}=="GE_SP", TAG+="systemd"
40 '';
41 programs.bash.shellAliases = {
42 mount-backup-WD10JPVT = "mount-zfs-backup WD10JPVT";
43 };
44 }