Using includes/excludes files

New user here. I’m trying to migrate our backup processes from other tools and scripts. Really enjoying restic (and resticprofile) so far!

But I’m unclear on something.

We currently specify include/exclude paths in external files. That is supported by restic via --files-from includes --exclude-file excludes.

Suppose includes has this:

/srv/app/aaa
/srv/app/bbb

I perform two backups. The output of restic snapshots:

ID       Time                Host Tags Paths         Size
----------------------------------------------------------------
ef9f49a7 2024-09-30 07:17:33 demo      /srv/app/aaa  198.197 KiB
                                       /srv/app/bbb
2d8c6801 2024-09-30 07:18:11 demo      /srv/app/aaa  198.197 KiB
                                       /srv/app/bbb

I add /srv/foo/ccc to the includes file, and perform three backups. Snapshots:

ID       Time                Host Tags Paths         Size
----------------------------------------------------------------
ef9f49a7 2024-09-30 07:17:33 demo      /srv/app/aaa  198.197 KiB
                                       /srv/app/bbb
2d8c6801 2024-09-30 07:18:11 demo      /srv/app/aaa  198.197 KiB
                                       /srv/app/bbb
995b881f 2024-09-30 07:25:17 demo      /srv/app/aaa  248.147 KiB
                                       /srv/app/bbb
                                       /srv/app/ccc
09e9c87a 2024-09-30 07:25:49 demo      /srv/app/aaa  248.147 KiB
                                       /srv/app/bbb
                                       /srv/app/ccc
71f731e3 2024-09-30 07:25:57 demo      /srv/app/aaa  248.147 KiB
                                       /srv/app/bbb
                                       /srv/app/ccc

Now I perform a forget (and prune), keeping only the last 2 snapshots (--keep-last 2).

I expect it to delete snapshots 1, 2 and 3, but it actually deletes snapshot 3 only.

It seems to only forget/prune snapshots that exactly match the current includes/excludes config. Since snapshots 1 and 2 don’t include ccc, it never deletes them.

That’s unexpected and confusing. Am I using restic incorrectly?

Check group by option in docs where forget is explained. By default snapshots are grouped by host and paths. You could group only by host or add tags to have more granular control.

2 Likes

Thank you @kapitainsky!

The docs state:

When forget is run with a policy, restic first loads the list of all snapshots and groups them by their host name and paths. The grouping options can be set with --group-by, e.g. using --group-by paths,tags to instead group snapshots by paths and tags. The policy is then applied to each group of snapshots individually. This is a safety feature to prevent accidental removal of unrelated backup sets. To disable grouping and apply the policy to all snapshots regardless of their host, paths and tags, use --group-by '' (that is, an empty value to --group-by). Note that one would normally set the --group-by option for the backup command to the same value.

So for me the solution was:

restic ... --group-by ''
2 Likes