def run(self, cmd, opts, backup_name, *restore_options): backup = spool.find_backup(backup_name) if not backup: logging.error("No backup found named %s", backup_name) return 1 config = backup.config plugin_name = config.get('holland:backup', {}).get('plugin') plugin = load_first_entrypoint('holland.restore', plugin_name)(backup) plugin.dispatch([plugin_name] + list(restore_options)) return 1
def run(self, cmd, opts, plugin_type): if opts.name and opts.provider: print >>sys.stderr, "Can't specify a name for a global provider config" return 1 try: plugin_cls = load_first_entrypoint("holland.backup", plugin_type) except PluginLoadError, exc: logging.info("Failed to load backup plugin %r: %s", plugin_type, exc) return 1
def run(self, cmd, opts, *args): backup = SPOOL.find_backup(args[0]) if not backup: logging.error("No backup found named %s", args[0]) return 1 config = backup.config plugin_name = config.get('holland:backup', {}).get('plugin') plugin = load_first_entrypoint('holland.restore', plugin_name)(backup) plugin.dispatch([plugin_name] + list(args)) return 1
def run(self, cmd, opts, plugin_type): if opts.name and opts.provider: print >>sys.stderr, "Can't specify a name for a global provider config" return 1 try: plugin_cls = load_first_entrypoint('holland.backup', plugin_type) except PluginLoadError, exc: logging.info("Failed to load backup plugin %r: %s", plugin_type, exc) return 1
def run(self, cmd, opts, *plugin_type): if not plugin_type: print("Missing plugin name", file=sys.stderr) return 1 if opts.name and opts.provider: print("Can't specify a name for a global provider config", file=sys.stderr) return 1 try: plugin_cls = load_first_entrypoint('holland.backup', plugin_type[0]) except PluginLoadError as exc: logging.info("Failed to load backup plugin %r: %s", plugin_type[0], exc) return 1 try: cfgspec = sys.modules[plugin_cls.__module__].CONFIGSPEC except BaseException as ex: print("Could not load config-spec from plugin %r, %s" % (plugin_type[0], ex), file=sys.stderr) return 1 base_config = """ [holland:backup] plugin = "" backups-to-keep = 1 auto-purge-failures = yes purge-policy = after-backup estimated-size-factor = 1.0 """.lstrip().splitlines() cfg = ConfigObj(base_config, configspec=cfgspec, list_values=True, stringify=True) cfg['holland:backup']['plugin'] = plugin_type[0] self._cleanup_config(cfg, skip_comments=opts.minimal) if opts.edit: done = False editor = _find_editor() if not editor: print("Could not find a valid editor", file=sys.stderr) return 1 tmpfileobj = tempfile.NamedTemporaryFile() cfg.filename = tmpfileobj.name cfg.write() while not done: status = subprocess.call([editor, cfg.filename]) if status != 0: if not confirm("Editor exited with non-zero status[%d]. " "Would you like to retry?" % status): print("Aborting", file=sys.stderr) return 1 try: cfg.reload() except ParseError as exc: print("%s : %s" % \ (exc.msg, exc.line), file=sys.stderr) else: errors = cfg.validate(VALIDATOR, preserve_errors=True) if errors is True: done = True continue else: _report_errors(cfg, errors) if not confirm('There were configuration errors. Continue?'): print("Aborting", file=sys.stderr) return 1 tmpfileobj.close() if not opts.name and not opts.file: buf = getattr(sys.stdout, 'buffer', sys.stdout) cfg.write(buf) buf.flush() if opts.file: print("Saving config to %r" % opts.file, file=sys.stderr) filehandle = open(opts.file, 'w') buf = getattr(filehandle, 'buffer', filehandle) cfg.write(buf) buf.flush() elif opts.name: base_dir = os.path.dirname(HOLLANDCFG.filename) path = os.path.join(base_dir, 'backupsets', opts.name + '.conf') print("Saving config to %r" % path, file=sys.stderr) filehandle = open(path, 'w') buf = getattr(filehandle, 'buffer', filehandle) cfg.write(buf) buf.flush() return 0
def run(self, cmd, opts, *plugin_type): if not plugin_type: print("Missing plugin name", file=sys.stderr) return 1 if opts.name and opts.provider: print("Can't specify a name for a global provider config", file=sys.stderr) return 1 try: plugin_cls = load_first_entrypoint("holland.backup", plugin_type[0]) except PluginLoadError as exc: logging.info("Failed to load backup plugin %r: %s", plugin_type[0], exc) return 1 try: cfgspec = sys.modules[plugin_cls.__module__].CONFIGSPEC except BaseException as ex: print( "Could not load config-spec from plugin %r, %s" % (plugin_type[0], ex), file=sys.stderr, ) return 1 base_config = """ [holland:backup] plugin = "" backups-to-keep = 1 auto-purge-failures = yes purge-policy = after-backup estimated-size-factor = 1.0 """.lstrip().splitlines() cfg = ConfigObj(base_config, configspec=cfgspec, list_values=True, stringify=True) cfg["holland:backup"]["plugin"] = plugin_type[0] self._cleanup_config(cfg, skip_comments=opts.minimal) if opts.edit: done = False editor = _find_editor() if not editor: print("Could not find a valid editor", file=sys.stderr) return 1 tmpfileobj = tempfile.NamedTemporaryFile() cfg.filename = tmpfileobj.name cfg.write() while not done: status = subprocess.call([editor, cfg.filename]) if status != 0: if not confirm( "Editor exited with non-zero status[%d]. " "Would you like to retry?" % status ): print("Aborting", file=sys.stderr) return 1 try: cfg.reload() except ParseError as exc: print("%s : %s" % (exc.msg, exc.line), file=sys.stderr) else: errors = cfg.validate(VALIDATOR, preserve_errors=True) if errors is True: done = True continue else: _report_errors(cfg, errors) if not confirm("There were configuration errors. Continue?"): print("Aborting", file=sys.stderr) return 1 tmpfileobj.close() if not opts.name and not opts.file: buf = getattr(sys.stdout, "buffer", sys.stdout) cfg.write(buf) buf.flush() if opts.file: print("Saving config to %r" % opts.file, file=sys.stderr) filehandle = open(opts.file, "w") buf = getattr(filehandle, "buffer", filehandle) cfg.write(buf) buf.flush() elif opts.name: base_dir = os.path.dirname(HOLLANDCFG.filename) path = os.path.join(base_dir, "backupsets", opts.name + ".conf") print("Saving config to %r" % path, file=sys.stderr) filehandle = open(path, "w") buf = getattr(filehandle, "buffer", filehandle) cfg.write(buf) buf.flush() return 0