| 
									
										
										
										
											2020-01-30 16:31:52 -05:00
										 |  |  | import ./make-test-python.nix ( | 
					
						
							|  |  |  |   { pkgs, ... }: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let | 
					
						
							|  |  |  |       password = "some_password"; | 
					
						
							|  |  |  |       repository = "/tmp/restic-backup"; | 
					
						
							| 
									
										
										
										
											2020-07-05 16:25:57 -04:00
										 |  |  |       rcloneRepository = "rclone:local:/tmp/restic-rclone-backup"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       passwordFile = "${pkgs.writeText "password" "correcthorsebatterystaple"}"; | 
					
						
							|  |  |  |       initialize = true; | 
					
						
							|  |  |  |       paths = [ "/opt" ]; | 
					
						
							|  |  |  |       pruneOpts = [ | 
					
						
							|  |  |  |         "--keep-daily 2" | 
					
						
							|  |  |  |         "--keep-weekly 1" | 
					
						
							|  |  |  |         "--keep-monthly 1" | 
					
						
							|  |  |  |         "--keep-yearly 99" | 
					
						
							|  |  |  |       ]; | 
					
						
							| 
									
										
										
										
											2020-01-30 16:31:52 -05:00
										 |  |  |     in | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name = "restic"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-10 20:08:30 +01:00
										 |  |  |         meta = with pkgs.lib.maintainers; { | 
					
						
							| 
									
										
										
										
											2020-07-05 16:25:57 -04:00
										 |  |  |           maintainers = [ bbigras i077 ]; | 
					
						
							| 
									
										
										
										
											2020-01-30 16:31:52 -05:00
										 |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         nodes = { | 
					
						
							|  |  |  |           server = | 
					
						
							| 
									
										
										
										
											2020-07-05 16:25:57 -04:00
										 |  |  |             { pkgs, ... }: | 
					
						
							| 
									
										
										
										
											2020-01-30 16:31:52 -05:00
										 |  |  |               { | 
					
						
							|  |  |  |                 services.restic.backups = { | 
					
						
							|  |  |  |                   remotebackup = { | 
					
						
							| 
									
										
										
										
											2020-07-05 16:25:57 -04:00
										 |  |  |                     inherit repository passwordFile initialize paths pruneOpts; | 
					
						
							|  |  |  |                   }; | 
					
						
							|  |  |  |                   rclonebackup = { | 
					
						
							|  |  |  |                     repository = rcloneRepository; | 
					
						
							|  |  |  |                     rcloneConfig = { | 
					
						
							|  |  |  |                       type = "local"; | 
					
						
							|  |  |  |                       one_file_system = true; | 
					
						
							|  |  |  |                     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     # This gets overridden by rcloneConfig.type | 
					
						
							|  |  |  |                     rcloneConfigFile = pkgs.writeText "rclone.conf" ''
 | 
					
						
							|  |  |  |                       [local] | 
					
						
							|  |  |  |                       type=ftp | 
					
						
							|  |  |  |                     '';
 | 
					
						
							|  |  |  |                     inherit passwordFile initialize paths pruneOpts; | 
					
						
							| 
									
										
										
										
											2020-01-30 16:31:52 -05:00
										 |  |  |                   }; | 
					
						
							| 
									
										
										
										
											2021-03-19 20:14:43 -04:00
										 |  |  |                   remoteprune = { | 
					
						
							|  |  |  |                     inherit repository passwordFile; | 
					
						
							|  |  |  |                     pruneOpts = [ "--keep-last 1" ]; | 
					
						
							|  |  |  |                   }; | 
					
						
							| 
									
										
										
										
											2020-01-30 16:31:52 -05:00
										 |  |  |                 }; | 
					
						
							| 
									
										
										
										
											2020-07-05 16:25:57 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 environment.sessionVariables.RCLONE_CONFIG_LOCAL_TYPE = "local"; | 
					
						
							| 
									
										
										
										
											2020-01-30 16:31:52 -05:00
										 |  |  |               }; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         testScript = ''
 | 
					
						
							|  |  |  |           server.start() | 
					
						
							|  |  |  |           server.wait_for_unit("dbus.socket") | 
					
						
							|  |  |  |           server.fail( | 
					
						
							| 
									
										
										
										
											2020-07-05 16:25:57 -04:00
										 |  |  |               "${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots", | 
					
						
							|  |  |  |               "${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots", | 
					
						
							| 
									
										
										
										
											2020-01-30 16:31:52 -05:00
										 |  |  |           ) | 
					
						
							|  |  |  |           server.succeed( | 
					
						
							|  |  |  |               "mkdir -p /opt", | 
					
						
							|  |  |  |               "touch /opt/some_file", | 
					
						
							| 
									
										
										
										
											2020-07-05 16:25:57 -04:00
										 |  |  |               "mkdir -p /tmp/restic-rclone-backup", | 
					
						
							| 
									
										
										
										
											2020-01-30 16:31:52 -05:00
										 |  |  |               "timedatectl set-time '2016-12-13 13:45'", | 
					
						
							|  |  |  |               "systemctl start restic-backups-remotebackup.service", | 
					
						
							| 
									
										
										
										
											2020-07-05 16:25:57 -04:00
										 |  |  |               "systemctl start restic-backups-rclonebackup.service", | 
					
						
							| 
									
										
										
										
											2020-01-30 16:31:52 -05:00
										 |  |  |               '${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots -c | grep -e "^1 snapshot"', | 
					
						
							| 
									
										
										
										
											2020-07-05 16:25:57 -04:00
										 |  |  |               '${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots -c | grep -e "^1 snapshot"', | 
					
						
							| 
									
										
										
										
											2020-01-30 16:31:52 -05:00
										 |  |  |               "timedatectl set-time '2017-12-13 13:45'", | 
					
						
							|  |  |  |               "systemctl start restic-backups-remotebackup.service", | 
					
						
							| 
									
										
										
										
											2020-07-05 16:25:57 -04:00
										 |  |  |               "systemctl start restic-backups-rclonebackup.service", | 
					
						
							| 
									
										
										
										
											2020-01-30 16:31:52 -05:00
										 |  |  |               "timedatectl set-time '2018-12-13 13:45'", | 
					
						
							|  |  |  |               "systemctl start restic-backups-remotebackup.service", | 
					
						
							| 
									
										
										
										
											2020-07-05 16:25:57 -04:00
										 |  |  |               "systemctl start restic-backups-rclonebackup.service", | 
					
						
							| 
									
										
										
										
											2020-01-30 16:31:52 -05:00
										 |  |  |               "timedatectl set-time '2018-12-14 13:45'", | 
					
						
							|  |  |  |               "systemctl start restic-backups-remotebackup.service", | 
					
						
							| 
									
										
										
										
											2020-07-05 16:25:57 -04:00
										 |  |  |               "systemctl start restic-backups-rclonebackup.service", | 
					
						
							| 
									
										
										
										
											2020-01-30 16:31:52 -05:00
										 |  |  |               "timedatectl set-time '2018-12-15 13:45'", | 
					
						
							|  |  |  |               "systemctl start restic-backups-remotebackup.service", | 
					
						
							| 
									
										
										
										
											2020-07-05 16:25:57 -04:00
										 |  |  |               "systemctl start restic-backups-rclonebackup.service", | 
					
						
							| 
									
										
										
										
											2020-01-30 16:31:52 -05:00
										 |  |  |               "timedatectl set-time '2018-12-16 13:45'", | 
					
						
							|  |  |  |               "systemctl start restic-backups-remotebackup.service", | 
					
						
							| 
									
										
										
										
											2020-07-05 16:25:57 -04:00
										 |  |  |               "systemctl start restic-backups-rclonebackup.service", | 
					
						
							| 
									
										
										
										
											2020-01-30 16:31:52 -05:00
										 |  |  |               '${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots -c | grep -e "^4 snapshot"', | 
					
						
							| 
									
										
										
										
											2020-07-05 16:25:57 -04:00
										 |  |  |               '${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots -c | grep -e "^4 snapshot"', | 
					
						
							| 
									
										
										
										
											2021-03-19 20:14:43 -04:00
										 |  |  |               "systemctl start restic-backups-remoteprune.service", | 
					
						
							|  |  |  |               '${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots -c | grep -e "^1 snapshot"', | 
					
						
							| 
									
										
										
										
											2020-01-30 16:31:52 -05:00
										 |  |  |           ) | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | ) |