lol

Merge pull request #264882 from robryk/resticfix

nixos/restic: fix #264696 and add a regression test

authored by

Janik and committed by
GitHub
22aa256c dcd6057e

+14 -3
+3 -3
nixos/modules/services/backup/restic.nix
··· 345 345 } // optionalAttrs (backup.environmentFile != null) { 346 346 EnvironmentFile = backup.environmentFile; 347 347 }; 348 - } // optionalAttrs (backup.initialize || backup.dynamicFilesFrom != null || backup.backupPrepareCommand != null) { 348 + } // optionalAttrs (backup.initialize || doBackup || backup.backupPrepareCommand != null) { 349 349 preStart = '' 350 350 ${optionalString (backup.backupPrepareCommand != null) '' 351 351 ${pkgs.writeScript "backupPrepareCommand" backup.backupPrepareCommand} ··· 360 360 ${pkgs.writeScript "dynamicFilesFromScript" backup.dynamicFilesFrom} >> ${filesFromTmpFile} 361 361 ''} 362 362 ''; 363 - } // optionalAttrs (backup.dynamicFilesFrom != null || backup.backupCleanupCommand != null) { 363 + } // optionalAttrs (doBackup || backup.backupCleanupCommand != null) { 364 364 postStop = '' 365 365 ${optionalString (backup.backupCleanupCommand != null) '' 366 366 ${pkgs.writeScript "backupCleanupCommand" backup.backupCleanupCommand} 367 367 ''} 368 - ${optionalString (backup.dynamicFilesFrom != null) '' 368 + ${optionalString doBackup '' 369 369 rm ${filesFromTmpFile} 370 370 ''} 371 371 '';
+11
nixos/tests/restic.nix
··· 4 4 let 5 5 remoteRepository = "/root/restic-backup"; 6 6 remoteFromFileRepository = "/root/restic-backup-from-file"; 7 + remoteNoInitRepository = "/root/restic-backup-no-init"; 7 8 rcloneRepository = "rclone:local:/root/restic-rclone-backup"; 8 9 9 10 backupPrepareCommand = '' ··· 63 64 dynamicFilesFrom = '' 64 65 find /opt -mindepth 1 -maxdepth 1 ! -name a_dir # all files in /opt except for a_dir 65 66 ''; 67 + }; 68 + remote-noinit-backup = { 69 + inherit passwordFile exclude pruneOpts paths; 70 + initialize = false; 71 + repository = remoteNoInitRepository; 66 72 }; 67 73 rclonebackup = { 68 74 inherit passwordFile paths exclude pruneOpts; ··· 114 120 "cp -rT ${testDir} /opt", 115 121 "touch /opt/excluded_file_1 /opt/excluded_file_2", 116 122 "mkdir -p /root/restic-rclone-backup", 123 + "restic-remote-noinit-backup init", 117 124 118 125 # test that remotebackup runs custom commands and produces a snapshot 119 126 "timedatectl set-time '2016-12-13 13:45'", ··· 129 136 # test that remote-from-file-backup produces a snapshot 130 137 "systemctl start restic-backups-remote-from-file-backup.service", 131 138 'restic-remote-from-file-backup snapshots --json | ${pkgs.jq}/bin/jq "length | . == 1"', 139 + 140 + # test that remote-noinit-backup produces a snapshot 141 + "systemctl start restic-backups-remote-noinit-backup.service", 142 + 'restic-remote-noinit-backup snapshots --json | ${pkgs.jq}/bin/jq "length | . == 1"', 132 143 133 144 # test that restoring that snapshot produces the same directory 134 145 "mkdir /tmp/restore-2",