Confusing behavior of `restic forget`: two snapshots for the same time frame?

Hi all!

I set up restic 0.17.0 on a server a few days ago and it works fine, but I’m confused by the following results of restic forget (I removed the Hosts, Paths and Size columns):

$ restic forget --prune --group-by host --keep-within 48h --keep-daily 14 --keep-weekly 8 --keep-monthly 24 --keep-yearly 4
Applying Policy: keep 14 daily, 8 weekly, 24 monthly, 4 yearly snapshots and all snapshots within 48h of the newest
keep 9 snapshots:
ID        Time                 Host        Tags        Reasons           Paths                   Size
-----------------------------------------------------------------------------------------------------------
46b93809  2024-08-20 18:51:40  myserver                daily snapshot    /etc/environment
                                                       weekly snapshot   /opt/REDACTED
                                                       monthly snapshot  /opt/pgadmin
                                                       yearly snapshot   /root/restic-backup.sh

8081eda8  2024-08-20 22:33:13  myserver                daily snapshot    /etc/environment
                                                                         /opt/REDACTED
                                                                         /opt/pgadmin
                                                                         /root/pgbackup
                                                                         /root/restic-backup.sh

48f81068  2024-08-21 14:27:14  myserver                within 48h        /etc/environment        29.508 MiB
                                                                         /opt/REDACTED
                                                                         /opt/pgadmin
                                                                         /root/pgbackup
                                                                         /root/restic-backup.sh

ad303df3  2024-08-21 16:00:14  myserver                within 48h        /etc/environment        29.508 MiB
                                                                         /opt/REDACTED
                                                                         /opt/pgadmin
                                                                         /root/pgbackup
                                                                         /root/restic-backup.sh

90480b00  2024-08-21 17:50:12  myserver                within 48h        /etc/environment        29.508 MiB
                                                       daily snapshot    /opt/REDACTED
                                                                         /opt/pgadmin
                                                                         /root/pgbackup
                                                                         /root/restic-backup.sh

2ea12ea4  2024-08-22 04:00:13  myserver                within 48h        /etc/environment        29.509 MiB
                                                                         /opt/REDACTED
                                                                         /opt/pgadmin
                                                                         /root/pgbackup
                                                                         /root/restic-backup.sh

e9794f9e  2024-08-22 16:00:13  myserver                within 48h        /etc/environment        29.510 MiB
                                                       daily snapshot    /opt/REDACTED
                                                                         /opt/pgadmin
                                                                         /root/pgbackup
                                                                         /root/restic-backup.sh

a73dfc74  2024-08-23 07:38:13  myserver                within 48h        /etc/environment        29.510 MiB
                                                                         /opt/REDACTED
                                                                         /opt/pgadmin
                                                                         /root/pgbackup
                                                                         /root/restic-backup.sh

90e7c3f2  2024-08-23 07:41:14  myserver                within 48h        /etc/environment        29.510 MiB
                                                       daily snapshot    /opt/REDACTED
                                                       weekly snapshot   /opt/pgadmin
                                                       monthly snapshot  /root/pgbackup
                                                       yearly snapshot   /root/restic-backup.sh
-----------------------------------------------------------------------------------------------------------

My first question was: how can both the first and second snapshots listed (46b93809 and 8081eda8) be considered a daily snapshot? They are from the same day, after all. (In case the time zone is relevant: Europe/Berlin, currently UTC+2.)

Second, why are the first and last snapshots (46b93809 and 90e7c3f2) considered weekly, monthly and yearly snapshots when they are in the same week, month and year, respectively?

Re-checking the documentation, I found a sentence I must have overlooked the first time:

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

Does that indeed explain everything? I just want to make sure I understand restic’s logic here.

Kind regards,
Jens

Please edit your post to include all of the output of the command. It is likely that the fields you removed contain the answer.

Done.

The host is the same, and although the paths did change, --group-by host should make that irrelevant.

Yes, the sentence you found in the documentation explains it. If you neglect the first snapshot in the list, everything is as expected, right? This first one is a pseudo-yearly, -monthly, -weekly and -daily snapshot – it is just the oldest one there is and is kept because there are not enough for each kind.

(Similar questions: 6994 and 7888.)

1 Like

Thank you!

Using the --dry-run option, I was able to verify this. When the numbers given for each --keep-* option is chosen to match the number of existing snapshots of that option, restic indeed no longer keeps the oldest snapshot.


Given that I’m not the first and likely not the last person to be confused by this, what do you guys all think about making this explicit in the output?

I’m thinking of something like adding a * in the Reasons column and displaying an explanation below the table, for example:

$ restic forget --prune --group-by host --keep-within 48h --keep-daily 14 --keep-weekly 8 --keep-monthly 24 --keep-yearly 4
Applying Policy: keep 14 daily, 8 weekly, 24 monthly, 4 yearly snapshots and all snapshots within 48h of the newest
keep 9 snapshots:
ID        Time                 Host        Tags        Reasons           Paths                   Size
-----------------------------------------------------------------------------------------------------------
46b93809  2024-08-20 18:51:40  myserver                daily snapshot*   /etc/environment
                                                       weekly snapshot*  /opt/REDACTED
                                                       monthly snapshot* /opt/pgadmin
                                                       yearly snapshot*  /root/restic-backup.sh

8081eda8  2024-08-20 22:33:13  myserver                daily snapshot    /etc/environment
                                                                         /opt/REDACTED
                                                                         /opt/pgadmin
                                                                         /root/pgbackup
                                                                         /root/restic-backup.sh

   < other snapshots omitted for this illustration >

-----------------------------------------------------------------------------------------------------------
 * As not enough snapshots exist for one or more 'keep' options, the oldest snapshot was kept, as well.

The suggestion in Forget: show reason why oldest snapshot in a group is kept · Issue #4806 · restic/restic · GitHub was to describe it as “additional oldest … snapshot”. Feel free to suggest an alternative naming.