borgbutler-server/src/main/java/de/micromata/borgbutler/server/BorgInstallation.java
@@ -3,6 +3,7 @@ import de.micromata.borgbutler.BorgCommands; import de.micromata.borgbutler.config.Configuration; import de.micromata.borgbutler.config.ConfigurationHandler; import lombok.Getter; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpResponse; @@ -26,6 +27,9 @@ return instance; } @Getter private BorgVersion borgVersion = new BorgVersion(); public void initialize() { Configuration configuration = ConfigurationHandler.getConfiguration(); if (StringUtils.isNotBlank(configuration.getBorgCommand())) { @@ -37,34 +41,31 @@ if (version(configuration)) { return; } BorgVersion borgVersion = ServerConfiguration.get()._getBorgVersion(); log.warn("No working borg version found. Please configure a borg version with minimal version '" + borgVersion.getMinimumRequiredBorgVersion() + "'."); } /** * Configures a new borg configuration if modifications was done. * @param oldVersion The old version before this current modification. * * @param newConfiguration The new configuration with the (new) borg command to use (executable). * @param borgBinary The id of the borg binary (Mac OS X, Linux 64, manual etc.) */ public void configure(BorgVersion oldVersion) { Configuration configuration = ConfigurationHandler.getConfiguration(); BorgVersion newVersion = ServerConfiguration.get()._getBorgVersion(); boolean borgBinaryChanged = !StringUtils.equals(oldVersion.getBorgBinary(), newVersion.getBorgBinary()); boolean manualBorgCommand = "manual".equals(newVersion.getBorgBinary()); public void configure(ServerConfiguration newConfiguration, String borgBinary) { ServerConfiguration configuration = ServerConfiguration.get(); boolean borgBinaryChanged = !StringUtils.equals(borgVersion.getBorgBinary(), borgBinary); borgVersion.setBorgBinary(borgBinary); // Update borg binary (if changed). boolean manualBorgCommand = "manual".equals(borgBinary); if (manualBorgCommand) { boolean borgCommandChanged = !StringUtils.equals(oldVersion.getBorgCommand(), newVersion.getBorgCommand()); boolean borgCommandChanged = !StringUtils.equals(newConfiguration.getBorgCommand(), configuration.getBorgCommand()); if (borgCommandChanged) { configuration.setBorgCommand(newVersion.getBorgCommand()); configuration.setBorgCommand(newConfiguration.getBorgCommand()); version(configuration); } else { newVersion.copyFrom(oldVersion); // Restore all old settings. } } else { if (borgBinaryChanged) { newVersion.setBorgCommand(oldVersion.getBorgCommand()); // Don't modify borg command, if not manual. initialize(getBinary(newVersion.getBorgBinary())); } else { newVersion.copyFrom(oldVersion); // Restore all old settings. initialize(getBinary(borgBinary)); } newConfiguration.setBorgCommand(configuration.getBorgCommand()); // borg command of this class overwrites new configuration for mode != 'manual'. } } @@ -74,19 +75,25 @@ } Configuration configuration = ConfigurationHandler.getConfiguration(); File file = download(binary); BorgVersion borgVersion = ServerConfiguration.get()._getBorgVersion(); if (file != null) { configuration.setBorgCommand(file.getAbsolutePath()); borgVersion.setBorgCommand(file.getAbsolutePath()); borgVersion.setBorgBinary(binary[0]); } return version(configuration); } private boolean version(Configuration configuration) { String borgCommand = configuration.getBorgCommand(); if (StringUtils.isNotBlank(borgCommand)) { for (String[] borgBinary : borgVersion.getBorgBinaries()) { if (borgCommand.contains(borgBinary[0])) { borgVersion.setBorgBinary(borgBinary[0]); break; } } } String versionString = BorgCommands.version(); boolean versionOK = false; BorgVersion borgVersion = ServerConfiguration.get()._getBorgVersion(); String msg = null; if (versionString != null) { borgVersion.setVersion(versionString); @@ -128,7 +135,6 @@ if (os == null) { return null; } BorgVersion borgVersion = ServerConfiguration.get()._getBorgVersion(); for (String[] binary : borgVersion.getBorgBinaries()) { if (binary[0].contains(os)) { return binary; @@ -152,7 +158,6 @@ // File already downloaded, nothing to do. return file; } BorgVersion borgVersion = ServerConfiguration.get()._getBorgVersion(); String url = borgVersion.getBinariesDownloadUrl() + getDownloadFilename(binary); log.info("Trying to download borg binary '" + binary[0] + "' (" + binary[1] + ") from url: " + url + "..."); HttpClientBuilder builder = HttpClients.custom() @@ -183,7 +188,6 @@ log.info("Creating binary directory: " + dir.getAbsolutePath()); dir.mkdirs(); } BorgVersion borgVersion = ServerConfiguration.get()._getBorgVersion(); return new File(dir, getDownloadFilename(binary) + "-" + borgVersion.getBinariesDownloadVersion()); } borgbutler-server/src/main/java/de/micromata/borgbutler/server/BorgVersion.java
@@ -26,12 +26,6 @@ @Getter @Setter(AccessLevel.PACKAGE) private String borgBinary; /** * The path of the borg command to use. */ @Getter @Setter private String borgCommand; @Getter @Setter(AccessLevel.PACKAGE) @@ -44,7 +38,6 @@ private String statusMessage; public BorgVersion copyFrom(BorgVersion other) { this.borgCommand = other.borgCommand; this.borgBinary = other.borgBinary; this.versionOK = other.versionOK; this.version = other.version; borgbutler-server/src/main/java/de/micromata/borgbutler/server/ServerConfiguration.java
@@ -18,7 +18,6 @@ private int port = WEBSERVER_PORT_DEFAULT; private boolean webDevelopmentMode = WEB_DEVELOPMENT_MODE_PREF_DEFAULT; private BorgVersion borgVersion = new BorgVersion(); @JsonProperty public String getCacheDir() { return ButlerCache.getInstance().getCacheDir().getAbsolutePath(); @@ -32,17 +31,6 @@ return SUPPORTED_LANGUAGES; } /** * @return a clone of this.borgVersion. */ public BorgVersion getBorgVersion() { return new BorgVersion().copyFrom(borgVersion); } BorgVersion _getBorgVersion() { return this.borgVersion; } public static String getApplicationHome() { if (applicationHome == null) { applicationHome = System.getProperty("applicationHome"); @@ -77,7 +65,5 @@ super.copyFrom(other); this.port = other.port; this.webDevelopmentMode = other.webDevelopmentMode; this.borgVersion.copyFrom(other.borgVersion); this.setBorgCommand(this.borgVersion.getBorgCommand()); } } borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ConfigurationInfo.java
New file @@ -0,0 +1,15 @@ package de.micromata.borgbutler.server.rest; import de.micromata.borgbutler.server.BorgVersion; import de.micromata.borgbutler.server.ServerConfiguration; import lombok.Getter; import lombok.Setter; public class ConfigurationInfo { @Getter @Setter private ServerConfiguration serverConfiguration; @Getter @Setter private BorgVersion borgVersion; } borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ConfigurationRest.java
@@ -4,7 +4,6 @@ import de.micromata.borgbutler.config.ConfigurationHandler; import de.micromata.borgbutler.json.JsonUtils; import de.micromata.borgbutler.server.BorgInstallation; import de.micromata.borgbutler.server.BorgVersion; import de.micromata.borgbutler.server.ServerConfiguration; import de.micromata.borgbutler.server.user.UserData; import de.micromata.borgbutler.server.user.UserManager; @@ -20,7 +19,6 @@ private Logger log = LoggerFactory.getLogger(ConfigurationRest.class); /** * * @param prettyPrinter If true then the json output will be in pretty format. * @see JsonUtils#toJson(Object, boolean) */ @@ -28,7 +26,10 @@ @Path("config") @Produces(MediaType.APPLICATION_JSON) public String getConfig(@QueryParam("prettyPrinter") boolean prettyPrinter) { String json = JsonUtils.toJson(ServerConfiguration.get(), prettyPrinter); ConfigurationInfo configurationInfo = new ConfigurationInfo(); configurationInfo.setServerConfiguration(ServerConfiguration.get()); configurationInfo.setBorgVersion(BorgInstallation.getInstance().getBorgVersion()); String json = JsonUtils.toJson(configurationInfo, prettyPrinter); return json; } @@ -37,16 +38,14 @@ @Produces(MediaType.TEXT_PLAIN) public void setConfig(String jsonConfig) { ConfigurationHandler configurationHandler = ConfigurationHandler.getInstance(); ServerConfiguration config = (ServerConfiguration)configurationHandler.getConfiguration(); ServerConfiguration srcConfig = JsonUtils.fromJson(ServerConfiguration.class, jsonConfig); BorgVersion oldBorgVersion = config.getBorgVersion(); config.copyFrom(srcConfig); BorgInstallation.getInstance().configure(oldBorgVersion); ConfigurationInfo configurationInfo = JsonUtils.fromJson(ConfigurationInfo.class, jsonConfig); BorgInstallation.getInstance().configure(configurationInfo.getServerConfiguration(), configurationInfo.getBorgVersion().getBorgBinary()); ServerConfiguration configuration = ServerConfiguration.get(); configuration.copyFrom(configurationInfo.getServerConfiguration()); configurationHandler.save(); } /** * * @param prettyPrinter If true then the json output will be in pretty format. * @see JsonUtils#toJson(Object, boolean) */ borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/SystemInfoRest.java
@@ -2,8 +2,8 @@ import de.micromata.borgbutler.BorgQueueExecutor; import de.micromata.borgbutler.json.JsonUtils; import de.micromata.borgbutler.server.BorgInstallation; import de.micromata.borgbutler.server.BorgVersion; import de.micromata.borgbutler.server.ServerConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,7 +24,7 @@ @Produces(MediaType.APPLICATION_JSON) @Path("info") public String getStatistics() { BorgVersion borgVersion = ServerConfiguration.get().getBorgVersion(); BorgVersion borgVersion = BorgInstallation.getInstance().getBorgVersion(); SystemInfo systemInfonfo = new SystemInfo() .setQueueStatistics(BorgQueueExecutor.getInstance().getStatistics()) .setConfigurationOK(borgVersion.isVersionOK()) borgbutler-webapp/src/components/views/config/ConfigurationServerTab.jsx
@@ -35,9 +35,9 @@ .then((data) => { this.setState({ loading: false, borgVersion: data.borgVersion, borgBinary: data.borgVersion.borgBinary, borgCommand: data.borgVersion.borgCommand, ...data ...data.serverConfiguration }) }) .catch((error) => { @@ -84,12 +84,14 @@ save() { var config = { port: this.state.port, maxArchiveContentCacheCapacityMb: this.state.maxArchiveContentCacheCapacityMb, webDevelopmentMode: this.state.webDevelopmentMode, showDemoRepos: this.state.showDemoRepos, serverConfiguration: { port: this.state.port, maxArchiveContentCacheCapacityMb: this.state.maxArchiveContentCacheCapacityMb, webDevelopmentMode: this.state.webDevelopmentMode, showDemoRepos: this.state.showDemoRepos, borgCommand: this.state.borgCommand }, borgVersion: { borgCommand: this.state.borgCommand, borgBinary: this.state.borgBinary } };