Forget snapshots when out of space

Hey! I’m thinking of picking up restic in order to back up my laptop to my new QNAP NAS, but one feature I’d like seems to be missing. I know it’s possible to set a “policy” so that restic will automatically forget snapshots past a certain expiration time, but instead I want restic to forget the oldest snapshots only when it needs more disk space to take new ones. Is there a way to achieve this functionality? Thanks in advance!

restic itself does not have such feature but have all ingredients required to “cook” simple script to achieve it.

You can run restic stats which tells you how much space your repo is using (Total Size), e.g.:

$ restic stats --mode raw-data
[0:03] 100.00%  23 / 23 index files loaded
scanning...
Stats in raw-data mode:
     Snapshots processed:  17
        Total Blob Count:  375228
 Total Uncompressed Size:  57.606 GiB
              Total Size:  24.319 GiB
    Compression Progress:  100.00%
       Compression Ratio:  2.37x
Compression Space Saving:  57.78%

followed by restic forget and restic prune to free space. You can repeat above steps until you reach required result. You will also need restic snapshots to get oldest snapshots IDs.

I would probably replace restic stats (as it can be quite slow) with some other means, e.g. on local NAS check used space using df or du over ssh.