summary refs log tree commit diff
path: root/nixos/tests/restic.nix
diff options
context:
space:
mode:
authorBruno Bigras <bigras.bruno@gmail.com>2020-01-30 16:31:52 -0500
committerJörg Thalheim <joerg@thalheim.io>2020-02-07 10:36:53 +0000
commit42adda1ec4884e2118d59826f1294d4eadeab642 (patch)
treea294d3719a3ff20ca524222eeb6fbc9d1c2696eb /nixos/tests/restic.nix
parent5ad71cfe84a49fc27ebcf7c810bcced1361a6e6e (diff)
downloadnixpkgs-42adda1ec4884e2118d59826f1294d4eadeab642.tar
nixpkgs-42adda1ec4884e2118d59826f1294d4eadeab642.tar.gz
nixpkgs-42adda1ec4884e2118d59826f1294d4eadeab642.tar.bz2
nixpkgs-42adda1ec4884e2118d59826f1294d4eadeab642.tar.lz
nixpkgs-42adda1ec4884e2118d59826f1294d4eadeab642.tar.xz
nixpkgs-42adda1ec4884e2118d59826f1294d4eadeab642.tar.zst
nixpkgs-42adda1ec4884e2118d59826f1294d4eadeab642.zip
nixos/tests/restic.nix: add test
Diffstat (limited to 'nixos/tests/restic.nix')
-rw-r--r--nixos/tests/restic.nix63
1 files changed, 63 insertions, 0 deletions
diff --git a/nixos/tests/restic.nix b/nixos/tests/restic.nix
new file mode 100644
index 00000000000..67bb7f1933d
--- /dev/null
+++ b/nixos/tests/restic.nix
@@ -0,0 +1,63 @@
+import ./make-test-python.nix (
+  { pkgs, ... }:
+
+    let
+      password = "some_password";
+      repository = "/tmp/restic-backup";
+      passwordFile = pkgs.writeText "password" "correcthorsebatterystaple";
+    in
+      {
+        name = "restic";
+
+        meta = with pkgs.stdenv.lib.maintainers; {
+          maintainers = [ bbigras ];
+        };
+
+        nodes = {
+          server =
+            { ... }:
+              {
+                services.restic.backups = {
+                  remotebackup = {
+                    inherit repository;
+                    passwordFile = "${passwordFile}";
+                    initialize = true;
+                    paths = [ "/opt" ];
+                    pruneOpts = [
+                      "--keep-daily 2"
+                      "--keep-weekly 1"
+                      "--keep-monthly 1"
+                      "--keep-yearly 99"
+                    ];
+                  };
+                };
+              };
+        };
+
+        testScript = ''
+          server.start()
+          server.wait_for_unit("dbus.socket")
+          server.fail(
+              "${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots"
+          )
+          server.succeed(
+              "mkdir -p /opt",
+              "touch /opt/some_file",
+              "timedatectl set-time '2016-12-13 13:45'",
+              "systemctl start restic-backups-remotebackup.service",
+              '${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots -c | grep -e "^1 snapshot"',
+              "timedatectl set-time '2017-12-13 13:45'",
+              "systemctl start restic-backups-remotebackup.service",
+              "timedatectl set-time '2018-12-13 13:45'",
+              "systemctl start restic-backups-remotebackup.service",
+              "timedatectl set-time '2018-12-14 13:45'",
+              "systemctl start restic-backups-remotebackup.service",
+              "timedatectl set-time '2018-12-15 13:45'",
+              "systemctl start restic-backups-remotebackup.service",
+              "timedatectl set-time '2018-12-16 13:45'",
+              "systemctl start restic-backups-remotebackup.service",
+              '${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots -c | grep -e "^4 snapshot"',
+          )
+        '';
+      }
+)