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

Forget: show reason why oldest snapshot in a group is kept #4806

Open
MrJack91 opened this issue May 17, 2024 · 8 comments
Open

Forget: show reason why oldest snapshot in a group is kept #4806

MrJack91 opened this issue May 17, 2024 · 8 comments
Labels
category: forget category: user interface help: minor complexity less complex issue, good for beginners that want a little challenge yet not too complicated help: wanted

Comments

@MrJack91
Copy link

MrJack91 commented May 17, 2024

Output of restic version

restic 0.16.4 compiled with go1.21.6 on linux/amd64

What backend/service did you use to store the repository?

local

Problem description / Steps to reproduce

I setup a new repo and did manually 3 snapshots.
All the same day, two in the same hour (09:00).

I try to specify forget -keep-hourly 24, which should keep for the latest 24 hour max one snapshot per hour.

The forget --keep-hourly keeps too many backups.
The 09:36:51 and 09:41:06 (same day) both keeps with reason hourly. But only the 09:41:06 should be kept.

$restic forget -r [path_to_repo] --prune  --keep-hourly 24  --dry-run

repository 0fc3d186 opened (version 2, compression level auto)
Applying Policy: keep 24 hourly snapshots
snapshots for (host [xxx-machine], paths [/etc, /home, /root, /usr/local, /var/spool/cron]):
keep 3 snapshots:
ID        Time                 Host         Tags        Reasons          Paths
----------------------------------------------------------------------------------------
0729c5c9  2024-05-17 09:36:51  xxx-machine              hourly snapshot  /etc
                                                                         /home
                                                                         /root
                                                                         /usr/local
                                                                         /var/spool/cron

fdee0afa  2024-05-17 09:41:06  xxx-machine              hourly snapshot  /etc
                                                                         /home
                                                                         /root
                                                                         /usr/local
                                                                         /var/spool/cron

f03c4f42  2024-05-17 11:54:19  xxx-machine              hourly snapshot  /etc
                                                                         /home
                                                                         /root
                                                                         /usr/local
                                                                         /var/spool/cron
----------------------------------------------------------------------------------------
3 snapshots

Expected behavior

The older backup in the hour 09:xx (0729c5c9 at 09:36:5) should be deleted, because in the same hour there is a newer one.

So command output should display:

$restic forget -r [path_to_repo] --prune  --keep-hourly 24  --dry-run

repository 0fc3d186 opened (version 2, compression level auto)
Applying Policy: keep 24 hourly snapshots
snapshots for (host [xxx-machine], paths [/etc, /home, /root, /usr/local, /var/spool/cron]):
keep 2 snapshots:
ID        Time                 Host         Tags        Reasons          Paths
----------------------------------------------------------------------------------------
fdee0afa  2024-05-17 09:41:06  xxx-machine              hourly snapshot  /etc
                                                                         /home
                                                                         /root
                                                                         /usr/local
                                                                         /var/spool/cron

f03c4f42  2024-05-17 11:54:19  xxx-machine              hourly snapshot  /etc
                                                                         /home
                                                                         /root
                                                                         /usr/local
                                                                         /var/spool/cron
----------------------------------------------------------------------------------------
2 snapshots

Actual behavior

The backup 0729c5c9 stays and is not forgotten by restic which is wrong in my opinion.

Do you have any idea what may have caused this?

No.
I found already different problems in the forum and issues. But mostly regarding time zones or confusing between the -keep-within and -keep-* option.

Did restic help you today? Did it make you happy in any way?

Restic is awesome. Thank you very much for all your work.
I used already to often to get a older config file version.

@MrJack91 MrJack91 changed the title Forget: keep Option not working correctly Forget: keep option not working correctly May 17, 2024
@MrJack91
Copy link
Author

Ok. It seems, that this is only not working like excepted for the initial snapshot. This initial one stays what ever happens later.

But for all other snapshots it's working like excepted.

I think it would be helpful to leave this issue to avoid initial confusion for others.

@MichaelEischer
Copy link
Member

MichaelEischer commented May 20, 2024

This is actually intended behavior (although a bit unexpected), see https://restic.readthedocs.io/en/stable/060_forget.html#removing-snapshots-according-to-a-policy :

If there are not enough snapshots to keep one for each duration related --keep-{within-,}* option, the oldest snapshot is kept additionally.

That special case isn't particularly relevant for --keep-hourly. However, for --keep-yearly 2 with a backup that contains only a few months of snapshot it's rather helpful to keep the oldest and the latest snapshot of this year.

@MrJack91
Copy link
Author

Oh sorry. Did not see this.
Thank you very much for your answer and all your work!

Maybe too less confuse, we could add this also as a reason in the restic forget command. Then everyone would understand this.

@MichaelEischer
Copy link
Member

Here you go: #4820

@MrJack91
Copy link
Author

@MichaelEischer: Thank you for your effort. just to be clear. I think it would be helpful to add the info about this into the forget command output (not the help).

So in the column reason where we have currently hourly snapshot there should be the additional reason: oldest-snapshot

$restic forget -r [path_to_repo] --prune  --keep-hourly 24  --dry-run

repository 0fc3d186 opened (version 2, compression level auto)
Applying Policy: keep 24 hourly snapshots
snapshots for (host [xxx-machine], paths [/etc, /home, /root, /usr/local, /var/spool/cron]):
keep 3 snapshots:
ID        Time                 Host         Tags        Reasons          Paths
----------------------------------------------------------------------------------------
0729c5c9  2024-05-17 09:36:51  xxx-machine              hourly snapshot  /etc
                                                                         /home
                                                                         /root
                                                                         /usr/local
                                                                         /var/spool/cron

fdee0afa  2024-05-17 09:41:06  xxx-machine              hourly snapshot  /etc
                                                                         /home
                                                                         /root
                                                                         /usr/local
                                                                         /var/spool/cron

That is the reason i was confused. Because i just checked this column. I guess others could be confused easily too, if this info is there missing. For me it's kind of uncomplete. If a reason is displayed, then all reason should be displayed.

@MichaelEischer
Copy link
Member

Any suggestion for a compact reason that would be understandable? Would oldest hourly snapshot work maybe?

@MichaelEischer MichaelEischer changed the title Forget: keep option not working correctly Forget: show reason why oldest snapshot in a group is kept May 30, 2024
@MrJack91
Copy link
Author

To keep the terms like in the doc maybe with the term additional. e.g. additional oldest hourly snapshot.

It will just be one for each keep criteria, so at least I would not mind about a line-breaked reason.

@MrJack91
Copy link
Author

I'm wondering if the snapshot keyword is necessary in general. forget lists a list of snapshots by definition.

@MichaelEischer MichaelEischer added help: wanted category: user interface help: minor complexity less complex issue, good for beginners that want a little challenge yet not too complicated category: forget labels May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: forget category: user interface help: minor complexity less complex issue, good for beginners that want a little challenge yet not too complicated help: wanted
Projects
None yet
Development

No branches or pull requests

2 participants