···
1
+
import ./make-test-python.nix (
5
+
remoteRepository = "rest:http://restic_rest_server:8001/";
7
+
backupPrepareCommand = ''
8
+
touch /root/backupPrepareCommand
9
+
test ! -e /root/backupCleanupCommand
12
+
backupCleanupCommand = ''
13
+
rm /root/backupPrepareCommand
14
+
touch /root/backupCleanupCommand
17
+
testDir = pkgs.stdenvNoCC.mkDerivation {
18
+
name = "test-files-to-backup";
19
+
unpackPhase = "true";
22
+
echo some_file > $out/some_file
23
+
echo some_other_file > $out/some_other_file
25
+
echo a_file > $out/a_dir/a_file
29
+
passwordFile = "${pkgs.writeText "password" "correcthorsebatterystaple"}";
31
+
exclude = [ "/opt/excluded_file_*" ];
40
+
name = "restic-rest-server";
43
+
restic_rest_server = {
44
+
services.restic.server = {
46
+
extraFlags = [ "--no-auth" ];
47
+
listenAddress = ":8001";
49
+
networking.firewall.allowedTCPPorts = [ 8001 ];
52
+
services.restic.backups = {
54
+
inherit passwordFile paths exclude pruneOpts backupPrepareCommand backupCleanupCommand;
55
+
repository = remoteRepository;
57
+
timerConfig = null; # has no effect here, just checking that it doesn't break the service
60
+
inherit passwordFile;
61
+
repository = remoteRepository;
62
+
pruneOpts = [ "--keep-last 1" ];
69
+
restic_rest_server.start()
71
+
restic_rest_server.wait_for_unit("restic-rest-server.service")
72
+
restic_rest_server.wait_for_open_port(8001)
73
+
server.wait_for_unit("dbus.socket")
75
+
"restic-remotebackup snapshots",
79
+
"cp -rT ${testDir} /opt",
80
+
"touch /opt/excluded_file_1 /opt/excluded_file_2",
82
+
# test that remotebackup runs custom commands and produces a snapshot
83
+
"timedatectl set-time '2016-12-13 13:45'",
84
+
"systemctl start restic-backups-remotebackup.service",
85
+
"rm /root/backupCleanupCommand",
86
+
'restic-remotebackup snapshots --json | ${pkgs.jq}/bin/jq "length | . == 1"',
88
+
# test that restoring that snapshot produces the same directory
89
+
"mkdir /tmp/restore-1",
90
+
"restic-remotebackup restore latest -t /tmp/restore-1",
91
+
"diff -ru ${testDir} /tmp/restore-1/opt",
93
+
# test that we can create four snapshots in remotebackup and rclonebackup
94
+
"timedatectl set-time '2017-12-13 13:45'",
95
+
"systemctl start restic-backups-remotebackup.service",
96
+
"rm /root/backupCleanupCommand",
98
+
"timedatectl set-time '2018-12-13 13:45'",
99
+
"systemctl start restic-backups-remotebackup.service",
100
+
"rm /root/backupCleanupCommand",
102
+
"timedatectl set-time '2018-12-14 13:45'",
103
+
"systemctl start restic-backups-remotebackup.service",
104
+
"rm /root/backupCleanupCommand",
106
+
"timedatectl set-time '2018-12-15 13:45'",
107
+
"systemctl start restic-backups-remotebackup.service",
108
+
"rm /root/backupCleanupCommand",
110
+
"timedatectl set-time '2018-12-16 13:45'",
111
+
"systemctl start restic-backups-remotebackup.service",
112
+
"rm /root/backupCleanupCommand",
114
+
'restic-remotebackup snapshots --json | ${pkgs.jq}/bin/jq "length | . == 4"',
116
+
# test that remoteprune brings us back to 1 snapshot in remotebackup
117
+
"systemctl start restic-backups-remoteprune.service",
118
+
'restic-remotebackup snapshots --json | ${pkgs.jq}/bin/jq "length | . == 1"',