|
1 |
| -# Filtering snapshots to copy |
| 1 | +## Filtering snapshots |
2 | 2 |
|
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: |
5 | 58 |
|
6 | 59 | ```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 |
8 | 61 | ```
|
9 | 62 |
|
10 | 63 | It is also possible to explicitly specify the list of snapshots to copy, in
|
11 | 64 | which case only these instead of all snapshots will be copied:
|
12 | 65 |
|
13 | 66 | ```console
|
14 |
| -rustic -r /srv/rustic-repo copy --repo2 /srv/rustic-repo-copy 410b18a2 4e5d5487 latest |
| 67 | +rustic copy 410b18a2 4e5d5487 latest |
15 | 68 | ```
|
0 commit comments