KenKundert / emborg

Interactive command line interface to Borg Backup
GNU General Public License v3.0
94 stars 8 forks source link

"emborg borg key export" needs to be run as root? #42

Closed dekiesel closed 3 years ago

dekiesel commented 3 years ago

I realize this is probably more of a forum-question kinda thing, but I couldn't find one, so here goes nothing:

I created a repo using emborg and uploaded some test data to it (rsync.net account). I was warned to extract my key, so I tried doing that:

pi@raspberrypi:~/.config/emborg $ emborg borg key export 12345@rsync.net:borg_rpi borg.ke
Local Exception
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/borg/archiver.py", line 4455, in main
    exit_code = archiver.run(args)
  File "/usr/lib/python3/dist-packages/borg/archiver.py", line 4387, in run
    return set_ec(func(args))
  File "/usr/lib/python3/dist-packages/borg/archiver.py", line 154, in wrapper
    return method(self, args, repository=repository, **kwargs)
  File "/usr/lib/python3/dist-packages/borg/archiver.py", line 358, in do_key_export
    manager.export(args.path)
  File "/usr/lib/python3/dist-packages/borg/crypto/keymanager.py", line 85, in export
    self.store_keyfile(path)
  File "/usr/lib/python3/dist-packages/borg/crypto/keymanager.py", line 81, in store_keyfile
    with open(target, 'w') as fd:
PermissionError: [Errno 13] Permission denied: 'borg.ke'

Platform: Linux raspberrypi 5.4.79-v7l+ #1373 SMP Mon Nov 23 13:27:40 GMT 2020 armv7l
Linux: debian 10.9
Borg: 1.1.9  Python: CPython 3.7.3
PID: 3949  CWD: /
sys.argv: ['/usr/bin/borg', '--remote-path', 'borg1', 'key', 'export', '123455@rsync.net:borg_rp
i', 'borg.ke']
SSH_ORIGINAL_COMMAND: None

emborg error: unexpected exit status (2)

It seems the process CWDs to ´/´ and then has a hard time creating a file there. Does that mean that I have to use sudo when extracting the key?

emborg info shows me where the keyfile is saved: /home/pi/.config/borg/keys/..., can't I just copy the keyfile from there?

Thanks for your help!

dekiesel commented 3 years ago

Of course after creating this issue I had the idea to just give it an absolute path like so emborg borg key export 12345@rsync.net:borg_rpi /home/pi/ .config/emborg/borg.ke, which works as expected.

Is there an advantage to using this command over simply copying the key from the keys directory?

KenKundert commented 3 years ago

Unlike Borg, Emborg is designed to be run from any directory. To make this work with Borg it changes the working directory to working_dir before running select commands. If working_dir is not specified then Emborg changes to / before running the borg command.

I don't know whether there are any disadvantages to simply copying the key from the keys directory.

dekiesel commented 3 years ago

Ah, that makes sense and works now. I got working_dir mixed up with src_dir, thanks for the help!

I also checked the resulting file against the file I copied manually and they are identical.