From d19ce0a67e9851d0a14b891193a35406acb0f765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 29 Sep 2020 13:27:42 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20backup:=20config=20flag/env=20var?= =?UTF-8?q?=20to=20mark=20restore=20as=20unsupported?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cc @LongLiveCHIEF --- docs/bundledplugins/backup.rst | 23 +++++++++++++++++++---- src/octoprint/plugins/backup/__init__.py | 21 ++++++++++++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/docs/bundledplugins/backup.rst b/docs/bundledplugins/backup.rst index 1d5f78097..e11c149c4 100644 --- a/docs/bundledplugins/backup.rst +++ b/docs/bundledplugins/backup.rst @@ -7,7 +7,7 @@ Backup Plugin The OctoPrint Backup Plugin comes bundled with OctoPrint (starting with 1.3.10). -It allows the creation and restoration of backups of OctoPrint's settings, data and installed plugins [#]_. +It allows the creation and restoration [#1]_ of backups of OctoPrint's settings, data and installed plugins [#2]_. This allows easy migration to newly setup instances as well as making regular backups to prevent data loss. @@ -23,6 +23,19 @@ As long as plugins adhere to the standard of storing their data and settings in data will be part of the backup. Note that the backups made by the Backup Plugin will *not* be part of any backups - you'll need to persist the resulting zip files yourself! +.. _sec-bundledplugins-backup-configuration: + +Configuring the plugin +---------------------- + +The plugin supports the following configuration keys: + + * ``restore_unsupported``: If the system you are installing OctoPrint on doesn't support restoring backups or you + want to disable that feature for other reasons, set this to `true`. Alternatively you can also set the + environment variable `OCTOPRINT_BACKUP_RESTORE_UNSUPPORTED` to `true`. OctoPrint will then disable the restore + functionality. Under normal circumstances you should not have to touch this setting (OctoPrint will do its + best to autodetect whether it's able to perform restores), thus it is not exposed in the Settings dialog. + .. _sec-bundledplugins-backup-cli: Command line usage @@ -172,6 +185,8 @@ Source code The source of the Backup plugin is bundled with OctoPrint and can be found in its source repository under ``src/octoprint/plugins/backup``. -.. [#] Note that only those plugins that are available on `OctoPrint's official plugin repository `_ - can be automatically restored. If you have plugins installed that are not available on there you'll get their - names and - if available - homepage URL displayed after restore in order to be able to manually reinstall them. +.. [#1] Note that restore is currently unavailable on OctoPrint servers running on Windows. Additionally they may be + disabled through a config flag or an environment variable as documented :ref:`here `. +.. [#2] Note that only those plugins that are available on `OctoPrint's official plugin repository `_ + can be automatically restored. If you have plugins installed that are not available on there you'll get their + names and - if available - homepage URL displayed after restore in order to be able to manually reinstall them. diff --git a/src/octoprint/plugins/backup/__init__.py b/src/octoprint/plugins/backup/__init__.py index 9b40a5a4e..f00063454 100644 --- a/src/octoprint/plugins/backup/__init__.py +++ b/src/octoprint/plugins/backup/__init__.py @@ -46,6 +46,8 @@ import json import sys import traceback +from octoprint.settings import valid_boolean_trues + UNKNOWN_PLUGINS_FILE = "unknown_plugins_from_restore.json" @@ -98,6 +100,13 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, self._clean_dir_backup(self._settings._basedir, on_log_progress=self._logger.info) + ##~~ SettingsPlugin + + def get_settings_defaults(self): + return { + "restore_unsupported": False + } + ##~~ AssetPlugin def get_assets(self): @@ -123,7 +132,7 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, return flask.jsonify(backups=backups, backup_in_progress=len(self._in_progress) > 0, unknown_plugins=unknown_plugins, - restore_supported=is_os_compatible(["!windows"])) + restore_supported=self._restore_supported(self._settings)) @octoprint.plugin.BlueprintPlugin.route("/unknown_plugins", methods=["GET"]) @no_firstrun_access @@ -231,7 +240,7 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, if not Permissions.PLUGIN_BACKUP_ACCESS.can() and not self._settings.global_get(["server", "firstRun"]): return flask.abort(403) - if not is_os_compatible(["!windows"]): + if not self._restore_supported(self._settings): return flask.make_response("Invalid request, the restores are not supported on the underlying operating system", 400) input_name = "file" @@ -800,7 +809,7 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, on_restore_start=None, on_restore_done=None, on_restore_failed=None): - if not is_os_compatible(["!windows"]): + if not cls._restore_supported(settings): if callable(on_log_error): on_log_error("Restore is not supported on this operating system") if callable(on_restore_failed): @@ -1024,6 +1033,12 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, return True + @classmethod + def _restore_supported(cls, settings): + return is_os_compatible(["!windows"]) \ + and not settings.get_boolean(["restore_unsupported"]) \ + and not os.environ.get("OCTOPRINT_BACKUP_RESTORE_UNSUPPORTED", False) in valid_boolean_trues + def _send_client_message(self, message, payload=None): if payload is None: