Added toString method to CompressionStatus, version bump to 3.0.0-a, few small tweaks
parent
afe9c8d051
commit
c040d05bd8
|
@ -6,7 +6,7 @@ yarn_mappings=1.19.2+build.28
|
|||
loader_version=0.14.10
|
||||
|
||||
#Fabric api
|
||||
fabric_version=0.64.0+1.19.2
|
||||
fabric_version=0.67.1+1.19.2
|
||||
|
||||
#Cloth Config
|
||||
cloth_version=8.2.88
|
||||
|
@ -21,6 +21,6 @@ lazydfu_version=v0.1.3
|
|||
pgzip_commit_hash=af5f5c297e735f3f2df7aa4eb0e19a5810b8aff6
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 2.5.0
|
||||
mod_version = 3.0.0-a
|
||||
maven_group = net.szum123321
|
||||
archives_base_name = textile_backup
|
|
@ -63,7 +63,7 @@ public class TextileBackup implements ModInitializer {
|
|||
Globals.INSTANCE.updateTMPFSFlag(server);
|
||||
});
|
||||
|
||||
//Wait 60s for already submited backups to finish. After that kill the bastards and run the one last if required
|
||||
//Wait 60s for already submitted backups to finish. After that kill the bastards and run the one last if required
|
||||
ServerLifecycleEvents.SERVER_STOPPED.register(server -> {
|
||||
Globals.INSTANCE.shutdownQueueExecutor(60000);
|
||||
|
||||
|
|
|
@ -22,11 +22,14 @@ import java.io.*;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Map;
|
||||
|
||||
public record CompressionStatus(long treeHash, LocalDateTime date, long startTimestamp, long finishTimestamp, Map<Path, Exception> brokenFiles) implements Serializable {
|
||||
public static final String DATA_FILENAME = "textile_status.data";
|
||||
public boolean isValid(long decompressedHash) { return true; }
|
||||
public boolean isValid(long decompressedHash) {
|
||||
return decompressedHash == treeHash;
|
||||
}
|
||||
|
||||
public static CompressionStatus readFromFile(Path folder) throws IOException, ClassNotFoundException {
|
||||
try(InputStream i = Files.newInputStream(folder.resolve(DATA_FILENAME));
|
||||
|
@ -43,4 +46,31 @@ public record CompressionStatus(long treeHash, LocalDateTime date, long startTim
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Hash: ")
|
||||
.append(treeHash)
|
||||
.append(", Date: ")
|
||||
.append(date.format(DateTimeFormatter.ISO_DATE_TIME))
|
||||
.append(", start time stamp: ").append(startTimestamp)
|
||||
.append(", finish time stamp: ").append(finishTimestamp);
|
||||
|
||||
builder.append(", broken files: ");
|
||||
if(brokenFiles.isEmpty()) builder.append("[]");
|
||||
else {
|
||||
builder.append("[\n");
|
||||
for(Path i: brokenFiles.keySet()) {
|
||||
builder.append(i.toString())
|
||||
.append(":");
|
||||
|
||||
ByteArrayOutputStream o = new ByteArrayOutputStream();
|
||||
brokenFiles.get(i).printStackTrace(new PrintStream(o));
|
||||
builder.append(o).append("\n");
|
||||
}
|
||||
builder.append("]");
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,6 @@ import java.io.IOException;
|
|||
*/
|
||||
public class NoSpaceLeftOnDeviceException extends IOException {
|
||||
public NoSpaceLeftOnDeviceException(Throwable cause) {
|
||||
super(cause);
|
||||
super("The underlying filesystem has ran out of available space.\nSee: https://github.com/Szum123321/textile_backup/wiki/ZIP-Problems", cause);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,11 +51,10 @@ public class MakeBackupRunnable implements Callable<Void> {
|
|||
public MakeBackupRunnable(BackupContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void call() throws IOException, ExecutionException, InterruptedException {
|
||||
Path outFile = Utilities
|
||||
.getBackupRootPath(Utilities.getLevelName(context.server()))
|
||||
.resolve(getFileName());
|
||||
Path outFile = Utilities.getBackupRootPath(Utilities.getLevelName(context.server())).resolve(getFileName());
|
||||
|
||||
log.trace("Outfile is: {}", outFile);
|
||||
|
||||
|
@ -77,11 +76,9 @@ public class MakeBackupRunnable implements Callable<Void> {
|
|||
|
||||
int coreCount;
|
||||
|
||||
if(config.get().compressionCoreCountLimit <= 0) {
|
||||
coreCount = Runtime.getRuntime().availableProcessors();
|
||||
} else {
|
||||
if (config.get().compressionCoreCountLimit <= 0) coreCount = Runtime.getRuntime().availableProcessors();
|
||||
else
|
||||
coreCount = Math.min(config.get().compressionCoreCountLimit, Runtime.getRuntime().availableProcessors());
|
||||
}
|
||||
|
||||
log.trace("Running compression on {} threads. Available cores: {}", coreCount, Runtime.getRuntime().availableProcessors());
|
||||
|
||||
|
@ -107,11 +104,8 @@ public class MakeBackupRunnable implements Callable<Void> {
|
|||
|
||||
Globals.INSTANCE.getQueueExecutor().submit(new Cleanup(context.commandSource(), Utilities.getLevelName(context.server())));
|
||||
|
||||
if(config.get().broadcastBackupDone) {
|
||||
Utilities.notifyPlayers(
|
||||
context.server(),
|
||||
"Done!"
|
||||
);
|
||||
if (config.get().broadcastBackupDone) {
|
||||
Utilities.notifyPlayers(context.server(), "Done!");
|
||||
} else {
|
||||
log.sendInfoAL(context, "Done!");
|
||||
}
|
||||
|
@ -119,7 +113,7 @@ public class MakeBackupRunnable implements Callable<Void> {
|
|||
//ExecutorService swallows exception, so I need to catch everything
|
||||
log.error("An exception occurred when trying to create new backup file!", e);
|
||||
|
||||
if(ConfigHelper.INSTANCE.get().errorErrorHandlingMode.isStrict()) {
|
||||
if (ConfigHelper.INSTANCE.get().errorErrorHandlingMode.isStrict()) {
|
||||
try {
|
||||
Files.delete(outFile);
|
||||
} catch (IOException ex) {
|
||||
|
@ -127,7 +121,7 @@ public class MakeBackupRunnable implements Callable<Void> {
|
|||
}
|
||||
}
|
||||
|
||||
if(context.initiator() == ActionInitiator.Player)
|
||||
if (context.initiator() == ActionInitiator.Player)
|
||||
log.sendError(context, "An exception occurred when trying to create new backup file!");
|
||||
|
||||
throw e;
|
||||
|
@ -139,9 +133,7 @@ public class MakeBackupRunnable implements Callable<Void> {
|
|||
return null;
|
||||
}
|
||||
|
||||
private String getFileName(){
|
||||
return Utilities.getDateTimeFormatter().format(context.startDate()) +
|
||||
(context.comment() != null ? "#" + context.comment().replaceAll("[\\\\/:*?\"<>|#]", "") : "") +
|
||||
config.get().format.getCompleteString();
|
||||
private String getFileName() {
|
||||
return Utilities.getDateTimeFormatter().format(context.startDate()) + (context.comment() != null ? "#" + context.comment().replaceAll("[\\\\/:*?\"<>|#]", "") : "") + config.get().format.getCompleteString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,8 @@ public class RestoreBackupRunnable implements Runnable {
|
|||
|
||||
ctx.server().stop(false);
|
||||
|
||||
Path worldFile = Utilities.getWorldFolder(ctx.server()), tmp;
|
||||
Path worldFile = Utilities.getWorldFolder(ctx.server()),
|
||||
tmp;
|
||||
|
||||
try {
|
||||
tmp = Files.createTempDirectory(
|
||||
|
@ -99,8 +100,11 @@ public class RestoreBackupRunnable implements Runnable {
|
|||
//locks until the backup is finished
|
||||
waitForShutdown.get();
|
||||
|
||||
if(status.isValid(hash) || !config.get().errorErrorHandlingMode.verify()) {
|
||||
if(status.isValid(hash)) log.info("Backup valid. Restoring");
|
||||
log.info("Status: {}", status);
|
||||
|
||||
boolean valid = status.isValid(hash);
|
||||
if(valid || !config.get().errorErrorHandlingMode.verify()) {
|
||||
if(valid) log.info("Backup valid. Restoring");
|
||||
else log.info("Backup is damaged, but verification is disabled. Restoring");
|
||||
|
||||
Utilities.deleteDirectory(worldFile);
|
||||
|
@ -116,7 +120,7 @@ public class RestoreBackupRunnable implements Runnable {
|
|||
} catch (ExecutionException | InterruptedException | ClassNotFoundException | IOException e) {
|
||||
log.error("An exception occurred while trying to restore a backup!", e);
|
||||
} finally {
|
||||
//Regardless of what happended, we shiuld still clean up
|
||||
//Regardless of what happened, we should still clean up
|
||||
if(Files.exists(tmp)) {
|
||||
try {
|
||||
Utilities.deleteDirectory(tmp);
|
||||
|
|
Loading…
Reference in New Issue