Skip to content

OctoPrint requires parent folder permissions to restore from backup #4961

@stephen-mw

Description

@stephen-mw

The problem

I have my octoprint root directory at /etc/octoprint. Restoring from a backup fails because the octoprint user doesn't have permission to create files in /etc which is expected behavior:

Uploading backup, this can take a while. Please wait...
 
Restoring from backup...
 
Unpacking backup to /tmp/tmplba213wr...
Unpacked
Renaming /etc/octoprint to /etc/octoprint.bck...
Removing temporary unpacked folder
Error while running restore
Traceback (most recent call last):
  File "/usr/lib/python3.11/shutil.py", line 825, in move
    os.rename(src, real_dst)
PermissionError: [Errno 13] Permission denied: '/etc/octoprint' -> '/etc/octoprint.bck'

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/dist-packages/octoprint/plugins/backup/__init__.py", line 1323, in _restore_backup
    shutil.move(basedir, basedir_backup)
  File "/usr/lib/python3.11/shutil.py", line 841, in move
    copytree(src, real_dst, copy_function=copy_function,
  File "/usr/lib/python3.11/shutil.py", line 561, in copytree
    return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/shutil.py", line 459, in _copytree
    os.makedirs(dst, exist_ok=dirs_exist_ok)
  File "<frozen os>", line 225, in makedirs
PermissionError: [Errno 13] Permission denied: '/etc/octoprint.bck'
 
Restore failed! Check the above output and octoprint.log for reasons as to why.
Removing temporary zip

This following can and should always fail because octoprint should never get write permissions to the parent directory:

PermissionError: [Errno 13] Permission denied: '/etc/octoprint' -> '/etc/octoprint.bck'

One workaround is to put octoprint in a subdirectory where it can have parent permissions such as /etc/octoprint/octoprint.

That has the following drawbacks:

  1. More directories and setup are required for managing permissions.
  2. Octoprint can always write to the parent so nothing else should be stored there.

I'd like to propose the following fix:

  1. When octoprint does a restore it backs everything up to /tmp and then removes the contents of the directory.
  2. Once the contents are removed, the restore zip contents are unzipped directory into the root directory.

Thoughts on these changes? I can start working on it.

Did the issue persist even in safe mode?

Yes, it did persist

If you could not test in safe mode, please state why ("currently printing" is NOT an excuse!)

No response

Version of OctoPrint

octoprint, version 1.9.3

Operating system running OctoPrint

Debian GNU/Linux 12 (bookworm) (rasberry pi 4)

Printer model & used firmware incl. version

No response

Browser and version of browser, operating system running browser

No response

Checklist of files to include below

  • Systeminfo Bundle (always include!)
  • Contents of the JavaScript browser console (always include in cases of issues with the user interface)
  • Screenshots and/or videos showing the problem (always include in case of issues with the user interface)
  • GCODE file with which to reproduce (always include in case of issues with GCODE analysis or printing behaviour)

Additional information & file uploads

octoprint-systeminfo-20240225162317.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    doneDone but not yet releasedimprovementImproving functionality, behaviour, UX, ...

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions