diff --git a/src/octoprint/plugins/backup/__init__.py b/src/octoprint/plugins/backup/__init__.py index ca75bc11f..68061ba44 100644 --- a/src/octoprint/plugins/backup/__init__.py +++ b/src/octoprint/plugins/backup/__init__.py @@ -211,7 +211,8 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, plugin_manager=self._plugin_manager, on_install_plugins=on_install_plugins, on_report_unknown_plugins=on_report_unknown_plugins, - logger=self._logger)) + on_log_progress=on_log_progress, + on_log_error=on_log_error)) thread.daemon = True thread.start() @@ -234,6 +235,10 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, access_validation=access_validation_factory(app, admin_validator))) ] + 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)] + ##~~ CLI hook def cli_commands_hook(self, cli_group, pass_octoprint_ctx, *args, **kwargs): @@ -490,7 +495,7 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, if len(plugins): zip.writestr("plugin_list.json", json.dumps(plugins)) - shutil.move(temporary_path, final_path) + os.rename(temporary_path, final_path) if callable(on_backup_done): on_backup_done(name, final_path, exclude) @@ -601,17 +606,17 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, if callable(on_log_progress): on_log_progress("Renaming {} to {}...".format(basedir, basedir_backup)) - shutil.move(basedir, basedir_backup) + os.rename(basedir, basedir_backup) try: if callable(on_log_progress): on_log_progress("Moving {} to {}...".format(basedir_extracted, basedir)) - shutil.move(basedir_extracted, basedir) + os.rename(basedir_extracted, basedir) except: if callable(on_log_error): on_log_error("Error while restoring config data", exc_info=sys.exc_info()) on_log_error("Rolling back old config data") - shutil.move(basedir_backup, basedir) + os.rename(basedir_backup, basedir) return False #shutil.rmtree(basedir_backup) @@ -663,5 +668,6 @@ __plugin_license__ = "AGPLv3" __plugin_implementation__ = BackupPlugin() __plugin_hooks__ = { "octoprint.server.http.routes": __plugin_implementation__.route_hook, + "octoprint.server.http.bodysize": __plugin_implementation__.bodysize_hook, "octoprint.cli.commands": __plugin_implementation__.cli_commands_hook } diff --git a/src/octoprint/plugins/backup/static/js/backup.js b/src/octoprint/plugins/backup/static/js/backup.js index 11b73d2ea..7910617ac 100644 --- a/src/octoprint/plugins/backup/static/js/backup.js +++ b/src/octoprint/plugins/backup/static/js/backup.js @@ -44,6 +44,13 @@ return this.base.postJson(this.url + "restore", data, opts); }; + OctoPrintBackupClient.prototype.restoreBackupFromUpload = function (file, data) { + data = data || {}; + + var filename = data.filename || undefined; + return this.base.upload(this.url + "restore", file, filename, data); + }; + OctoPrintClient.registerPluginComponent("backup", OctoPrintBackupClient); return OctoPrintBackupClient; }); @@ -72,10 +79,36 @@ $(function() { [], 10 ); + self.markedForBackupDeletion = ko.observableArray([]); + self.excludeFromBackup = ko.observableArray([]); self.backupInProgress = ko.observable(false); + self.backupUploadButton = $("#settings-backup-upload"); + self.backupUploadData = undefined; + self.backupUploadButton.fileupload({ + dataType: "json", + maxNumberOfFiles: 1, + autoUpload: false, + headers: OctoPrint.getRequestHeaders(), + add: function(e, data) { + if (data.files.length == 0) { + // no files? ignore + return false; + } + + self.backupUploadName(data.files[0].name); + self.backupUploadData = data; + }, + done: function(e, data) { + self.backupUploadName(undefined); + self.backupUploadData = undefined; + } + }); + self.backupUploadName = ko.observable(); + self.restoreInProgress = ko.observable(false); + self.requestData = function() { OctoPrint.plugins.backup.get() .done(self.fromResponse); @@ -107,6 +140,11 @@ $(function() { }) }; + self.performRestoreFromUpload = function() { + if (self.backupUploadData === undefined) return; + self.backupUploadData.submit(); + }; + self.markFilesOnPage = function() { self.markedForBackupDeletion(_.uniq(self.markedForBackupDeletion().concat(_.map(self.backups.paginatedItems(), "name")))); }; diff --git a/src/octoprint/plugins/backup/templates/backup_settings.jinja2 b/src/octoprint/plugins/backup/templates/backup_settings.jinja2 index 8ce6edf2d..f69ca130a 100644 --- a/src/octoprint/plugins/backup/templates/backup_settings.jinja2 +++ b/src/octoprint/plugins/backup/templates/backup_settings.jinja2 @@ -26,7 +26,7 @@