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

Ability to specify cwd #23

Closed
nettnikl opened this issue Nov 22, 2021 · 11 comments
Closed

Ability to specify cwd #23

nettnikl opened this issue Nov 22, 2021 · 11 comments

Comments

@nettnikl
Copy link

I'd like to propose a new feature - the ability to specify the cwd of the backup process. This seems to be a recurring pattern to allow relative path based backups (a use case is described at https://forum.restic.net/t/backing-up-restoring-relative-paths/744). This would be quite easy, as the subprocess.call supports the cwd parameter.

@nettnikl nettnikl changed the title Ability tp specify cwd Ability to specify cwd Nov 22, 2021
@nils-werner
Copy link
Owner

Agreed, that might be handy to have.

I'm thinking of introducing it as something like _cwd: and deprecating arguments: in favor of _args:, to prevent collisions with restic commandline options now or in the future.

@nils-werner
Copy link
Owner

nils-werner commented Nov 23, 2021

I have pushed a few changes to cwd-param. Have a go and see if it works as expected.

@nettnikl
Copy link
Author

Will do, thanks for your quick reaction!

@nettnikl
Copy link
Author

Hey, finally had a chance to test on my setup, sorry for the delay.
It works, in the dry run as well as in my real setup! Great job!
One thing that it'd like considered looking at the resulting configs however - maybe a default backup path of "." would make sense, maybe only in cases where a path is given via cwd? What are your thoughts on this (or do you see discussion potential for another issue)?
Thanks again!

@nils-werner
Copy link
Owner

nils-werner commented Nov 26, 2021

Great to hear!

You mean a file

[home]
_cwd: ~

implies

[home]
_cwd: ~
_args: .

?

Hmm... I think woud prefer to not implement any default behaviour here, as using a cwd and then defining a path relative to it is definitely advanced usage that requires knowledge about how restic treats the two differently. In that case I think it would be best to make all the paths involved directly visible to the user.

@nettnikl
Copy link
Author

Okay, i agree, i'm just looking for an option to have a "speaking" config file, as the idea of the option "_args: /path/to/backup" is not immediately clear for everyone. However, that has nothing to do with this request. I'll open a new ticket, this one is solved perfectly!

@nils-werner
Copy link
Owner

Lets keep this open until it has been merged into master.

@nils-werner nils-werner reopened this Nov 28, 2021
@nils-werner
Copy link
Owner

nils-werner commented Nov 28, 2021

Actually, I am playing with the idea of moving _cwd into the [backup.environ] group, because it is arguably an attribute of the execution environment, and not a command option or argument

@nils-werner
Copy link
Owner

Ok, I think I like it more that way: Your typical UNIX environment variables already contain $PWD that contains the current working directory. So it kind of makes sense to use this variable to change the cwd of restic:

[home]
_args: .

[home.environ]
PWD: ~

And you can also now cleanly override this value from the commandline

env PWD=~ crestic home backup

A small caveat: Normally, changing $PWD before running a command is not the same as changing the current cwd. Compare

(cd / && ls)
env PWD=/ ls

but I am ignoring that fact here.

@nettnikl
Copy link
Author

While it technically is, i think it makes the config harder to read, which should also not be neglected. The current solution looks good to me - maybe you could show how the idiom i mentioned would look in with the alternative approach?

@nils-werner
Copy link
Owner

This is now in 0.8.0 and called _workdir:.

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

2 participants