aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/nixos/tests/restic.nix
blob: 67bb7f1933d66a80944dc4076b4d1009e88f792c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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"',
          )
        '';
      }
)