Skip to content

Commit 1ea0245

Browse files
simonsanaawsome
andauthored
docs: add explanation for filters (#85)
Fixes #84 --------- Signed-off-by: simonsan <[email protected]> Co-authored-by: Alexander Weiss <[email protected]> Co-authored-by: aawsome <[email protected]>
1 parent de35c59 commit 1ea0245

File tree

2 files changed

+59
-6
lines changed

2 files changed

+59
-6
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
- [Working with repositories](./commands/misc/intro.md)
3030
- [Listing Snapshots](./commands/misc/listing.md)
3131
- [Copying Snapshots between Repositories](./commands/misc/copy.md)
32-
- [Filtering Snapshots to Copy](./commands/misc/filter.md)
32+
- [Filtering Snapshots](./commands/misc/filter.md)
3333
- [Ensuring deduplication for copied Snapshots](./commands/misc/deduplication.md)
3434
- [Checking Integrity and Consistency](./commands/misc/check.md)
3535
- [Managing Repository Keys](./commands/misc/key.md)

src/commands/misc/filter.md

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,68 @@
1-
# Filtering snapshots to copy
1+
## Filtering snapshots
22

3-
The list of snapshots to copy can be filtered by host, path in the backup and /
4-
or a comma-separated tag list:
3+
rustic allows to filter snapshots by certain criteria. This can be useful when
4+
listing snapshots, copying snapshots between repositories.
5+
6+
Filters can by given in the config profile
7+
8+
```toml
9+
filter-host = ["host2"] # Default: []
10+
filter-label = ["label1"] # Default: []
11+
filter-tags = ["tag1,tag2"] # Default: []
12+
filter-paths = ["path1"] # Default: no paths filter
13+
filter-fn = '|sn| {sn.host == "host1" || sn.description.contains("test")}' # Default: no filter function
14+
```
15+
16+
or alternatively as CLI options `--filter-host`, `--filter-label`,
17+
`--filter-tags`, `--filter-paths` and `--filter-fn`.
18+
19+
The `filter-host` option allows to filter snapshots by the host name. The
20+
`filter-label` option allows to filter snapshots by the label. The `filter-tags`
21+
option allows to filter snapshots by tags. The `filter-paths` option allows to
22+
filter snapshots by the paths in the backup. The `filter-fn` option allows to
23+
filter snapshots by a custom filter function. The filter function is a string
24+
that is parsed as a Rust closure. The closure takes a `Snapshot` struct as
25+
argument and returns a boolean value.
26+
27+
Multiple filter arguments are connected with an `or` condition, i.e. snapshots
28+
are not filtered out if they match anything of what is the given in the array.
29+
For instance, this shows snapshots having either a tag `tag1` or a tag `tag2`:
30+
31+
```toml
32+
filter-tags = ["tag1", "tag2"]
33+
```
34+
35+
Moreover the different `filter-*` options are combined using an `and`
36+
condition - if a snapshot does not satisfy any of the filters, they are sorted
37+
out. For example, to list snapshots that are tagged with `tag1` and `tag2` and
38+
are located in the path `/srv`, use the following configuration:
39+
40+
```toml
41+
filter-tags = ["tag1,tag2"]
42+
filter-paths = ["/srv"]
43+
```
44+
45+
**Note**: For paths and tags it is already possible to give multiple values -
46+
and then they are `and`ed: `filter-tags=["a,b"]` matches snapshots which have
47+
both "a" and "b" as tags, whereas `filter-tags=["a","b"]` matches snapshots
48+
which have either "a" or "b" as tag.
49+
50+
What is (currently) not possible is to filter exactly for a tag list or path
51+
list: A snapshot with tags "a,b,c" is currently shown when you specify
52+
`filter-tags=["a,b"]`.
53+
54+
## Filtering snapshots to copy
55+
56+
The list of snapshots to copy can be filtered by using the above described
57+
`filter-*` options:
558

659
```console
7-
rustic -r /srv/rustic-repo copy --repo2 /srv/rustic-repo-copy --host luigi --path /srv --tag foo,bar
60+
rustic copy --filter-host luigi --filter-tags foo,bar
861
```
962

1063
It is also possible to explicitly specify the list of snapshots to copy, in
1164
which case only these instead of all snapshots will be copied:
1265

1366
```console
14-
rustic -r /srv/rustic-repo copy --repo2 /srv/rustic-repo-copy 410b18a2 4e5d5487 latest
67+
rustic copy 410b18a2 4e5d5487 latest
1568
```

0 commit comments

Comments
 (0)