borgbase / vorta

Desktop Backup Client for Borg Backup
https://vorta.borgbase.com
GNU General Public License v3.0
1.98k stars 130 forks source link

Vorta cannot be executed as root user #1125

Closed Carpe-Diem-Postero closed 2 years ago

Carpe-Diem-Postero commented 2 years ago

Describe the bug Vorta execution fails when run as root user.

To Reproduce Steps to reproduce the behavior:

  1. Install borgbackup and vorta as root (sudo su)
  2. Run vorta as root
  3. vorta fails to initiate, throws an "IndexError: list index out of range"
  4. vorta works fine if run as any other non-root user

Environment (please complete the following information):

Additional context Was using an alpine docker container with vorta, compiled on 2020. It worked fine, but vorta failed when updating inside container from command line. I cloned the repository, and found that building the same original Dockerfile myself ended in a non-functional container. Then I troubleshoot the problem and found that even on native installations, 0.8.2 fails to start if root user is the one running the launching command. When I switch to other user, it works fine.

That's a problem, as you might need root privilege to backup some directories, and also most containers run as root user, which breaks compatibility.

Log when running as su:


Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/peewee.py", line 6933, in get
    return clone.execute(database)[0]
  File "/usr/lib/python3.8/site-packages/peewee.py", line 4306, in __getitem__
    return self.row_cache[item]
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/peewee.py", line 6518, in get_or_create
    return query.get(), False
  File "/usr/lib/python3.8/site-packages/peewee.py", line 6936, in get
    raise self.model.DoesNotExist('%s instance matching query does '
vorta.store.models.SettingsModelDoesNotExist: <Model: SettingsModel> instance matching query does not exist:
SQL: SELECT "t1"."id", "t1"."key", "t1"."value", "t1"."str_value", "t1"."label", "t1"."type" FROM "settingsmodel" AS "t1" WHERE ("t1"."key" = ?) LIMIT ? OFFSET ?
Params: ['autostart', 1, 0]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/vorta", line 11, in <module>
    load_entry_point('vorta==0.8.2', 'gui_scripts', 'vorta')()
  File "/usr/lib/python3.8/site-packages/vorta/__main__.py", line 54, in main
    init_db(sqlite_db)
  File "/usr/lib/python3.8/site-packages/vorta/store/connection.py", line 47, in init_db
    s, created = SettingsModel.get_or_create(key=setting['key'], defaults=setting)
  File "/usr/lib/python3.8/site-packages/peewee.py", line 6524, in get_or_create
    return cls.create(**kwargs), True
  File "/usr/lib/python3.8/site-packages/peewee.py", line 6393, in create
    inst.save(force_insert=True)
  File "/usr/lib/python3.8/site-packages/playhouse/signals.py", line 72, in save
    post_save.send(self, created=created)
  File "/usr/lib/python3.8/site-packages/playhouse/signals.py", line 51, in send
    responses.append((r, r(sender, instance, *args, **kwargs)))
  File "/usr/lib/python3.8/site-packages/vorta/store/connection.py", line 16, in setup_autostart
    open_app_at_startup(instance.value)
  File "/usr/lib/python3.8/site-packages/vorta/autostart.py", line 49, in open_app_at_startup
    autostart_path.mkdir()
  File "/usr/lib/python3.8/pathlib.py", line 1288, in mkdir
    self._accessor.mkdir(self, mode)
FileNotFoundError: [Errno 2] No such file or directory: '/config/xdg/config/autostart' ```
m3nu commented 2 years ago

There is some existing discussion on this. TLDR is that Vorta focuses on backing up your home folder and doing a full system backup with root permissions is not a targeted use case.

There are still different ways to run it as root. Old issues and discussions here on Github will have more.

Of course, if we could make it work with minor changes, I'd consider a PR to change this.

Carpe-Diem-Postero commented 2 years ago

There is some existing discussion on this. TLDR is that Vorta focuses on backing up your home folder and doing a full system backup with root permissions is not a targeted use case.

There are still different ways to run it as root. Old issues and discussions here on Github will have more.

Of course, if we could make it work with minor changes, I'd consider a PR to change this.

I can understand that, thanks (although I think that users should have the choice about running Vorta as root or not, if it's not too much work).

I have been digging for the last few days in the closed issues trying to find something about it, but I was not able to do so. I'll research a little more, but if you could point me to some of this posts about running vorta as root, You would immensely help me.

Thanks again.

goebbe commented 2 years ago

@TraumaGuy: See #559 #422 and #240 for the discussion and background information.

Carpe-Diem-Postero commented 2 years ago

@TraumaGuy: See #559 #422 and #240 for the discussion and background information.

Ok, thanks for the references..

I see that, as stated previously, Devs think that Vorta is not a server backup tool, so no need for root access.

While I can understand that thinking current, I can assure, as admin in several NAS and server communities, that this is not true. More and more people are starting to use NAS as home microserver and as backup storage for their homes devices. That data must be backup up somewhere else as for 3-2-1 backup policy, and not everyone (in fact, I'd say most NAS users) don't even how to use CLI. Duplicati is the most used FOSS backup solution right now, and it's for a reason: It has GUI.

Also, PULL backup policy offer a more secure approach to backups, and it requires software running on the server side.

It's a pity that Borg is so underused as server backup tool just for not having a proper GUI.

Thanks everyone for the help.

m3nu commented 2 years ago

It's a pity that Borg is so underused as server backup tool just for not having a proper GUI.

I don't think it's underused. Most people just don't use a GUI on a server. Usually it's Borgmatic or their own Borg script.

FileNotFoundError: [Errno 2] No such file or directory: '/config/xdg/config/autostart'

If it's just for this error, this can be fixed. You can also run it from root user's desktop without issue (I think). It's just tricky if you run sudo vorta and the window manager and possibly cache files all use different users. This could be chaotic.

Carpe-Diem-Postero commented 2 years ago

If it's just for this error, this can be fixed. You can also run it from root user's desktop without issue (I think). It's just tricky if you run sudo vorta and the window manager and possibly cache files all use different users. This could be chaotic.

No, you can't, or at least I was not able to (tried in 2 different installations) Installing vorta as su, and running as su (no sudo command involved except for the first "sudo su"). Same thing happens when using flatpak installation.

sudo su --> install vorta --> run vorta = Not working non root user --> install vorta --> sudo vorta = Not working non root user --> install vorta --> sudo su --> run vorta = Not working non root user --> install vorta --> run vorta = Working

So, it seem that problem lays in root execution of vorta. sudo vorta or just vorta as root just don't seem to matter.

IndexError: list index out of range <-- This seems to be the first error that vorta outputs when running as root, so even if the mentioned FileNotFoundError: [Errno 2] No such file or directory: '/config/xdg/config/autostart' would be fixed, I don't think it would work.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.