Forget policy if exist

Apologies for another post on forget policies. I’ve searched the way to delete all snapshots, that older than defined date. As I see from documentation, all --keep-XXX option save most recent snapshots (each defined date period for --keep-XXX or within the specified duration of the latest snapshot for --keep-within).
I have mono repository (I known t’s not best choice, but it happened for history reason), that have some group of snapshots, which is now not backuped. For example:

restic -r /mnt/repo forget --keep-daily 30 --keep-weekly 12 --keep-yearly 5 --prune --dry-run
Applying Policy: keep 30 daily, 12 weekly, 5 yearly snapshots
keep 39 snapshots:
ID Time Host Tags Reasons Paths


dacde85c 2021-06-02 04:11:19 host mysql yearly snapshot /spamassassin.sql

remove 330 snapshots:
ID Time Host Tags Paths


7e0fb0ad 2021-06-03 04:11:20 host mysql /spamassassin.sql

keep 38 snapshots:
ID Time Host Tags Reasons Paths


f4936dc7 2023-11-14 04:26:08 host mysql yearly snapshot /baikal.sql

remove 39 snapshots:
ID Time Host Tags Paths


5a065ec8 2023-11-15 04:26:18 host mysql /baikal.sql

Is there a way to apple some if-exist logic for --keep options, that save snapshots, which correspond to --keep rules, and remove all snapshots, that are older than defined date?

If you use the --keep-* variants, older snapshots are kept if recent time intervals are empty. But if you use the --keep-within-* arguments, only the provided time span is kept. Is that what you want?

--keep-within-monthly 1y keeps snapshots only for the last year even if some months have no snapshot at all.

Documentation show us that:

--keep-within-monthly duration keep all monthly snapshots made within the specified duration of the latest snapshot.

And how it works:

restic -r /mnt/repo forget --keep-within-monthly 1y --prune --dry-run
Applying Policy: keep monthly snapshots within 1y
keep 13 snapshots:
ID Time Host Tags Reasons Paths
-------------------------------------------------------------------------------------------
53f2a095 2021-06-30 04:07:57 host mysql monthly within 1y /spamassassin.sql

remove 356 snapshots:
ID Time Host Tags Paths
------------------------------------------------------------------------
dacde85c 2021-06-02 04:11:19 host mysql /spamassassin.sql

As we see, --keep-within-XXX duration keep snapshots not from current date, but from last snapshot date.