Setting --strip-components all leads to no files being extracted #851

Closed
opened 2024-04-17 22:26:36 +00:00 by christian-heusel · 3 comments

What I'm trying to do and why

I had found a bug which wiped the database of my headscale service so I wanted to restore the database from backup. The database is sqlite and just backup'ed as a regular file.

Steps to reproduce

  1. Extract the file from backup:
     borgmatic extract --archive latest --strip-components all --path "/opt/docker/headscale/data/db.sqlite"
    
  2. Try to find the extracted file (no results):
    find / -type f -name "db.sqlite"
    

Actual behavior

No file is extracted.

Expected behavior

The file is extracted from backup like it is without setting --strip-component all:

borgmatic extract --archive latest --path "/opt/docker/headscale/data/db.sqlite"

Which after you find the extracted file in$PWD/opt/docker/headscale/data/db.sqlite
I would expect the file to be extracted to $PWD/db.sqlite with the command from the repro steps.

Other notes / implementation ideas

I also have an Arch Linux install with version 1.8.10 and the issue also is present.

borgmatic version

1.8.9

borgmatic installation method

Debian package

Borg version

1.2.7

Python version

3.11.8

Database version (if applicable)

No response

Operating system and version

Debian GNU/Linux trixie/sid

### What I'm trying to do and why I had found [a bug](https://github.com/juanfont/headscale/pull/1878) which wiped the database of my headscale service so I wanted to restore the database from backup. The database is sqlite and just backup'ed as a regular file. ### Steps to reproduce 1. Extract the file from backup: ``` borgmatic extract --archive latest --strip-components all --path "/opt/docker/headscale/data/db.sqlite" ``` 2. Try to find the extracted file (no results): ``` find / -type f -name "db.sqlite" ``` ### Actual behavior No file is extracted. ### Expected behavior The file is extracted from backup like it is without setting `--strip-component all`: ``` borgmatic extract --archive latest --path "/opt/docker/headscale/data/db.sqlite" ``` Which after you find the extracted file in`$PWD/opt/docker/headscale/data/db.sqlite` I would expect the file to be extracted to `$PWD/db.sqlite` with the command from the repro steps. ### Other notes / implementation ideas I also have an Arch Linux install with version 1.8.10 and the issue also is present. ### borgmatic version 1.8.9 ### borgmatic installation method Debian package ### Borg version 1.2.7 ### Python version 3.11.8 ### Database version (if applicable) _No response_ ### Operating system and version Debian GNU/Linux trixie/sid
Owner

Good catch.. What's apparently going on is that the --path value in your example has a leading slash, which causes the number of path components to strip to be miscalculated (off-by-one error), which causes Borg to ignore the path since the provided number of components to strip exceed the number of components in the path!

Borg stores file paths within its archives without a leading slash, but apparently allows leading slashes on paths given to extract. So borgmatic with --strip-components all should IMO be made to work that way as well. I'll make that fix as part of this ticket, but in the meantime you can just drop the leading slash and your example should work fine with the version of borgmatic you're using.

Thanks for bringing this to my attention and slogging through the registration process.

Good catch.. What's apparently going on is that the `--path` value in your example has a leading slash, which causes the number of path components to strip to be miscalculated (off-by-one error), which causes Borg to ignore the path since the provided number of components to strip exceed the number of components in the path! Borg stores file paths within its archives without a leading slash, but apparently allows leading slashes on paths given to `extract`. So borgmatic with `--strip-components all` should IMO be made to work that way as well. I'll make that fix as part of this ticket, but in the meantime you can just drop the leading slash and your example should work fine with the version of borgmatic you're using. Thanks for bringing this to my attention and slogging through the registration process.
witten added the
bug
label 2024-04-17 23:38:52 +00:00
Owner

Fixed in main! It'll be part of the next release. Thanks again.

Fixed in main! It'll be part of the next release. Thanks again.
Owner

Released in borgmatic 1.8.11!

Released in borgmatic 1.8.11!
Sign in to join this conversation.
No Milestone
No Assignees
2 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#851
No description provided.