Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract without full path #1102

Closed
Ovski4 opened this issue May 30, 2016 · 12 comments
Closed

Extract without full path #1102

Ovski4 opened this issue May 30, 2016 · 12 comments

Comments

@Ovski4
Copy link

Ovski4 commented May 30, 2016

Hi,

I would like to know if there is a way to extract an archive without getting the full path. I didn't find this answer in the "borg extract options".

If I am in /home/user, and want to extract the directory /home/toto/important_files from my backup, I will get the following path: /home/user/home/toto/important_files.

I find this dangerous, because a user might want to delete the home directory recursively : rm -rf ~/home/
If by mistake, It runs rm -rf /home, it's bad. It's even worse for other directories etc/, and so on.

Thank you!

@ThomasWaldmann
Copy link
Member

from borg extract help

  --strip-components NUMBER
                        Remove the specified number of leading path elements.
                        Pathnames with fewer elements will be silently
                        skipped.

@ThomasWaldmann
Copy link
Member

In general: causing a desaster by badly mistyping rm or other commands is not in scope of this issue tracker. The general rule here is to better type such stuff slowly and read / think again for a few seconds before hitting enter. In case you nevertheless cause a desaster, that is why you have (full) backups.

@Ovski4
Copy link
Author

Ovski4 commented May 30, 2016

Thank you for your answer, I read too quickly and didn't get the purpose of this option. I agree with what you said anyway, I always try to be as careful as possible.

@Ovski4 Ovski4 closed this as completed May 30, 2016
@jcrben
Copy link
Contributor

jcrben commented Nov 1, 2016

The commands and options here are rather unfriendly to the user...

@ThomasWaldmann
Copy link
Member

@jcrben so, what is your suggestion to improve?

@jcrben
Copy link
Contributor

jcrben commented Nov 1, 2016

Sorry to be critical without more details!

Why would an option for removing leading path elements be called --strip-components? Naming is hard, it's easier to criticize than create, but keep in mind that even if the users are mostly programmers we are still humans...

I think also this sort of problem is better solved by specifying the path directly rather than trying to strip out elements with a number. It's like the difference between an array and a hash map: see https://www.reddit.com/r/programming/comments/lirke/simple_made_easy_by_rich_hickey_video/

@ThomasWaldmann
Copy link
Member

So, what you suggest is --strip-path=/path/prefix/to/strip ?

@jcrben
Copy link
Contributor

jcrben commented Nov 4, 2016

Maybe, but I guess I was thinking I'd just specify the full intended pathname explicitly as an override. I haven't run into this use case yet.

I guess I'd also rather just use code to do something like this... I'm mostly using borg-backup in an automated fashion with scripts so I would probably just split the path and slice it as necessary if needed.

@ThomasWaldmann
Copy link
Member

@jcrben not sure i understand. assume you have these pathes in the archive:

mnt/server/home/username/document.txt
mnt/server/etc/passwd

So, one likely will want borg extract --strip-path=mnt/server/ archive::repo (as an easier replacement for --strip-components=2).

So, what would you do?

@Tuxie
Copy link

Tuxie commented Nov 12, 2016

IMHO, it would be most intuitive to be able to append the extraction root path to the repo definition, and use ending slashes like rsync:

borg extract archive::repo/mnt/server/ home/username/document.txt etc/passwd

Extraction would work like this:
borg backup archive::home-2016-11-12 /home

cd ~/code/
borg extract archive::home-2016-11-12/home/tuxie/code/ my_project

or

mkdir ~/code/my_project_restored
cd ~/code/my_project_restored
borg extract archive::home-2016-11-12/home/tuxie/code/ my_project/

@ThomasWaldmann
Copy link
Member

I don't think we want to make the repo::archive parsing even more complex than it already is (in contrary: there is a ticket to make it simpler by splitting it up).

@jcrben
Copy link
Contributor

jcrben commented Nov 27, 2016

I think what I want is basically just a destination path for extract: jborg/attic#195

Generally when I'm extracting it is to examine the backup first rather than just clobbering my existing files...

I guess this might be handled by the attic todo list per #1563

Making it clear that extract is relative to the current directory https://borgbackup.readthedocs.io/en/stable/quickstart.html#a-step-by-step-example could probably save a lot of confusion. See #1885

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants