✨ backup: config flag/env var to mark restore as unsupported

cc @LongLiveCHIEF
This commit is contained in:
Gina Häußge committed 2020-09-29 13:27:42 +02:00
1 parent 3672f7bad7
commit d19ce0a67e
2 files changed
+37 -7

No files matched your search

+19 -4
View File
@@ -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 <https://plugins.octoprint.org>`_
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 <sec-bundledplugins-backup-configuration>`.
.. [#2] Note that only those plugins that are available on `OctoPrint's official plugin repository <https://plugins.octoprint.org>`_
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.
+18 -3
View File
@@ -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: