Uncertainty with "forget"

Hi, Happy new year all.

I have a question about the forget command, which is likely me failing to understand it properly.

I use the following command to trim a repository.

restic forget --host <hostname> -g host,tag -n -y 2 -w 6 -m 6 -l 3

(I group by host/tag because each backup type is tagged. Path is irellevant for this particular backup schedule)

Applying Policy: keep 3 latest, 6 weekly, 6 monthly, 2 yearly snapshots
keep 14 snapshots:
ID        Time                 Host         Tags        Reasons           Paths
---------------------------------------------------------------------------------
02e6d523  2023-06-30 22:39:11  <hostname>   domain      monthly snapshot  <path>
fc2b3df3  2023-07-31 22:56:07  <hostname>   domain      monthly snapshot  <path>
8eda28d3  2023-08-31 22:09:19  <hostname>   domain      monthly snapshot  <path>
79f7e16f  2023-09-30 22:05:38  <hostname>   domain      monthly snapshot  <path>
07c2ed95  2023-10-31 18:58:50  <hostname>   domain      monthly snapshot  <path>
e891aba4  2023-11-26 22:00:00  <hostname>   domain      weekly snapshot   <path>
0fa5874b  2023-11-30 22:01:33  <hostname>   domain      monthly snapshot  <path>
c3bac093  2023-12-03 22:40:33  <hostname>   domain      weekly snapshot   <path>
96fce5ea  2023-12-10 22:32:00  <hostname>   domain      weekly snapshot   <path>
e93e023c  2023-12-12 22:14:17  <hostname>   domain      weekly snapshot   <path>
7ab0425a  2023-12-31 22:45:57  <hostname>   domain      yearly snapshot   <path>
c9839b9c  2024-01-01 02:45:57  <hostname>   domain      last snapshot     <path>
57bc7a44  2024-01-01 06:12:01  <hostname>   domain      last snapshot     <path>
30f95edc  2024-01-01 10:12:01  <hostname>   domain      last snapshot     <path>
                                                        weekly snapshot   <path>
                                                        monthly snapshot
                                                        yearly snapshot
---------------------------------------------------------------------------------
14 snapshots

As far as I can tell, yesterday (as in 31st) I had a yearly snapshot for 2022, and another for 2023.
Today (as in the 1st), yearly backups are pretty much the last snapshot from yesterday and the first from today.

Does this sound right? I’m fairly sure it is, but it feels wrong. I feel like the yearly snapshot should be more like the 1st of jan 2023, and the 1st of jan 2024.

An I doing this wrong?

Thanks

Restic forget’s keep policy works on a “keep the most recent” basis.

This means that the snapshot from the 1st Jan 2024 is the “yearly” for 2024; it is the most recent snapshot from 2024. This also means that the 31st Dec 2023 is the “yearly” for 2023, as it is the most recent snapshot from 2023. Having two “yearly” snapshots fulfils the -y 2 portion of your forget policy, so the 2022 snapshot was forgotten.

If you run another backup on the 2nd Jan, and then apply your forget policy, this time the 2nd Jan 2024 will show as the “yearly” for 2024.
Assuming you take a backup every day, this process will repeat throughout 2024, until eventually 31st Dec 2024 will show up as the “yearly” for 2024.

This can be confusing when coming from other backup software, where “keep the oldest” is often used; it definitely tripped me up when I first starting using restic.

Anyway, some possible solutions; if you wanted to keep n years of yearly snapshots from the present date, the keep-within-yearly option could be what you’re after.
Or you could do what I do and add +1 to the desired period to keep snapshots within (i.e., if you want 2 years worth of yearly snapshots, use --keep-yearly 3 with your forget policy).

1 Like