PowerToys icon indicating copy to clipboard operation
PowerToys copied to clipboard

[Hosts] Backup Settings

Open davidegiacometti opened this issue 10 months ago • 21 comments

Summary of the Pull Request

Add backup settings for the Hosts File Editor to allow users to customize the existing hardcoded logic.

PR Checklist

  • [x] Closes: #37666
  • [ ] Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • [x] Tests: Added/updated and all pass
  • [ ] Localization: All end user facing strings can be localized
  • [ ] Dev docs: Added/updated
  • [ ] New binaries: Added on the required places
  • [x] Documentation updated: If checked, please file a pull request on our docs repo and link it here: https://github.com/MicrosoftDocs/windows-dev-docs/pull/5342

Detailed Description of the Pull Request / Additional comments

image image image

Validation Steps Performed

  • Backup on: verified that backup isn't executed
  • Backups off: Verified that only one backup is executed
  • Verified that backup is located in the expected path
  • Auto delete is set to "never": verified that no backups are deleted
  • Auto delete is set to "based on count": verified that backups are deleted according to count value
  • Auto delete is set to "based on age and count": verified that backups are deleted according to days and count values
  • Verified that files without the backup pattern aren't deleted
  • There is also adequate test coverage for these scenarios šŸš€

davidegiacometti avatar Mar 05 '25 22:03 davidegiacometti

I suggest as we have the on/of checkbox for cleanup to set the number boxes to min=1.

htcfreek avatar Mar 06 '25 07:03 htcfreek

I suggest as we have the on/of checkbox for cleanup to set the number boxes to min=1.

The idea is that user can configure retention by:

  • Days only: Days = N - Backups = 0
  • Backups only: Days = 0 - Backups = N
  • Both: Days = N - Backups = N

In case both are set to 0 the warning is displayed and no backups are deleted.

Do you think this makes sense?

davidegiacometti avatar Mar 06 '25 19:03 davidegiacometti

I suggest as we have the on/of checkbox for cleanup to set the number boxes to min=1.

The idea is that user can configure retention by:

  • Days only: Days = N - Backups = 0
  • Backups only: Days = 0 - Backups = N
  • Both: Days = N - Backups = N

In case both are set to 0 the warning is displayed and no backups are deleted.

Do you think this makes sense?

These all feels to complicated. I think keep it simple is the way to go.

And simple for me is:

  • Backups are enabled or not.
  • Automatic cleanup is "disable" or "based on age" or "based on number". (Can be a drop down.)
  • Based on the cleanup type I can configure nothing or the days or the number.

htcfreek avatar Mar 06 '25 19:03 htcfreek

These all feels to complicated. I think keep it simple is the way to go.

And simple for me is:

  • Backups are enabled or not.
  • Automatic cleanup is "disable" or "based on age" or "based on number". (Can be a drop down.)
  • Based on the cleanup type I can configure nothing or the days or the number.

I started with this idea, but https://github.com/microsoft/PowerToys/issues/37666#issuecomment-2689795329 made me change it.

Safer would be to keep at least the most recent backup (no matter how old) and then delete others older than 15 days?

But I am happy to have a feedback on this.

davidegiacometti avatar Mar 06 '25 19:03 davidegiacometti

Safer would be to keep at least the most recent backup (no matter how old) and then delete others older than 15 days?\n\nBut I am happy to have a feedback on this.

Okay. But then lets allow the following logic: Remove backups older x days (x = setting >= 1) and hard coded keep always 1 backup.

The if-else-else solution is to complicated.

We can add a description to cleanup checkbox that at least one backup is always kept regardless of its age.

htcfreek avatar Mar 06 '25 19:03 htcfreek

I need to think about this: the idea around the PR is to remove any hardcoded/hidden logic related to backups. What do you find confusing of the proposed logic? The warning message?

davidegiacometti avatar Mar 06 '25 20:03 davidegiacometti

I need to think about this: the idea around the PR is to remove any hardcoded/hidden logic related to backups. What do you find confusing of the proposed logic? The warning message?

The point that we have multiple ways of doing it which influence each other. And that you can configure it to not clean up even that zhe clean up is enabled.

htcfreek avatar Mar 06 '25 21:03 htcfreek

Animation

@htcfreek any thoughts on this UX?

  • No warning
  • User can set only Days or Copies to 0
  • When Days and Copies are set to 0, "Automatically delete old backups" is disabled and Days and Copies are set to their default

davidegiacometti avatar Mar 08 '25 13:03 davidegiacometti

Animation

@htcfreek any thoughts on this UX?

  • No warning
  • User can set only Days or Copies to 0
  • When Days and Copies are set to 0, "Automatically delete old backups" is disabled and Days and Copies are set to their default

@davidegiacometti Much better.

With zero as date or time all backups will be deleted on the next ????. We should add description to explain that. May on the cleanup check box something like "Clean up is executed on the ....".

htcfreek avatar Mar 08 '25 13:03 htcfreek

The backups cleanup is always executed on editor startup. These options are used to determine for how many days backups are kept or/and how many fixed backups are kept.

davidegiacometti avatar Mar 08 '25 13:03 davidegiacometti

The backups cleanup is always executed on editor startup. These options are used to determine for how many days backups are kept or/and how many fixed backups are kept.

Yes. What I mean is: It makes a difference with 0 days if I start Hosts multiple times per day or not.

And for me keeping 0 days means deleting at the day of creating and not keeping indefinitely. That is confusing.

htcfreek avatar Mar 08 '25 13:03 htcfreek

Yes. What I mean is: It makes a difference with 0 days if I start Hosts multiple times per day or not.

0 days means only the number of backups is considered.

And for me keeping 0 days means deleting at the day of creating and not keeping indefinitely. That is confusing.

image

You mean that this may be confused as Keep for infinite days AND Keep 10 backups... I see...

TBH I am thinking about reconsider the following solution even if user is forced to choose between number of days or number or backups.

  • Backups are enabled or not.
  • Automatic cleanup is "disable" or "based on age" or "based on number". (Can be a drop down.)
  • Based on the cleanup type I can configure nothing or the days or the number.

davidegiacometti avatar Mar 08 '25 15:03 davidegiacometti

Yes. What I mean is: It makes a difference with 0 days if I start Hosts multiple times per day or not.

0 days means only the number of backups is considered.

And for me keeping 0 days means deleting at the day of creating and not keeping indefinitely. That is confusing.

image

You mean that this may be confused as Keep for infinite days AND Keep 10 backups... I see...

No. As keeping 0 backups for 10 days which means no backups kept.

To make the current UI logically we need drop downs instead of number boxes:

  • Keep backups: All, 1, 2, 3, 5, 10, 15, 30, 50, 75, 100
  • Kepp days: Indefinit, 1, 2, 3, 5, 10, 15, 30, 60, 90, 180

TBH I am thinking about reconsider the following solution even if user is forced to choose between number of days or number or backups.

  • Backups are enabled or not.
  • Automatic cleanup is "disable" or "based on age" or "based on number". (Can be a drop down.)
  • Based on the cleanup type I can configure nothing or the days or the number.

Would be the easiest implementation.

htcfreek avatar Mar 08 '25 16:03 htcfreek

I think the drop downs are limiting.. šŸ¤” I’m going to close this PR for now and try to create a new one with a better approach in the future. In any case, it is not a priority but rather an enhancement.

davidegiacometti avatar Mar 08 '25 17:03 davidegiacometti

Hey @htcfreek

Can I have a feedback on these mocks? Every NumberBox has Minimum set to 1, except for Based on age | Number of backups to keep that is optional and has a Minimum of 0.

image 420622303-349f7a33-355b-4665-b5fe-2abdadb7ccfa 420622309-c4571bca-3dd7-40ab-85bd-a9205c3d0948

Let me know if you think this solution is clear. If your answer is positive I am going to reopen this PR and tweak the implementation.

davidegiacometti avatar Mar 08 '25 20:03 davidegiacometti

@davidegiacometti

Two suggestions:

  • Replace Number with Count in the drop down.
  • For the combined type use Based on age and count in the drop down.

Every NumberBox has Minimum set to 1, except for Based on age | Number of backups to keep that is optional and has a Minimum of 0.

Can't follow you. There are only these two number boxes in the screenshots. Are there any screenshots missing?

And I still see see the problem that 0 means nothing. So we should explain the meaning of 0 in the number box description.

htcfreek avatar Mar 08 '25 20:03 htcfreek

Ok for the suggestions.

Please see the update screenshot. TBH I don't understand what's the problem of 0: see the last NumberBox description.

davidegiacometti avatar Mar 08 '25 21:03 davidegiacometti

TBH I don't understand what's the problem of 0: see the last NumberBox description.

Sory. My mistake. Was confused after all the solutions we discussed.

htcfreek avatar Mar 08 '25 21:03 htcfreek

Let me know if you think this solution is clear. If your answer is positive I am going to reopen this PR and tweak the implementation.

Yes. It is clear. Let's implement that solution.

htcfreek avatar Mar 08 '25 21:03 htcfreek

Thanks for the feedback.. And I like this solution! Reopening the PR.

davidegiacometti avatar Mar 09 '25 11:03 davidegiacometti

Addressed the last feedback and updated the screenshot in the first post. I'll take some time to review and test once again before removing the draft from the PR.

davidegiacometti avatar Mar 10 '25 19:03 davidegiacometti

my bad, forgot to click 'Submit' to save my review comments. apology for the delay... :(

jamrobot avatar Apr 04 '25 22:04 jamrobot

Don't worry and thanks for the review. I have pushed the changes.

davidegiacometti avatar Apr 06 '25 09:04 davidegiacometti

/azp run

davidegiacometti avatar Apr 08 '25 18:04 davidegiacometti

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Apr 08 '25 18:04 azure-pipelines[bot]

/azp run

davidegiacometti avatar Apr 17 '25 18:04 davidegiacometti

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Apr 17 '25 18:04 azure-pipelines[bot]

@davidegiacometti we've let this PR hanging for too long - apologies for that! Would you mind looking at the conflicts, so we can get this reviewed?

niels9001 avatar Nov 03 '25 09:11 niels9001

Hi @niels9001 It's been a while, but thanks for the update on this! 😃
I have aligned the branch with latest main and fixed the conflicts.

davidegiacometti avatar Nov 03 '25 19:11 davidegiacometti