Find a file by name across archives #541

Closed
opened 2022-06-03 20:37:28 +00:00 by witten · 2 comments
Owner

What I'm trying to do and why

A common use case with borgmatic is as follows: The user accidentally deletes or overwrites a file and wants to extract the original from backup so they can continue working with it. This is feasible with Borg and borgmatic, but it's kind of a pain today. The process might go something like this:

  1. Crap, it looks like foo.txt got deleted at some point! I need to restore it from backup.
  2. Okay, I need to figure out what archive it's in. borgmatic list --archive latest.
  3. Huh, it's not actually in that archive. How long has it been deleted? Let's get a list of all archives borgmatic list.
  4. Now I need to go through these archives one-by-one looking for the file... borgmatic list --archive 1234, borgmatic list --archive 1235, etc etc.
  5. I've finally found the file. Now I can finally extract it! borgmatic extract ....

As you can see, this process is kind of tedious—and not what you want to be doing when you're frantically trying to get your file back. Furthermore, if you're trying to use Borg patterns to try to find your file with --path or --pattern, that can further complicate the process if you're not super familiar with the pattern syntax.

So what if that process was a little more streamlined? Something like this:

  1. Crap, it looks like foo.txt got deleted at some point! I need to restore it from backup. borgmatic list --find foo.txt
  2. Aha! I can see at a glance every archive it's found in. Now I can easily borgmatic extract ...

And since this is borgmatic list, you can combine --find with parameters like --last 5 or --archive latest or --glob-archives ... to limit the search to the archives you're interested in searching.

Other notes / implementation ideas

Proposed output:

# borgmatic -c test.yaml list --find test.yaml
test.borg: Listing archives
flux-2022-05-29T15:27:04.333739      Sun, 2022-05-29 15:27:04 [2012...19d4]
-rw------- root   root      25833 Sat, 2022-05-28 19:15:15 root/tmp/test.yaml
flux-2022-05-29T15:27:09.202111      Sun, 2022-05-29 15:27:09 [c193...7e74]
-rw------- root   root      25833 Sat, 2022-05-28 19:15:15 root/tmp/test.yaml
flux-2022-05-30T19:47:15.848721      Mon, 2022-05-30 19:47:15 [5ddc...9266]
flux-2022-05-31T10:09:34.550785      Tue, 2022-05-31 10:09:34 [4df4...a40e]
flux-2022-06-02T19:31:09.768100      Thu, 2022-06-02 19:31:09 [ed60...a261]

Proposed implementation: When borgmatic list --find is used, ask Borg for a list of all matching archives via borg list. Parse that list and run borg list again with each archive, passing in the --find path to each invocation.

Inspired by: https://gitlab.gnome.org/World/pika-backup/-/issues/232 and restic-find.

#### What I'm trying to do and why A common use case with borgmatic is as follows: The user accidentally deletes or overwrites a file and wants to extract the original from backup so they can continue working with it. This is feasible with Borg and borgmatic, but it's kind of a pain today. The process might go something like this: 1. Crap, it looks like foo.txt got deleted at some point! I need to restore it from backup. 2. Okay, I need to figure out what archive it's in. `borgmatic list --archive latest`. 3. Huh, it's not actually *in* that archive. How long has it been deleted? Let's get a list of all archives `borgmatic list`. 4. Now I need to go through these archives one-by-one looking for the file... `borgmatic list --archive 1234`, `borgmatic list --archive 1235`, etc etc. 5. I've finally found the file. Now I can finally extract it! `borgmatic extract ...`. As you can see, this process is kind of tedious—and not what you want to be doing when you're frantically trying to get your file back. Furthermore, if you're trying to use Borg patterns to try to find your file with `--path` or `--pattern`, that can further complicate the process if you're not super familiar with the pattern syntax. So what if that process was a little more streamlined? Something like this: 1. Crap, it looks like foo.txt got deleted at some point! I need to restore it from backup. `borgmatic list --find foo.txt` 2. Aha! I can see at a glance every archive it's found in. Now I can easily `borgmatic extract ...` And since this is `borgmatic list`, you can combine `--find` with parameters like `--last 5` or `--archive latest` or `--glob-archives ...` to limit the search to the archives you're interested in searching. #### Other notes / implementation ideas **Proposed output:** ```bash # borgmatic -c test.yaml list --find test.yaml test.borg: Listing archives flux-2022-05-29T15:27:04.333739 Sun, 2022-05-29 15:27:04 [2012...19d4] -rw------- root root 25833 Sat, 2022-05-28 19:15:15 root/tmp/test.yaml flux-2022-05-29T15:27:09.202111 Sun, 2022-05-29 15:27:09 [c193...7e74] -rw------- root root 25833 Sat, 2022-05-28 19:15:15 root/tmp/test.yaml flux-2022-05-30T19:47:15.848721 Mon, 2022-05-30 19:47:15 [5ddc...9266] flux-2022-05-31T10:09:34.550785 Tue, 2022-05-31 10:09:34 [4df4...a40e] flux-2022-06-02T19:31:09.768100 Thu, 2022-06-02 19:31:09 [ed60...a261] ``` **Proposed implementation:** When `borgmatic list --find` is used, ask Borg for a list of all matching archives via `borg list`. Parse that list and run `borg list` again with each archive, passing in the `--find` path to each invocation. Inspired by: https://gitlab.gnome.org/World/pika-backup/-/issues/232 and [`restic-find`](https://manpages.ubuntu.com/manpages/kinetic/man1/restic-find.1.html).
witten added the
design finalized
label 2022-06-03 20:42:14 +00:00
witten referenced this issue from a commit 2022-06-03 22:20:35 +00:00
Author
Owner

Implemented in master!

Implemented in master!
Author
Owner

Released in borgmatic 1.6.3!

Released in borgmatic 1.6.3!
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: borgmatic-collective/borgmatic#541
No description provided.