Removing snapshots with policy

Hi,

I want to keep the last 7 daily backups all the time. And weekly 4 and monthly 7 backups.

This is my config:

–keep-daily 7
–keep-weekly 4
–keep-monthly 7

I will run my backup script every day once for daily backups with forget and prune option. So, Will I have 18 backup files every month?

I am a little bit confused about forget and prune settings.

At the end of February you will have one, perhaps 2 files covering January, a monthly and maybe one weekly, depending on when in February you look at January.

At the end of January though you will not have any monthly, but 7 dailies and 3 or 4 weekly.

1 Like

Nice looking avatar! Simply add the --dry-run option to your forget command and you’ll see which snapshots restic would keep and not (see restic help forget for more information).

1 Like

Hi,

Thanks for explantion. I created a table. Can you look at it?

48week 04.12.2021		1st Daily Backup
48week 05.12.2021		2nd Daily Backup

49week 06.12.2021		3rd Daily Backup
49week 07.12.2021		4th Daily Backup 
49week 08.12.2021		5th Daily Backup
49week 09.12.2021		6th Daily Backup
49week 10.12.2021		7th Daily Backup
49week 11.12.2021		8th Daily Backup
49week 12.12.2021		9th Daily Backup

50week 13.12.2021		10th Daily Backup
50week 14.12.2021		11th Daily Backup

–keep-daily 3
–keep-weekly 4
–keep-monthly 6

on 4th Daily Backup, will restic delete 1st Daily Backup or keep it because it is weekly?

on 10th Daily Backup, will restic keep 3rd Daily Backup and 2nd Daily Backup because they are weekly?

Thank you. I just started backuping my server so don’t have much backup to test --dry-run option :slight_smile:

It always keeps the youngest snapshot of each period.

1 Like

restic backup --time is a great way to create fictional snapshots to test forget settings. I just created 30 snapshots to test your settings.

user@host:~$ restic snapshots
repository bc06e9d3 opened successfully, password is correct
ID        Time                 Host                 Tags     Paths
------------------------------------------------------------------
ea9c5e5f  2021-11-01 20:00:00  host.exmaple.com              /tmp
3eeb33eb  2021-11-02 20:00:00  host.exmaple.com              /tmp
e92be6e1  2021-11-03 20:00:00  host.exmaple.com              /tmp
d8ea5c51  2021-11-04 20:00:00  host.exmaple.com              /tmp
d3a3d064  2021-11-05 20:00:00  host.exmaple.com              /tmp
c5794721  2021-11-06 20:00:00  host.exmaple.com              /tmp
ebcb1a5c  2021-11-07 20:00:00  host.exmaple.com              /tmp
f885b8af  2021-11-08 20:00:00  host.exmaple.com              /tmp
64bcdda6  2021-11-09 20:00:00  host.exmaple.com              /tmp
74221d7d  2021-11-10 20:00:00  host.exmaple.com              /tmp
211c98da  2021-11-11 20:00:00  host.exmaple.com              /tmp
b08661a4  2021-11-12 20:00:00  host.exmaple.com              /tmp
29ab8d64  2021-11-13 20:00:00  host.exmaple.com              /tmp
7c2e0906  2021-11-14 20:00:00  host.exmaple.com              /tmp
9cb15c54  2021-11-15 20:00:00  host.exmaple.com              /tmp
73f3dc52  2021-11-16 20:00:00  host.exmaple.com              /tmp
7087e831  2021-11-17 20:00:00  host.exmaple.com              /tmp
917b5e49  2021-11-18 20:00:00  host.exmaple.com              /tmp
51102550  2021-11-19 20:00:00  host.exmaple.com              /tmp
0f8414f3  2021-11-20 20:00:00  host.exmaple.com              /tmp
dffede33  2021-11-21 20:00:00  host.exmaple.com              /tmp
76550419  2021-11-22 20:00:00  host.exmaple.com              /tmp
00b05430  2021-11-23 20:00:00  host.exmaple.com              /tmp
0820e9d4  2021-11-24 20:00:00  host.exmaple.com              /tmp
0f8267d3  2021-11-25 20:00:00  host.exmaple.com              /tmp
bfdf114b  2021-11-26 20:00:00  host.exmaple.com              /tmp
d0114e7e  2021-11-27 20:00:00  host.exmaple.com              /tmp
fd84115f  2021-11-28 20:00:00  host.exmaple.com              /tmp
45893df0  2021-11-29 20:00:00  host.exmaple.com              /tmp
a03d4786  2021-11-30 20:00:00  host.exmaple.com              /tmp
------------------------------------------------------------------
30 snapshots
restic forget --dry-run --keep-daily 7 --keep-weekly 4 --keep-monthly 7
repository bc06e9d3 opened successfully, password is correct
Applying Policy: keep 7 daily, 4 weekly, 7 monthly snapshots
keep 9 snapshots:
ID        Time                 Host                 Tags     Reasons           Paths
------------------------------------------------------------------------------------
7c2e0906  2021-11-14 20:00:00  host.exmaple.com              weekly snapshot   /tmp
dffede33  2021-11-21 20:00:00  host.exmaple.com              weekly snapshot   /tmp
0820e9d4  2021-11-24 20:00:00  host.exmaple.com              daily snapshot    /tmp
0f8267d3  2021-11-25 20:00:00  host.exmaple.com              daily snapshot    /tmp
bfdf114b  2021-11-26 20:00:00  host.exmaple.com              daily snapshot    /tmp
d0114e7e  2021-11-27 20:00:00  host.exmaple.com              daily snapshot    /tmp
fd84115f  2021-11-28 20:00:00  host.exmaple.com              daily snapshot    /tmp
                                                             weekly snapshot
45893df0  2021-11-29 20:00:00  host.exmaple.com              daily snapshot    /tmp
a03d4786  2021-11-30 20:00:00  host.exmaple.com              daily snapshot    /tmp
                                                             weekly snapshot
                                                             monthly snapshot
------------------------------------------------------------------------------------
9 snapshots
1 Like

Thank you for your time. This helped me a lot.

I understand clearly.