Merge branch 'improve/backup-max-size' into maintenance

This commit is contained in:
Gina Häußge committed 2021-02-16 19:13:10 +01:00
commit c00fe8fda2
6 files changed
+61 -4

No files matched your search

+12 -2
View File
@@ -51,12 +51,15 @@ from flask_babel import gettext
from octoprint.plugins.pluginmanager import DEFAULT_PLUGIN_REPOSITORY
from octoprint.settings import valid_boolean_trues
from octoprint.util import get_formatted_size
from octoprint.util.text import sanitize
UNKNOWN_PLUGINS_FILE = "unknown_plugins_from_restore.json"
BACKUP_DATE_TIME_FMT = "%Y%m%d-%H%M%S"
MAX_UPLOAD_SIZE = 1024 * 1024 * 1024 # 1GB
class BackupPlugin(
octoprint.plugin.SettingsPlugin,
@@ -124,6 +127,12 @@ class BackupPlugin(
{"type": "wizard", "name": gettext("Restore Backup?")},
]
def get_template_vars(self):
return {
"max_upload_size": MAX_UPLOAD_SIZE,
"max_upload_size_str": get_formatted_size(MAX_UPLOAD_SIZE),
}
##~~ BlueprintPlugin
@octoprint.plugin.BlueprintPlugin.route("/", methods=["GET"])
@@ -137,6 +146,7 @@ class BackupPlugin(
backup_in_progress=len(self._in_progress) > 0,
unknown_plugins=unknown_plugins,
restore_supported=self._restore_supported(self._settings),
max_upload_size=MAX_UPLOAD_SIZE,
)
@octoprint.plugin.BlueprintPlugin.route("/unknown_plugins", methods=["GET"])
@@ -391,8 +401,8 @@ class BackupPlugin(
]
def bodysize_hook(self, current_max_body_sizes, *args, **kwargs):
# max upload size of 1GB for the restore endpoint
return [("POST", r"/restore", 1024 * 1024 * 1024)]
# max upload size for the restore endpoint
return [("POST", r"/restore", MAX_UPLOAD_SIZE)]
# Exported plugin helpers
def create_backup_helper(self, exclude=None, filename=None):
@@ -27,10 +27,15 @@ $(function () {
self.excludeFromBackup = ko.observableArray([]);
self.backupInProgress = ko.observable(false);
self.restoreSupported = ko.observable(true);
self.maxUploadSize = ko.observable(0);
self.backupUploadData = undefined;
self.backupUploadName = ko.observable();
self.isAboveUploadSize = function (data) {
return data.size > self.maxUploadSize();
};
var backupFileuploadOptions = {
dataType: "json",
maxNumberOfFiles: 1,
@@ -70,6 +75,7 @@ $(function () {
self.backups.updateItems(response.backups);
self.unknownPlugins(response.unknown_plugins);
self.restoreSupported(response.restore_supported);
self.maxUploadSize(response.max_upload_size);
};
self.createBackup = function () {
@@ -45,7 +45,7 @@
<td class="settings_plugin_backup_checkbox"><input type="checkbox" data-bind="value: name, checked: $root.markedForBackupDeletion"></td>
<td class="settings_plugin_backup_name" data-bind="text: name"></td>
<td class="settings_plugin_backup_date" data-bind="text: formatDate(date)"></td>
<td class="settings_plugin_backup_size" data-bind="text: formatSize(size)"></td>
<td class="settings_plugin_backup_size"><i class="fa fa-warning text-error" data-bind="visible: $root.isAboveUploadSize($data)" title="{{ _("This backup exceeds the maximum allowed upload size")|edq }}"></i> <span data-bind="text: formatSize(size)"></span></td>
<td class="settings_plugin_backup_actions"><a href="javascript:void(0)" title="{{ _('Delete')|edq }}" class="far fa-trash-alt" data-bind="click: function() { $parent.removeBackup($data.name) }, css: {disabled: $root.backupInProgress() || $root.restoreInProgress()}"></a>&nbsp;|&nbsp;<a href="javascript:void(0)" title="{{ _('Download')|edq }}" class="fas fa-download" data-bind="attr: {href: url}"></a><span data-bind="visible: $parent.restoreSupported()">&nbsp;|&nbsp;<a href="javascript:void(0)" title="{{ _('Restore')|edq }}" data-bind="click: function() { $parent.restoreBackup($data.name) }, css: {disabled: $root.backupInProgress() || $root.restoreInProgress()}"><i class="fas fa-sync"></i></a></span></td>
</tr>
</tbody>
@@ -61,6 +61,17 @@
<li data-bind="css: {disabled: backups.currentPage() === backups.lastPage()}"><a href="javascript:void(0)" data-bind="click: backups.nextPage">»</a></li>
</ul>
</div>
<p>
<strong>{{ _("Note:") }}</strong>
{% trans marker="<i class='fa fa-warning text-error'></i>" %}
OctoPrint currently only allows uploading backups of a maximum size of
{{ plugin_backup_max_upload_size_str }} via the UI. Backups larger than this can only be restored by command line,
or by adjusting the size by removing large contents (like timelapses) from the
zip prior to uploading. Backups exceeding this size limit are marked with a
{{ marker }} up there.
{% endtrans %}
</p>
</div>
<h3>{{ _('Create backup') }}</h3>
+13
View File
@@ -228,6 +228,19 @@ def recovery():
except Exception:
_logger.exception("Error processing theming CSS, ignoring")
try:
from octoprint.plugins.backup import MAX_UPLOAD_SIZE
from octoprint.util import get_formatted_size
render_kwargs.update(
{
"plugin_backup_max_upload_size": MAX_UPLOAD_SIZE,
"plugin_backup_max_upload_size_str": get_formatted_size(MAX_UPLOAD_SIZE),
}
)
except Exception:
_logger.exception("Error adding backup upload size info, ignoring")
return render_template("recovery.jinja2", **render_kwargs)
@@ -53,6 +53,10 @@ $(function () {
self.restoreSupported = ko.observable(false);
self.backups = ko.observableArray([]);
self.excludeFromBackup = ko.observableArray([]);
self.backupMaxUploadSize = ko.observable();
self.backupIsAboveUploadSize = function (data) {
return data.size > self.backupMaxUploadSize();
};
// working dialog
self.workDialog = $("#workdialog");
@@ -96,6 +100,7 @@ $(function () {
OctoPrint.plugins.backup.get().done(function (resp) {
self.backupSupported(true);
self.restoreSupported(resp.restore_supported);
self.backupMaxUploadSize(resp.max_upload_size);
var backups = resp.backups;
backups.sort(function (a, b) {
+13 -1
View File
@@ -132,7 +132,9 @@
<tbody data-bind="foreach: backups">
<tr>
<td><a href="javascript:void(0)" data-bind="text: name, attr: {href: url}"></a></td>
<td style="text-align: right" data-bind="text: formatSize(size)"></td>
<td style="text-align: right">
<strong data-bind="visible: $root.backupIsAboveUploadSize($data)" class="text-error">!</strong> <span data-bind="text: formatSize(size)"></span>
</td>
<td style="text-align: center" data-bind="text: formatDate(date)"></td>
<td style="text-align: center">
<button class="btn btn-small" data-bind="visible: $root.restoreSupported, click: $root.restoreBackup">{{ _('Restore') }}</button>
@@ -141,6 +143,16 @@
</tr>
</tbody>
</table>
<p data-bind="visible: backups().length > 0">
<strong>{{ _("Note:") }}</strong>
{% trans marker="<strong class='text-error'>!</strong>" %}
OctoPrint currently only allows uploading backups of a maximum size of
{{ plugin_backup_max_upload_size_str }} via the UI. Backups larger than this can only be restored by command line,
or by adjusting the size by removing large contents (like timelapses) from the
zip prior to uploading. Backups exceeding this size limit are marked with a
{{ marker }} up there.
{% endtrans %}
</p>
<p data-bind="visible: backups().length <= 0">
{{ _('There are no backups yet.') }}
</p>