1import ./make-test-python.nix (
2 { pkgs, ... }:
3
4 let
5 password = "some_password";
6 repository = "/tmp/restic-backup";
7 rcloneRepository = "rclone:local:/tmp/restic-rclone-backup";
8
9 passwordFile = "${pkgs.writeText "password" "correcthorsebatterystaple"}";
10 initialize = true;
11 paths = [ "/opt" ];
12 pruneOpts = [
13 "--keep-daily 2"
14 "--keep-weekly 1"
15 "--keep-monthly 1"
16 "--keep-yearly 99"
17 ];
18 in
19 {
20 name = "restic";
21
22 meta = with pkgs.lib.maintainers; {
23 maintainers = [ bbigras i077 ];
24 };
25
26 nodes = {
27 server =
28 { pkgs, ... }:
29 {
30 services.restic.backups = {
31 remotebackup = {
32 inherit repository passwordFile initialize paths pruneOpts;
33 };
34 rclonebackup = {
35 repository = rcloneRepository;
36 rcloneConfig = {
37 type = "local";
38 one_file_system = true;
39 };
40
41 # This gets overridden by rcloneConfig.type
42 rcloneConfigFile = pkgs.writeText "rclone.conf" ''
43 [local]
44 type=ftp
45 '';
46 inherit passwordFile initialize paths pruneOpts;
47 };
48 remoteprune = {
49 inherit repository passwordFile;
50 pruneOpts = [ "--keep-last 1" ];
51 };
52 };
53
54 environment.sessionVariables.RCLONE_CONFIG_LOCAL_TYPE = "local";
55 };
56 };
57
58 testScript = ''
59 server.start()
60 server.wait_for_unit("dbus.socket")
61 server.fail(
62 "${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots",
63 "${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots",
64 )
65 server.succeed(
66 "mkdir -p /opt",
67 "touch /opt/some_file",
68 "mkdir -p /tmp/restic-rclone-backup",
69 "timedatectl set-time '2016-12-13 13:45'",
70 "systemctl start restic-backups-remotebackup.service",
71 "systemctl start restic-backups-rclonebackup.service",
72 '${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots -c | grep -e "^1 snapshot"',
73 '${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots -c | grep -e "^1 snapshot"',
74 "timedatectl set-time '2017-12-13 13:45'",
75 "systemctl start restic-backups-remotebackup.service",
76 "systemctl start restic-backups-rclonebackup.service",
77 "timedatectl set-time '2018-12-13 13:45'",
78 "systemctl start restic-backups-remotebackup.service",
79 "systemctl start restic-backups-rclonebackup.service",
80 "timedatectl set-time '2018-12-14 13:45'",
81 "systemctl start restic-backups-remotebackup.service",
82 "systemctl start restic-backups-rclonebackup.service",
83 "timedatectl set-time '2018-12-15 13:45'",
84 "systemctl start restic-backups-remotebackup.service",
85 "systemctl start restic-backups-rclonebackup.service",
86 "timedatectl set-time '2018-12-16 13:45'",
87 "systemctl start restic-backups-remotebackup.service",
88 "systemctl start restic-backups-rclonebackup.service",
89 '${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots -c | grep -e "^4 snapshot"',
90 '${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots -c | grep -e "^4 snapshot"',
91 "systemctl start restic-backups-remoteprune.service",
92 '${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots -c | grep -e "^1 snapshot"',
93 )
94 '';
95 }
96)