borgbackup / borg

Deduplicating archiver with compression and authenticated encryption.
https://www.borgbackup.org/
Other
11.15k stars 742 forks source link

environment variable to set borg base location #3338

Closed Siassei closed 6 years ago

Siassei commented 6 years ago

In some use cases it is necessary to tell borg to use a home location that is not the user $HOME. Actually I do that do start all borg commands with modificated $HOME variable. But that feature should be included into borg! That makes it also possible to set another variables relativ to it and leads to cleaner code.

So, a variable like BORG_BASE_DIR or BORG_HOME_DIR should be introduced. e.g

# new shell variable, default value is $HOME
BORG_BASE_DIR=/yxz/abc

# possible default values of offical variables, if they are not set explicitly
BORG_CONFIG_DIR=$BORG_BASE_DIR/.config/borg
BORG_CACHE_DIR=$BORG_BASE_DIR/.cache/borg
BORG_KEYS_DIR=$BORG_CONFIG_DIR/keys
BORG_SECURITY_DIR=$BORG_CONFIG_DIR/security
# ...
ThomasWaldmann commented 6 years ago

Did you try setting HOME env var?

Siassei commented 6 years ago

yes, but I'm setting it up in a virtual machine and I changed also the setting of all offical announced borg env variables. One problem to set a new user home is, all other commands are also using it. From my side of view, a $BORG_BASE_DIR variable should exists and by default set to $HOME.

It should be possible (with a big hope of clean code base :-) ) if I look to fs.py. A new function ala _get_borg_basedir could provide the entry point https://github.com/borgbackup/borg/blob/c0b905875953a3819cb8b1454d3985608dff1934/src/borg/helpers/fs.py#L15-L74

beware, some test cases use the '~' for home directory, e.g. https://github.com/borgbackup/borg/blob/4a58310433f21857fc124eed4bafde2956bac46a/src/borg/testsuite/helpers.py#L492-L500

ThomasWaldmann commented 6 years ago
HOME=/foo borg ...

Then only borg (and everything invoked by borg, e.g. ssh) will see it.

ThomasWaldmann commented 6 years ago

Also, please add specifics about your use case, it is not really clear to my why you need to move all that stuff.

Siassei commented 6 years ago

Different systems == different behaivor of $HOME

What you would be expect? Look the following output and try to answer, is that what you expect?

'$' normal user console '#' root console

$ echo $HOME
/home/tenzinger
$ sudo -s
# echo $HOME
/root
# su backup
$ echo $HOME
/home/backup
$ exit
exit
# echo $HOME
/root
# exit
exit
$ echo $HOME
/home/tenzinger
$ uname -r
4.13.12-1-ARCH

# Arch Linux, Version 2017-11-20

and look to an different system with different linux disto :smile:

$ echo $HOME
/home/thomas
$ sudo -s
# echo $HOME
/home/thomas
# su hermann 
$ echo $HOME
/home/hermann
$ exit
exit
# echo $HOME
/home/thomas
# exit
exit
$ echo $HOME
/home/thomas
$ uname -r
4.4.0-98-generic

# lsb_release -a
LSB Version:    core-9.20160110ubuntu0.2-amd64:core-9.20160110ubuntu0.2-noarch:security-9.20160110ubuntu0.2-amd64:security-9.20160110ubuntu0.2-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:    16.04
Codename:   xenial

So. Some Linux/Distro do not setting $HOME=/root if you get root

Using borg inside docker container

To create an unisono solution for an backup strategy of my personal (and family) devices, I'm using two different solution. One solution ist to create an docker image. So, the borg settings + cache must be written into an virtual volume and for that, I will seperate the borg files from the reset, that writes to $HOME. So, actually I mount the volume to /xyz and create symbolic links to .config and .cache dir of borg. Yes, alternative I can pass $HOME to each borg command. But it possible solve an problem and not the root of the problem and I cann't do that. e.g. the .ssh directory is shared over multi-containers. So, the ssh command do not work correct / I need an additional symbolic link :face_with_head_bandage: Also, all future modification of borg env variables must be watched. To have one base dir replacment to $HOME / '~' would be nice!

edit: I forgot, the used user do not have an home directory.

Also, using ~ in your test files is very bad! ~ is always solved to $HOME. Fu... than use $HOME! It is more readable and keep sure on systems like windows, it is set correctly.

dimejo commented 6 years ago

Why sudo -s instead of sudo -i?

ThomasWaldmann commented 6 years ago

This can be used as a workaround if $HOME is somehow malfunctioning (see #3395).

But guess we need to stick a fat warning into the docs that one still has to care for permissions (not mixing up file permissions by using same dir by different users, so one user creates files the other user can't use) and separation (keeping stuff separate for different users).

Changes needed:

Alternatively:

@enkore any opinion? ^