From d15e13c81dd4c05fe3d305cd0cb4c4b9c9e3fa17 Mon Sep 17 00:00:00 2001 From: Alexander Heldt Date: Sat, 31 Aug 2024 14:10:09 +0200 Subject: [PATCH] backwards: Backup `sync` to external drive with `restic` --- hosts/backwards/modules/default.nix | 1 + hosts/backwards/modules/restic/default.nix | 51 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 hosts/backwards/modules/restic/default.nix diff --git a/hosts/backwards/modules/default.nix b/hosts/backwards/modules/default.nix index c592aaa..ac48b4a 100644 --- a/hosts/backwards/modules/default.nix +++ b/hosts/backwards/modules/default.nix @@ -13,6 +13,7 @@ in ssh.enable = true; git.enable = true; syncthing.enable = true; + restic.enable = true; }; }; } diff --git a/hosts/backwards/modules/restic/default.nix b/hosts/backwards/modules/restic/default.nix new file mode 100644 index 0000000..a8a28b1 --- /dev/null +++ b/hosts/backwards/modules/restic/default.nix @@ -0,0 +1,51 @@ +{ lib, config, ... }: +let + enabled = config.mod.restic.enable; +in +{ + options = { + mod.restic = { + enable = lib.mkEnableOption "Enable restic"; + }; + }; + + config = lib.mkIf enabled { + fileSystems."/home/alex/backup" = { + device = "/dev/disk/by-uuid/34601701-65e6-4b2c-ac4d-8bef3dfd743f"; + fsType = "ext4"; + options = [ "nofail" ]; + }; + + services = { + restic.backups = { + "sync-to-external" = { + initialize = true; + + user = "alex"; + passwordFile = config.age.secrets.restic-password.path; + + paths = [ "/home/alex/sync" ]; + repository = "/home/alex/backup"; + + timerConfig = { + OnCalendar = "*-*-* 0/12:00:00"; # Every 12th hour, i.e. twice a day + Persistent = true; + }; + + pruneOpts = [ + "--keep-daily 1" + "--keep-weekly 7" + "--keep-yearly 12" + ]; + }; + }; + }; + + age = { + secrets = { + "restic-password".file = ../../../../secrets/backwards/restic-password.age; + }; + }; + }; +} +