Skip to content

Commit

Permalink
nixos/rustic: add basic nixos integration test with prometheus metric…
Browse files Browse the repository at this point in the history
…s check
  • Loading branch information
Ekleog committed Jan 15, 2025
1 parent a62ecf9 commit c0a05cb
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ in {
rsyslogd = handleTest ./rsyslogd.nix {};
rtkit = runTest ./rtkit.nix;
rtorrent = handleTest ./rtorrent.nix {};
rustic = handleTest ./rustic.nix {};
rustls-libssl = handleTest ./rustls-libssl.nix {};
rxe = handleTest ./rxe.nix {};
sabnzbd = handleTest ./sabnzbd.nix {};
Expand Down
102 changes: 102 additions & 0 deletions nixos/tests/rustic.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import ./make-test-python.nix (
{ pkgs, ... }:
{
name = "rustic";
meta.maintainers = with pkgs.lib.maintainers; [
ekleog
nobbz
pmw
];

nodes.machine =
{ pkgs, ... }:
{
services.rustic = {
enable = true;
profiles."rustic" = {
repository = {
repository = "/root/repo";
password = "foobar"; # obviously don't do that
};
forget = {
keep-last = 1;
};
};
backups.fs.files = {
sources = [ "/root/backup" ];
startAt = "minutely";
pipeJsonInto.prometheus.nodeExporterCollectorFolder = "/root/prometheus-text";
};
checks.regularly = {
startAt = "minutely";
};
prune = {
enable = true;
startAt = "minutely";
};
};

# Disable the timers, as nixos testing seems ill-adapted to timers
systemd.timers.rustic-backup-fs.enable = false;
systemd.timers.rustic-check-regularly.enable = false;
systemd.timers.rustic-prune.enable = false;
};

testScript = ''
# Initialize the repository
machine.succeed("mkdir /root/{backup,repo,prometheus-text}")
machine.succeed("touch /root/backup/first-file")
machine.succeed("rustic init")
# Make a first backup
machine.succeed("systemctl start rustic-backup-fs.service")
# Check we made one valid backup
machine.succeed("rustic snapshots") # debug
machine.succeed("rustic list snapshots | wc -l | egrep '^1$'")
machine.succeed("rustic check --read-data")
# Validate the prometheus metrics file was written
machine.succeed("ls /root/prometheus-text | wc -l | egrep '^1$'")
# Restore the first backup
machine.succeed("mkdir /root/restore-1")
machine.succeed("rustic restore latest /root/restore-1")
machine.succeed("ls /root/restore-1/root/backup | grep first-file")
# Add one file and make a new backup
machine.succeed("touch /root/backup/second-file")
machine.succeed("systemctl start rustic-backup-fs.service")
machine.succeed("systemctl start rustic-check-regularly.service")
# Check we have a second valid backup
machine.succeed("rustic snapshots") # debug
machine.succeed("rustic list snapshots | wc -l | egrep '^2$'")
machine.succeed("rustic check --read-data")
# Validate we overwrote the prometheus metrics file, without adding a new one
machine.succeed("ls /root/prometheus-text | wc -l | egrep '^1$'")
# Restore the second backup
machine.succeed("mkdir /root/restore-2")
machine.succeed("rustic restore latest /root/restore-2")
machine.succeed("ls /root/restore-2/root/backup | grep first-file")
machine.succeed("ls /root/restore-2/root/backup | grep second-file")
# Prune the first backup
machine.succeed("systemctl start rustic-prune.service")
machine.succeed("systemctl start rustic-check-regularly.service")
# Check we only have one backup left
machine.succeed("rustic snapshots") # debug
machine.succeed("rustic list snapshots | wc -l | egrep '^1$'")
machine.succeed("rustic check --read-data")
# Restore the second backup again, checking we didn't, just now, delete it
machine.succeed("mkdir /root/restore-3")
machine.succeed("rustic restore latest /root/restore-3")
machine.succeed("ls /root/restore-3/root/backup | grep first-file")
machine.succeed("ls /root/restore-3/root/backup | grep second-file")
'';
}
)
3 changes: 3 additions & 0 deletions pkgs/by-name/ru/rustic/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
SystemConfiguration,
installShellFiles,
nix-update-script,
nixosTests,
}:

rustPlatform.buildRustPackage rec {
Expand Down Expand Up @@ -39,6 +40,8 @@ rustPlatform.buildRustPackage rec {

passthru.updateScript = nix-update-script { };

passthru.tests.nixos = nixosTests.rustic;

meta = {
homepage = "https://github.com/rustic-rs/rustic";
changelog = "https://github.com/rustic-rs/rustic/blob/${src.rev}/CHANGELOG.md";
Expand Down

0 comments on commit c0a05cb

Please sign in to comment.