Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/duplicity: enable to prevent backup from growing infinitely #120622

Merged
merged 3 commits into from May 20, 2021

Conversation

symphorien
Copy link
Member

Motivation for this change

In the current state, the module stores backup indefinitely, without a way to prune old backups. This adds new options to curb space usage.

First commit formats the file, second commit contains the logic.

Tested backported to 20.09.

cc @OlivierMarty who wrote the module, cc @peti as maintainer of duplicity

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Current module add backups forever, with no way to prune old ones.

Add an option to remove backups after n full backups or after some
amount of time.

Also run duplicity cleanup to clean unused files in case some previous
backup was improperly interrupted.
in
''
set -x
${dup} cleanup ${target} --force ${extra}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will all extra parameters that can be passed to 'duplicity incr' fit 'duplicity cleanup', remove-older-than, or remove-all-but-n-full?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. If you look at the man page you will see that all options are accepted by all verbs. For example, during testing I am using extraFlags = [ "--full-if-older-than" "7D" ];. This option does not make sense for cleanup, but it still works (it is ignored).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, instead of maxAge and maxFull, what do you think of an option to set the list of actions, the default being ["incr"].

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verbs don't take the same positional arguments: cleanup only takes the target, and incr takes both a source and a target, so there seems to be no way to provide such a unified interface.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. We could add the source only for verbs that need it, but on the other hand the only verbs that make sense in a timer are:

  • full
  • incr
  • remove-older-than
  • remove-all-but-n-full
  • remove-all-inc-of-but-n-full

so if you add an option for remove-all-inc-of-but-n-full we're covered.
(full is incr --full-if-older-than 0, probably.)

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather add options maxIncAge for remove-all-inc-but-n-full and mode = "full" | "incremental" to choose between incremental and full backups (and maybe an option to set --full-if-older-than).

This way you specify the end result you want instead of the list of actions to take. Also it's kind of self documenting by reading the option list.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just did that, please have a look.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks nice!

script =
let
target = escapeShellArg cfg.targetUrl;
extra = escapeShellArgs ([ "--archive-dir" stateDirectory ] ++ cfg.extraFlags);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename 'extra' into 'flags'?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we enter bikeshedding territory here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Feel free to ignore, I don't decide.
But it's confusing between extra an extraFlags. It's not extra, it's all flags. Or options.

@OlivierMarty
Copy link

The request looks fine. I haven't tested it.

@symphorien
Copy link
Member Author

I haven't tested it.

Do you intend to ? I have been using it for a week and it work, so I'm inclined to merge, but if you want to test I can wait :)

If <literal>"never"</literal> (the default) always do incremental
backups (the first backup will be a full backup, of course). If
<literal>"always"</literal> always do full backups (the first backup
will be a full backup, of course). Otherwise, this must be a string

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"the first backup will be a full backup, of course" this doesn't really make sense for the "always" option.

nixos/modules/services/backup/duplicity.nix Outdated Show resolved Hide resolved
nixos/modules/services/backup/duplicity.nix Outdated Show resolved Hide resolved
in
''
set -x
${dup} cleanup ${target} --force ${extra}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks nice!

@OlivierMarty
Copy link

Do you intend to ? I have been using it for a week and it work, so I'm inclined to merge, but if you want to test I can wait :)

Sorry, I don't have time right now.

@symphorien
Copy link
Member Author

Thanks for you review! I think I addressed it, I'll merge soon unless someone speaks up.

@symphorien symphorien merged commit 0d5fa1c into NixOS:master May 20, 2021
SuperSandro2000 pushed a commit that referenced this pull request Jun 27, 2021
In #120622 cleanup options were
added, but `remove-all-inc-of-but-n-full` was misspelled and as such
was not functioning.
github-actions bot pushed a commit that referenced this pull request Jun 27, 2021
In #120622 cleanup options were
added, but `remove-all-inc-of-but-n-full` was misspelled and as such
was not functioning.

(cherry picked from commit 0a977cf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants