Skip to content

Commit 9926a79

Browse files
committed
Using Borg version 1.1.17 as default. Version is now configurable via web client and json file.
1 parent 32cb86d commit 9926a79

File tree

14 files changed

+137
-102
lines changed

14 files changed

+137
-102
lines changed

borgbutler-core/src/main/kotlin/de/micromata/borgbutler/config/Configuration.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ open class Configuration {
3030
/**
3131
* The borg version to install from github (optional).
3232
*/
33-
// @JsonIgnore needed by client: ConfigurationserverTab.jsx fails otherwise (conflicting borgVersion fields).
34-
@JsonIgnore
3533
var borgVersion: String? = null
3634

3735
/**
@@ -101,6 +99,7 @@ open class Configuration {
10199

102100
fun copyFrom(other: Configuration) {
103101
borgCommand = other.borgCommand
102+
borgVersion = other.borgVersion
104103
maxArchiveContentCacheCapacityMb = other.maxArchiveContentCacheCapacityMb
105104
showDemoRepos = other.showDemoRepos
106105
}
@@ -123,6 +122,10 @@ open class Configuration {
123122
return this
124123
}
125124

125+
override fun toString(): String {
126+
return "borgCommand=[$borgCommand], borgVersion=[$borgVersion], workingDir=[$workingDir], maxArchiveContentCacheCapacityMb=[$maxArchiveContentCacheCapacityMb], showDemoRepos=[$showDemoRepos]"
127+
}
128+
126129
companion object {
127130
/**
128131
* Default dir name for restoring archives.

borgbutler-core/src/test/resources/log4j.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
log4j.rootLogger=info, stdout
2-
log4j.logger.de.micromata.paypal=debug
32

43
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
54
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

borgbutler-server/src/main/java/de/micromata/borgbutler/server/BorgVersion.java renamed to borgbutler-server/src/main/java/de/micromata/borgbutler/server/BorgConfig.java

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
import org.apache.commons.lang3.StringUtils;
44

5-
public class BorgVersion {
6-
public static final String BORG_DEFAULT_DOWNLOAD_VERSION = "1.1.16";
7-
8-
private static final String BORG_VERSION = BORG_DEFAULT_DOWNLOAD_VERSION;
9-
10-
private String binariesDownloadVersion = BORG_DEFAULT_DOWNLOAD_VERSION;
5+
public class BorgConfig {
6+
public static final String BORG_DEFAULT_DOWNLOAD_VERSION = "1.1.17";
117

128
private String[][] borgBinaries = {
139
{"freebsd64", "FreeBSD 64"},
@@ -18,7 +14,7 @@ public class BorgVersion {
1814
private String minimumRequiredBorgVersion = "1.1.8";
1915

2016
public String getBinariesDownloadUrl() {
21-
return "https://github.com/borgbackup/borg/releases/download/" + binariesDownloadVersion + "/";
17+
return "https://github.com/borgbackup/borg/releases/download/" + version + "/";
2218
}
2319

2420
/**
@@ -28,29 +24,17 @@ public String getBinariesDownloadUrl() {
2824
private String borgBinary;
2925

3026
private boolean versionOK = false;
31-
private String version;
27+
private String version = BORG_DEFAULT_DOWNLOAD_VERSION;
3228
private String statusMessage;
3329

34-
public BorgVersion copyFrom(BorgVersion other) {
30+
public BorgConfig copyFrom(BorgConfig other) {
3531
this.borgBinary = other.borgBinary;
3632
this.versionOK = other.versionOK;
3733
this.version = other.version;
3834
this.statusMessage = other.statusMessage;
3935
return this;
4036
}
4137

42-
public String getBinariesDownloadVersion() {
43-
return this.binariesDownloadVersion;
44-
}
45-
46-
public void setBinariesDownloadVersion(String binariesDownloadVersion) {
47-
if (StringUtils.isNotBlank(binariesDownloadVersion)) {
48-
this.binariesDownloadVersion = binariesDownloadVersion;
49-
} else {
50-
this.binariesDownloadVersion = BORG_DEFAULT_DOWNLOAD_VERSION;
51-
}
52-
}
53-
5438
public String[][] getBorgBinaries() {
5539
return this.borgBinaries;
5640
}
@@ -78,22 +62,26 @@ public String getStatusMessage() {
7862
return this.statusMessage;
7963
}
8064

81-
BorgVersion setBorgBinary(String borgBinary) {
65+
BorgConfig setBorgBinary(String borgBinary) {
8266
this.borgBinary = borgBinary;
8367
return this;
8468
}
8569

86-
BorgVersion setVersionOK(boolean versionOK) {
70+
BorgConfig setVersionOK(boolean versionOK) {
8771
this.versionOK = versionOK;
8872
return this;
8973
}
9074

91-
BorgVersion setVersion(String version) {
92-
this.version = version;
75+
BorgConfig setVersion(String version) {
76+
if (StringUtils.isNotBlank(version)) {
77+
this.version = version;
78+
} else {
79+
this.version = BORG_DEFAULT_DOWNLOAD_VERSION;
80+
}
9381
return this;
9482
}
9583

96-
BorgVersion setStatusMessage(String statusMessage) {
84+
BorgConfig setStatusMessage(String statusMessage) {
9785
this.statusMessage = statusMessage;
9886
return this;
9987
}
@@ -125,4 +113,14 @@ public static String[] checkVersion(String version) {
125113
}
126114
return version.split("\\.");
127115
}
116+
117+
@Override
118+
public String toString() {
119+
return "BorgConfig{" +
120+
", borgBinary='" + borgBinary + '\'' +
121+
", versionOK=" + versionOK +
122+
", version='" + version + '\'' +
123+
", statusMessage='" + statusMessage + '\'' +
124+
'}';
125+
}
128126
}

borgbutler-server/src/main/java/de/micromata/borgbutler/server/BorgInstallation.java

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static BorgInstallation getInstance() {
2626
return instance;
2727
}
2828

29-
private BorgVersion borgVersion = new BorgVersion();
29+
private BorgConfig borgConfig = new BorgConfig();
3030

3131
public void initialize() {
3232
Configuration configuration = ConfigurationHandler.getConfiguration();
@@ -35,24 +35,30 @@ public void initialize() {
3535
return;
3636
}
3737
}
38-
borgVersion.setBinariesDownloadVersion(configuration.getBorgVersion());
38+
borgConfig.setVersion(configuration.getBorgVersion());
3939
initialize(getBinary(RunningMode.getOSType()));
40-
if (!borgVersion.isVersionOK()) {
41-
log.warn("No working borg version found. Please configure a borg version with minimal version '" + borgVersion.getMinimumRequiredBorgVersion() + "'.");
40+
if (!borgConfig.isVersionOK()) {
41+
log.warn("No working borg version found. Please configure a borg version with minimal version '" + borgConfig.getMinimumRequiredBorgVersion() + "'.");
4242
}
4343
}
4444

4545
/**
4646
* Configures a new borg configuration if modifications was done.
4747
*
4848
* @param newConfiguration The new configuration with the (new) borg command to use (executable).
49-
* @param borgBinary The id of the borg binary (Mac OS X, Linux 64, manual etc.)
49+
* @param newBorgConfig The new config, including the id of the borg binary (Mac OS X, Linux 64, manual etc.) and version.
5050
*/
51-
public void configure(ServerConfiguration newConfiguration, String borgBinary) {
51+
public void configure(ServerConfiguration newConfiguration, BorgConfig newBorgConfig) {
5252
ServerConfiguration configuration = ServerConfiguration.get();
53-
boolean borgBinaryChanged = !StringUtils.equals(borgVersion.getBorgBinary(), borgBinary);
54-
borgVersion.setBorgBinary(borgBinary); // Update borg binary (if changed).
55-
boolean manualBorgCommand = "manual".equals(borgBinary);
53+
String oldBorgBinary = borgConfig.getBorgBinary();
54+
String oldVersion = borgConfig.getVersion();
55+
String newBorgBinary = newBorgConfig.getBorgBinary();
56+
String newVersion = newConfiguration.getBorgVersion();
57+
boolean borgBinaryChanged = !StringUtils.equals(oldBorgBinary, newBorgBinary) ||
58+
!StringUtils.equals(oldVersion, newVersion);
59+
borgConfig.setBorgBinary(newBorgBinary); // Update borg binary (if changed).
60+
borgConfig.setVersion(newVersion);
61+
boolean manualBorgCommand = "manual".equals( newBorgConfig.getBorgBinary());
5662
if (manualBorgCommand) {
5763
boolean borgCommandChanged = !StringUtils.equals(newConfiguration.getBorgCommand(), configuration.getBorgCommand());
5864
if (borgCommandChanged) {
@@ -61,9 +67,16 @@ public void configure(ServerConfiguration newConfiguration, String borgBinary) {
6167
}
6268
} else {
6369
if (borgBinaryChanged) {
64-
initialize(getBinary(borgBinary));
70+
initialize(getBinary(newBorgBinary));
6571
}
6672
newConfiguration.setBorgCommand(configuration.getBorgCommand()); // borg command of this class overwrites new configuration for mode != 'manual'.
73+
newConfiguration.setBorgVersion(newVersion);
74+
if (!StringUtils.equals(oldVersion, newVersion)) {
75+
log.info("Version '" + oldVersion + "' -> '" + newVersion + "'.");
76+
}
77+
if (!StringUtils.equals(oldBorgBinary, newBorgBinary)) {
78+
log.info("Binary '" + oldBorgBinary + "' -> '" + newBorgBinary + "'.");
79+
}
6780
}
6881
}
6982

@@ -75,17 +88,17 @@ private boolean initialize(String[] binary) {
7588
File file = download(binary);
7689
if (file != null) {
7790
configuration.setBorgCommand(file.getAbsolutePath());
78-
borgVersion.setBorgBinary(binary[0]);
91+
borgConfig.setBorgBinary(binary[0]);
7992
}
8093
return version(configuration);
8194
}
8295

8396
private boolean version(Configuration configuration) {
8497
String borgCommand = configuration.getBorgCommand();
8598
if (StringUtils.isNotBlank(borgCommand)) {
86-
for (String[] borgBinary : borgVersion.getBorgBinaries()) {
99+
for (String[] borgBinary : borgConfig.getBorgBinaries()) {
87100
if (borgCommand.contains(borgBinary[0])) {
88-
borgVersion.setBorgBinary(borgBinary[0]);
101+
borgConfig.setBorgBinary(borgBinary[0]);
89102
break;
90103
}
91104
}
@@ -94,22 +107,22 @@ private boolean version(Configuration configuration) {
94107
boolean versionOK = false;
95108
String msg = null;
96109
if (versionString != null) {
97-
borgVersion.setVersion(versionString);
98-
int cmp = BorgVersion.compareVersions(versionString, borgVersion.getMinimumRequiredBorgVersion());
110+
borgConfig.setVersion(versionString);
111+
int cmp = BorgConfig.compareVersions(versionString, borgConfig.getMinimumRequiredBorgVersion());
99112
if (cmp < 0) {
100-
msg = "Found borg version '" + versionString + "' is less than minimum required version '" + borgVersion.getMinimumRequiredBorgVersion() + "'.";
113+
msg = "Found borg version '" + versionString + "' is less than minimum required version '" + borgConfig.getMinimumRequiredBorgVersion() + "'.";
101114
log.info(msg);
102115
} else {
103116
versionOK = true;
104-
msg = "Found borg '" + configuration.getBorgCommand() + "', version: " + versionString + " (equals to or newer than '" + borgVersion.getMinimumRequiredBorgVersion()
117+
msg = "Found borg '" + configuration.getBorgCommand() + "', version: " + versionString + " (equals to or newer than '" + borgConfig.getMinimumRequiredBorgVersion()
105118
+ "', OK).";
106119
log.info(msg);
107120
}
108121
} else {
109122
msg = "Couldn't execute borg command '" + configuration.getBorgCommand() + "'.";
110123
}
111-
borgVersion.setVersionOK(versionOK);
112-
borgVersion.setStatusMessage(msg);
124+
borgConfig.setVersionOK(versionOK);
125+
borgConfig.setStatusMessage(msg);
113126
return versionOK;
114127
}
115128

@@ -133,7 +146,7 @@ private String[] getBinary(String os) {
133146
if (os == null) {
134147
return null;
135148
}
136-
for (String[] binary : borgVersion.getBorgBinaries()) {
149+
for (String[] binary : borgConfig.getBorgBinaries()) {
137150
if (binary[0].contains(os)) {
138151
return binary;
139152
}
@@ -156,7 +169,7 @@ private File download(String[] binary) {
156169
// File already downloaded, nothing to do.
157170
return file;
158171
}
159-
String url = borgVersion.getBinariesDownloadUrl() + getDownloadFilename(binary);
172+
String url = borgConfig.getBinariesDownloadUrl() + getDownloadFilename(binary);
160173
log.info("Trying to download borg binary '" + binary[0] + "' (" + binary[1] + ") from url: " + url + "...");
161174
HttpClientBuilder builder = HttpClients.custom()
162175
.setDefaultRequestConfig(RequestConfig.custom()
@@ -186,7 +199,7 @@ private File getBinaryFile(String[] binary) {
186199
log.info("Creating binary directory: " + dir.getAbsolutePath());
187200
dir.mkdirs();
188201
}
189-
return new File(dir, getDownloadFilename(binary) + "-" + borgVersion.getBinariesDownloadVersion());
202+
return new File(dir, getDownloadFilename(binary) + "-" + borgConfig.getVersion());
190203
}
191204

192205
private String getDownloadFilename(String[] binary) {
@@ -196,7 +209,7 @@ private String getDownloadFilename(String[] binary) {
196209
private BorgInstallation() {
197210
}
198211

199-
public BorgVersion getBorgVersion() {
200-
return this.borgVersion;
212+
public BorgConfig getBorgConfig() {
213+
return this.borgConfig;
201214
}
202215
}

borgbutler-server/src/main/kotlin/de/micromata/borgbutler/server/ServerConfiguration.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class ServerConfiguration : Configuration() {
2020
webDevelopmentMode = other.webDevelopmentMode
2121
}
2222

23+
override fun toString(): String {
24+
return "${super.toString()}, port=[$port], webDevelopmentMode=[$webDevelopmentMode]"
25+
}
26+
2327
companion object {
2428
val supportedLanguages = arrayOf("en", "de")
2529
const val WEBSERVER_PORT_DEFAULT = 9042
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package de.micromata.borgbutler.server.rest
22

3-
import de.micromata.borgbutler.server.BorgVersion
3+
import de.micromata.borgbutler.server.BorgConfig
44
import de.micromata.borgbutler.server.ServerConfiguration
55

66
class ConfigurationInfo(
77
var serverConfiguration: ServerConfiguration? = null,
8-
var borgVersion: BorgVersion? = null
8+
var borgConfig: BorgConfig? = null
99
)

borgbutler-server/src/main/kotlin/de/micromata/borgbutler/server/rest/ConfigurationRest.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ package de.micromata.borgbutler.server.rest
22

33
import de.micromata.borgbutler.cache.ButlerCache
44
import de.micromata.borgbutler.config.ConfigurationHandler
5-
import de.micromata.borgbutler.json.JsonUtils
65
import de.micromata.borgbutler.server.BorgInstallation
76
import de.micromata.borgbutler.server.ServerConfiguration
87
import de.micromata.borgbutler.server.user.UserData
98
import de.micromata.borgbutler.server.user.UserManager
109
import mu.KotlinLogging
11-
import org.apache.commons.lang3.StringUtils
1210
import org.springframework.web.bind.annotation.*
1311

1412
private val log = KotlinLogging.logger {}
@@ -21,19 +19,19 @@ class ConfigurationRest {
2119
fun getConfig(): ConfigurationInfo {
2220
val configurationInfo = ConfigurationInfo()
2321
configurationInfo.serverConfiguration = ServerConfiguration.get()
24-
configurationInfo.borgVersion = BorgInstallation.getInstance().borgVersion
22+
configurationInfo.borgConfig = BorgInstallation.getInstance().borgConfig
2523
return configurationInfo
2624
}
2725

2826
@PostMapping("config")
2927
fun setConfig(@RequestBody configurationInfo: ConfigurationInfo) {
30-
val configurationHandler = ConfigurationHandler.getInstance()
31-
BorgInstallation.getInstance()
32-
.configure(configurationInfo.serverConfiguration, configurationInfo.borgVersion?.borgBinary)
28+
log.info("server-config: ${configurationInfo.serverConfiguration}, borg-binary: ${configurationInfo.borgConfig?.borgBinary}")
29+
BorgInstallation.getInstance().configure(configurationInfo.serverConfiguration, configurationInfo.borgConfig)
3330
val configuration: ServerConfiguration = ServerConfiguration.get()
3431
configurationInfo.serverConfiguration?.let {
3532
configuration.copyFrom(it)
3633
}
34+
val configurationHandler = ConfigurationHandler.getInstance()
3735
configurationHandler.save()
3836
}
3937

borgbutler-server/src/main/kotlin/de/micromata/borgbutler/server/rest/SystemInfo.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package de.micromata.borgbutler.server.rest
22

33
import de.micromata.borgbutler.BorgQueueStatistics
4-
import de.micromata.borgbutler.server.BorgVersion
4+
import de.micromata.borgbutler.server.BorgConfig
55

66
/**
77
* Statistics of all the job queues, especially the number of total queued and running jobs.
@@ -13,7 +13,7 @@ class SystemInfo {
1313
private set
1414
var configurationOK = false
1515
private set
16-
var borgVersion: BorgVersion? = null
16+
var borgConfig: BorgConfig? = null
1717
private set
1818

1919
fun setQueueStatistics(queueStatistics: BorgQueueStatistics?): SystemInfo {
@@ -26,8 +26,8 @@ class SystemInfo {
2626
return this
2727
}
2828

29-
fun setBorgVersion(borgVersion: BorgVersion?): SystemInfo {
30-
this.borgVersion = borgVersion
29+
fun setBorgConfig(borgConfig: BorgConfig?): SystemInfo {
30+
this.borgConfig = borgConfig
3131
return this
3232
}
3333
}

borgbutler-server/src/main/kotlin/de/micromata/borgbutler/server/rest/SystemInfoRest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class SystemInfoRest {
1616
*/
1717
@GetMapping("info")
1818
fun statistics(): SystemInfo {
19-
val borgVersion = BorgInstallation.getInstance().borgVersion
20-
val systemInfonfo = SystemInfo()
19+
val borgConfig = BorgInstallation.getInstance().borgConfig
20+
val systemInfo = SystemInfo()
2121
.setQueueStatistics(BorgQueueExecutor.getInstance().statistics)
22-
.setConfigurationOK(borgVersion.isVersionOK)
23-
.setBorgVersion(borgVersion)
24-
return systemInfonfo
22+
.setConfigurationOK(borgConfig.isVersionOK)
23+
.setBorgConfig(borgConfig)
24+
return systemInfo
2525
}
2626
}

0 commit comments

Comments
 (0)