at 23.05-pre 5.3 kB view raw
1import ./make-test-python.nix ( 2 { pkgs, ... }: 3 4 let 5 password = "some_password"; 6 repository = "/tmp/restic-backup"; 7 repositoryFile = "${pkgs.writeText "repositoryFile" "/tmp/restic-backup-from-file"}"; 8 rcloneRepository = "rclone:local:/tmp/restic-rclone-backup"; 9 10 backupPrepareCommand = '' 11 touch /opt/backupPrepareCommand 12 test ! -e /opt/backupCleanupCommand 13 ''; 14 15 backupCleanupCommand = '' 16 rm /opt/backupPrepareCommand 17 touch /opt/backupCleanupCommand 18 ''; 19 20 passwordFile = "${pkgs.writeText "password" "correcthorsebatterystaple"}"; 21 initialize = true; 22 paths = [ "/opt" ]; 23 pruneOpts = [ 24 "--keep-daily 2" 25 "--keep-weekly 1" 26 "--keep-monthly 1" 27 "--keep-yearly 99" 28 ]; 29 in 30 { 31 name = "restic"; 32 33 meta = with pkgs.lib.maintainers; { 34 maintainers = [ bbigras i077 ]; 35 }; 36 37 nodes = { 38 server = 39 { pkgs, ... }: 40 { 41 services.restic.backups = { 42 remotebackup = { 43 inherit repository passwordFile initialize paths pruneOpts backupPrepareCommand backupCleanupCommand; 44 }; 45 remotebackup-from-file = { 46 inherit repositoryFile passwordFile initialize paths pruneOpts; 47 }; 48 rclonebackup = { 49 repository = rcloneRepository; 50 rcloneConfig = { 51 type = "local"; 52 one_file_system = true; 53 }; 54 55 # This gets overridden by rcloneConfig.type 56 rcloneConfigFile = pkgs.writeText "rclone.conf" '' 57 [local] 58 type=ftp 59 ''; 60 inherit passwordFile initialize paths pruneOpts; 61 }; 62 remoteprune = { 63 inherit repository passwordFile; 64 pruneOpts = [ "--keep-last 1" ]; 65 }; 66 custompackage = { 67 inherit repository passwordFile paths; 68 package = pkgs.writeShellScriptBin "restic" '' 69 echo "$@" >> /tmp/fake-restic.log; 70 ''; 71 72 pruneOpts = [ "--keep-last 1" ]; 73 checkOpts = [ "--some-check-option" ]; 74 }; 75 }; 76 77 environment.sessionVariables.RCLONE_CONFIG_LOCAL_TYPE = "local"; 78 }; 79 }; 80 81 testScript = '' 82 server.start() 83 server.wait_for_unit("dbus.socket") 84 server.fail( 85 "${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots", 86 '${pkgs.restic}/bin/restic --repository-file ${repositoryFile} -p ${passwordFile} snapshots"', 87 "${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots", 88 "grep 'backup .* /opt' /tmp/fake-restic.log", 89 ) 90 server.succeed( 91 "mkdir -p /opt", 92 "touch /opt/some_file", 93 "mkdir -p /tmp/restic-rclone-backup", 94 "timedatectl set-time '2016-12-13 13:45'", 95 "systemctl start restic-backups-remotebackup.service", 96 "rm /opt/backupCleanupCommand", 97 "systemctl start restic-backups-remotebackup-from-file.service", 98 "systemctl start restic-backups-rclonebackup.service", 99 '${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots -c | grep -e "^1 snapshot"', 100 '${pkgs.restic}/bin/restic --repository-file ${repositoryFile} -p ${passwordFile} snapshots -c | grep -e "^1 snapshot"', 101 '${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots -c | grep -e "^1 snapshot"', 102 "systemctl start restic-backups-custompackage.service", 103 "grep 'backup .* /opt' /tmp/fake-restic.log", 104 "grep 'check .* --some-check-option' /tmp/fake-restic.log", 105 "timedatectl set-time '2017-12-13 13:45'", 106 "systemctl start restic-backups-remotebackup.service", 107 "rm /opt/backupCleanupCommand", 108 "systemctl start restic-backups-rclonebackup.service", 109 "timedatectl set-time '2018-12-13 13:45'", 110 "systemctl start restic-backups-remotebackup.service", 111 "rm /opt/backupCleanupCommand", 112 "systemctl start restic-backups-rclonebackup.service", 113 "timedatectl set-time '2018-12-14 13:45'", 114 "systemctl start restic-backups-remotebackup.service", 115 "rm /opt/backupCleanupCommand", 116 "systemctl start restic-backups-rclonebackup.service", 117 "timedatectl set-time '2018-12-15 13:45'", 118 "systemctl start restic-backups-remotebackup.service", 119 "rm /opt/backupCleanupCommand", 120 "systemctl start restic-backups-rclonebackup.service", 121 "timedatectl set-time '2018-12-16 13:45'", 122 "systemctl start restic-backups-remotebackup.service", 123 "rm /opt/backupCleanupCommand", 124 "systemctl start restic-backups-rclonebackup.service", 125 '${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots -c | grep -e "^4 snapshot"', 126 '${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots -c | grep -e "^4 snapshot"', 127 "systemctl start restic-backups-remoteprune.service", 128 '${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots -c | grep -e "^1 snapshot"', 129 ) 130 ''; 131 } 132)