Prune won't delete snapshots

I am seeing some inconsistent behavior while trying to remove old backups…
I am using this bash script.
#!/bin/bash

restic -r ./important --verbose backup --tag daily --exclude-file=filters -p ./pass --files-from target_important
restic -r ./important -p ./pass forget --tag daily --keep-daily 7 --prune

restic -r ./browsers --verbose backup --tag daily --exclude-file=exclude_browsers -p ./pass --files-from target_browsers
restic -r ./browsers -p ./pass forget --tag daily --keep-daily 7 --prune

In important repo, there are 8 snapshots and using --keep-daily 7 won’t actually remove any snapshots… I am running that bash script using cron, but tested it in terminal too -

[akya@quady backup]$ restic -r ./important/ -p ./pass snapshots 
repository a798782e opened successfully, password is correct
ID        Time                 Host        Tags        Paths
-------------------------------------------------------------------------------------------
b84223c3  2019-09-17 03:17:01  quady       daily       

afd7d71a  2019-09-18 09:29:02  quady       daily       

854733f5  2019-09-19 10:36:03  quady       daily       

fdc220e9  2019-09-20 03:20:02  quady       daily       

4b673566  2019-09-21 20:30:43  quady       daily       

a9d146d3  2019-09-22 03:16:01  quady       daily       

23941d0b  2019-09-23 20:43:33  quady       daily       

dd2fe619  2019-09-24 11:41:55  quady       daily       
-------------------------------------------------------------------------------------------
8 snapshots
[akya@quady backup]$ restic -r ./important/ -p ./pass forget --tag daily --keep-daily 7 --prune
repository a798782e opened successfully, password is correct
Applying Policy: keep the last 7 daily snapshots
keep 6 snapshots:
ID        Time                 Host        Tags        Reasons         Paths
-----------------------------------------------------------------------------------------------------------
854733f5  2019-09-19 10:36:03  quady       daily       daily snapshot  

fdc220e9  2019-09-20 03:20:02  quady       daily       daily snapshot  

4b673566  2019-09-21 20:30:43  quady       daily       daily snapshot  

a9d146d3  2019-09-22 03:16:01  quady       daily       daily snapshot  

23941d0b  2019-09-23 20:43:33  quady       daily       daily snapshot  

dd2fe619  2019-09-24 11:41:55  quady       daily       daily snapshot  
-----------------------------------------------------------------------------------------------------------
6 snapshots

keep 2 snapshots:
ID        Time                 Host        Tags        Reasons         Paths
------------------------------------------------------------------------------------------------
b84223c3  2019-09-17 03:17:01  quady       daily       daily snapshot  

afd7d71a  2019-09-18 09:29:02  quady       daily       daily snapshot  
------------------------------------------------------------------------------------------------
2 snapshots

[akya@quady backup]$ restic -r ./important/ -p ./pass snapshots 
repository a798782e opened successfully, password is correct
ID        Time                 Host        Tags        Paths
-------------------------------------------------------------------------------------------
b84223c3  2019-09-17 03:17:01  quady       daily       

afd7d71a  2019-09-18 09:29:02  quady       daily       

854733f5  2019-09-19 10:36:03  quady       daily       

fdc220e9  2019-09-20 03:20:02  quady       daily       

4b673566  2019-09-21 20:30:43  quady       daily       

a9d146d3  2019-09-22 03:16:01  quady       daily       

23941d0b  2019-09-23 20:43:33  quady       daily       

dd2fe619  2019-09-24 11:41:55  quady       daily       
-------------------------------------------------------------------------------------------
8 snapshots

forget groups snapshots and then applies the policy separately to each group. The default grouping is on hostname and paths. If you’ve changed the input set of paths to back up at any point, then the backups taken after that point in time won’t group with the backups taken prior.

Given that the output lists the snapshots in two groups (one of 6 and one of 2), I suspect this is what’s happening. You can change how forget groups snapshots with the --group-by flag. See restic help forget.

1 Like

Aah yes, I had changed the paths and that’s why the groups of 6 and 2. I removed the paths before posting in here since I thought it was too much output for the forums. But I understand it now. I used the --group-by flag and the prune properly removed the oldest backup. Sorry I should have went through the help section a bit more thoroughly. Thanks a lot for this amazing piece of software. It has already saved me once. :slightly_smiling_face:

1 Like