Skip to content

Commit

Permalink
Added backup compression setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxMaeder committed Sep 20, 2020
1 parent 1e08cdf commit 04184a3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
10 changes: 10 additions & 0 deletions DriveBackup/src/main/java/ratismal/drivebackup/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Config {
private static int backupThreadPriority;
private static int keepCount;
private static int localKeepCount;
private static int zipCompression;
private static boolean backupsRequirePlayers;

private static boolean scheduleBackups;
Expand Down Expand Up @@ -89,6 +90,7 @@ public void reload() {
backupThreadPriority = config.getInt("backup-thread-priority");
keepCount = config.getInt("keep-count");
localKeepCount = config.getInt("local-keep-count");
zipCompression = config.getInt("zip-compression");
backupsRequirePlayers = config.getBoolean("backups-require-players");

scheduleBackups = config.getBoolean("scheduled-backups");
Expand Down Expand Up @@ -267,6 +269,14 @@ public static int getLocalKeepCount() {
return localKeepCount;
}

/**
* Gets the compression level of the backup zips
* @return the compression level
*/
public static int getZipCompression() {
return zipCompression;
}

/**
* Gets whether backups shouldn't run if no new player activity has occurred
* @return whether to run if no new activity has occurred
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.regex.Pattern;
import java.util.zip.Deflater;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

Expand Down Expand Up @@ -171,6 +172,7 @@ private static void zipIt(String inputFolderPath, String outputFilePath) throws
try {
fileOutputStream = new FileOutputStream(outputFilePath);
zipOutputStream = new ZipOutputStream(fileOutputStream);
zipOutputStream.setLevel(Config.getZipCompression());

for (String file : fileList) {
zipOutputStream.putNextEntry(new ZipEntry(formattedInputFolderPath + File.separator + file));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okio.Buffer;

public class HttpLogger implements Interceptor {
private static final MediaType jsonMediaType = MediaType.parse("application/json; charset=utf-8");

@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request request = chain.request();
Expand All @@ -18,11 +23,26 @@ public Response intercept(Interceptor.Chain chain) throws IOException {
Response response = chain.proceed(request);

long t2 = System.nanoTime();
MessageUtil.sendConsoleMessage(String.format("Received response for %s in %.1fms%n%s", response.request().url(),
(t2 - t1) / 1e6d, response.headers()));

MessageUtil.sendConsoleMessage(response.body().string());

return response;
MessageUtil.sendConsoleMessage(String.format("Received response for %s in %.1fms%n%s", response.request().url(), (t2 - t1) / 1e6d, response.headers()));

try {
if (request.body().contentType().equals(jsonMediaType)) {
final Buffer requestBody = new Buffer();
request.body().writeTo(requestBody);
MessageUtil.sendConsoleMessage("req: " + requestBody.readUtf8());
} else {
MessageUtil.sendConsoleMessage("req: not JSON");
}
} catch (Exception exception) {
MessageUtil.sendConsoleMessage("req: none");
}

ResponseBody responseBody = response.body();
String responseBodyString = responseBody.string();
MediaType responseBodyContentType = responseBody.contentType();
responseBody.close();
MessageUtil.sendConsoleMessage("res: " + responseBodyString);

return response.newBuilder().body(ResponseBody.create(responseBodyContentType, responseBodyString)).build();
}
}
3 changes: 1 addition & 2 deletions DriveBackup/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ delay: 60
backup-thread-priority: 0
keep-count: 20
local-keep-count: 0

zip-compression: -1
backups-require-players: true
restart-after-backup: false

scheduled-backups: false
schedule-timezone: "-00:00"
Expand Down

0 comments on commit 04184a3

Please sign in to comment.