NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.39k stars 14.34k forks source link

[restic] Allow backup without prune/check #216457

Open cultpony opened 1 year ago

cultpony commented 1 year ago

Describe the bug

The automatic restic backup service runs a prune after every backup.

For my use case, I'm having multiple machines backup into an Append-Only repository, there is no need for them to prune, the prune runs elsewhere. Many of the machines don't even have the RAM to run prune reliably without going into an OOM state or the machine hangs entirely due to the CPU demand and having run out of CPU quota.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Setup services.restic.backups. to backup to an append-only repo
  2. Prune will run, possibly OOM the machine

Expected behavior

I would love an option that turns off both the check and the prune running on the repository to reduce unneeded traffic from my nix machines.

Notify maintainers

@dotlambda @mbrgm

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.7, NixOS, 23.05 (Stoat), 23.05pre446447.1b1f50645af`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.12.0`
 - channels(root): `"home-manager, nixos"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
gabysbrain commented 1 year ago

If pruneOpts is empty then the prune and check aren't run

cultpony commented 1 year ago

Yes but then forget isn't run at all either, I would like to run forget without the check or prune, as I can prune the repo later without issue but atm it's causing issues with the repo randomly just being deadlocked due to an OOM event.

sedlund commented 1 month ago

It can be useful for each host and job to have its own retention settings.

Here is an idea of how to do it:

```nix services.restic.backups = let pruneOpts = [ "--keep-within 7d" "--keep-daily 7" "--keep-weekly 6" "--keep-monthly 6" ]; repository = "s3:https://blah"; mkForgetScript = name: '' restic-${name} forget --host ${config.networking.hostName} ${lib.concatStringsSep " " pruneOpts} ''; in { backup = { inherit repository; # this will forget after each backup backupCleanupCommand = mkForgetScript "backup"; runCheck = false; # ... }; }; { # prune should only be ran on one host prune = { inherit repository pruneOpts; timerConfig = { onCalendar = "weekly"; persistent = true; randomizedDelaySec = "15m"; }; # ... }; }; ```