···
+
import ./make-test-python.nix (
+
remoteRepository = "rest:http://restic_rest_server:8001/";
+
backupPrepareCommand = ''
+
touch /root/backupPrepareCommand
+
test ! -e /root/backupCleanupCommand
+
backupCleanupCommand = ''
+
rm /root/backupPrepareCommand
+
touch /root/backupCleanupCommand
+
testDir = pkgs.stdenvNoCC.mkDerivation {
+
name = "test-files-to-backup";
+
echo some_file > $out/some_file
+
echo some_other_file > $out/some_other_file
+
echo a_file > $out/a_dir/a_file
+
passwordFile = "${pkgs.writeText "password" "correcthorsebatterystaple"}";
+
exclude = [ "/opt/excluded_file_*" ];
+
name = "restic-rest-server";
+
services.restic.server = {
+
extraFlags = [ "--no-auth" ];
+
listenAddress = ":8001";
+
networking.firewall.allowedTCPPorts = [ 8001 ];
+
services.restic.backups = {
+
inherit passwordFile paths exclude pruneOpts backupPrepareCommand backupCleanupCommand;
+
repository = remoteRepository;
+
timerConfig = null; # has no effect here, just checking that it doesn't break the service
+
repository = remoteRepository;
+
pruneOpts = [ "--keep-last 1" ];
+
restic_rest_server.start()
+
restic_rest_server.wait_for_unit("restic-rest-server.service")
+
restic_rest_server.wait_for_open_port(8001)
+
server.wait_for_unit("dbus.socket")
+
"restic-remotebackup snapshots",
+
"cp -rT ${testDir} /opt",
+
"touch /opt/excluded_file_1 /opt/excluded_file_2",
+
# test that remotebackup runs custom commands and produces a snapshot
+
"timedatectl set-time '2016-12-13 13:45'",
+
"systemctl start restic-backups-remotebackup.service",
+
"rm /root/backupCleanupCommand",
+
'restic-remotebackup snapshots --json | ${pkgs.jq}/bin/jq "length | . == 1"',
+
# test that restoring that snapshot produces the same directory
+
"mkdir /tmp/restore-1",
+
"restic-remotebackup restore latest -t /tmp/restore-1",
+
"diff -ru ${testDir} /tmp/restore-1/opt",
+
# test that we can create four snapshots in remotebackup and rclonebackup
+
"timedatectl set-time '2017-12-13 13:45'",
+
"systemctl start restic-backups-remotebackup.service",
+
"rm /root/backupCleanupCommand",
+
"timedatectl set-time '2018-12-13 13:45'",
+
"systemctl start restic-backups-remotebackup.service",
+
"rm /root/backupCleanupCommand",
+
"timedatectl set-time '2018-12-14 13:45'",
+
"systemctl start restic-backups-remotebackup.service",
+
"rm /root/backupCleanupCommand",
+
"timedatectl set-time '2018-12-15 13:45'",
+
"systemctl start restic-backups-remotebackup.service",
+
"rm /root/backupCleanupCommand",
+
"timedatectl set-time '2018-12-16 13:45'",
+
"systemctl start restic-backups-remotebackup.service",
+
"rm /root/backupCleanupCommand",
+
'restic-remotebackup snapshots --json | ${pkgs.jq}/bin/jq "length | . == 4"',
+
# test that remoteprune brings us back to 1 snapshot in remotebackup
+
"systemctl start restic-backups-remoteprune.service",
+
'restic-remotebackup snapshots --json | ${pkgs.jq}/bin/jq "length | . == 1"',