Keeping yearly snapshots policy when backup began during the year

Restic should keep two yearly snapshots, meaning that I can go back for a longer period of time.
Therefore I have this policy:

restic forget --keep-daily 7 --keep-monthly 4 --keep-yearly 2 --keep-weekly 4 --prune

Backup begins in April 2021. This policy would remove the backup from april, because yearly snapshot is the oldest of the year 2021. If first backup was on or before 31.12.2020 then everything would be fine and it would work as desired. But what to do until then?
Below is an example. All snapshots that are due to remove could be removed except Snapshot 4d7b1636 from 22.4.2021.

It would work perfect if restic would have an option to have to also flag the first snapshot of a year as yearly snapshot, then only the number of yearly snapshots to keep must be increased.

What ideas do you have to do this with the given possibilities of keeping snapshots?

Applying Policy: keep 7 daily, 4 weekly, 4 monthly, 2 yearly snapshots
keep 7 snapshots:
ID        Time                 Host        Tags        Reasons           Paths
------------------------------------------------------------------------------
ac05f518  2021-09-21 15:33:56  systemfour              daily snapshot    /
                                                       monthly snapshot  /boot

d55aae8d  2021-10-20 23:14:59  systemfour              daily snapshot    /
                                                       weekly snapshot   /boot
                                                       monthly snapshot

0b3ff612  2021-12-06 14:18:51  systemfour              daily snapshot    /
                                                       weekly snapshot   /boot

fec94056  2021-12-21 10:57:50  systemfour              daily snapshot    /
                                                                         /boot

2f80bbbd  2021-12-22 18:12:56  systemfour              daily snapshot    /
                                                                         /boot

d8c8de43  2021-12-26 00:00:03  systemfour              daily snapshot    /
                                                       weekly snapshot   /boot
                                                       monthly snapshot
                                                       yearly snapshot

089e4b0e  2022-01-02 00:00:03  systemfour              daily snapshot    /
                                                       weekly snapshot   /boot
                                                       monthly snapshot
                                                       yearly snapshot
------------------------------------------------------------------------------
7 snapshots

remove 6 snapshots:
ID        Time                 Host        Tags        Paths
------------------------------------------------------------
4d7b1636  2021-04-22 00:30:46  systemfour              /
                                                       /boot

feb37297  2021-05-21 17:20:52  systemfour              /
                                                       /boot

59464c6b  2021-05-24 11:53:38  systemfour              /
                                                       /boot

1e9bada5  2021-06-14 09:20:32  systemfour              /
                                                       /boot

511acfa6  2021-06-26 12:06:02  systemfour              /
                                                       /boot

c0bb9ed0  2021-12-22 00:10:16  systemfour              /
                                                       /boot
------------------------------------------------------------

Hi @Restic and thanks for your interesting question!

The problem you are describing applies as you did not reach yet the two yearly backups, but the forget algorithm identifies and then only holds back the last snapshots within a year as yearly backup.
The same problem obviously applies for the monthly and weekly option if you start in the middle of a month/week.

I would suggest you to keep as much monthly/weekly/daily backups such that a complete year/month/week is covered. In your case, I would keep at least 12 monthly backups.

Once you reached your desired number (2 yearly backups in your case) you can adjust the forgetrule.

Feel also free to open an issue at github to request that the oldest snapshot is kept if there are not enough yearly/monthly/weekly/daily backups to keep.

1 Like

Thanks alexweiss using at least 12 monthly backups is a very good idea. There is more data saved than intended but still it is a very good idea and maybe even better.

I’ve opened an issue restic forget: Keep also oldest snapshot when there are not enough backups to keep · Issue #3624 · restic/restic · GitHub and hopefully it will be implemented soon.