File -> RestoreableFile
parent
870f133273
commit
6f9e98f104
|
@ -24,9 +24,7 @@ import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.szum123321.textile_backup.Statics;
|
import net.szum123321.textile_backup.Statics;
|
||||||
import net.szum123321.textile_backup.core.restore.RestoreHelper;
|
import net.szum123321.textile_backup.core.restore.RestoreHelper;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.*;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ListBackupsCommand {
|
public class ListBackupsCommand {
|
||||||
public static LiteralArgumentBuilder<ServerCommandSource> register() {
|
public static LiteralArgumentBuilder<ServerCommandSource> register() {
|
||||||
|
@ -40,7 +38,7 @@ public class ListBackupsCommand {
|
||||||
builder.append("There is only one backup available: ");
|
builder.append("There is only one backup available: ");
|
||||||
builder.append(backups.get(0).toString());
|
builder.append(backups.get(0).toString());
|
||||||
} else {
|
} else {
|
||||||
backups.sort(Comparator.comparing(RestoreHelper.RestoreableFile::getCreationTime));
|
backups.sort(null);
|
||||||
Iterator<RestoreHelper.RestoreableFile> iterator = backups.iterator();
|
Iterator<RestoreHelper.RestoreableFile> iterator = backups.iterator();
|
||||||
builder.append("Available backups: ");
|
builder.append("Available backups: ");
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ import net.minecraft.text.LiteralText;
|
||||||
import net.szum123321.textile_backup.Statics;
|
import net.szum123321.textile_backup.Statics;
|
||||||
import net.szum123321.textile_backup.core.restore.RestoreHelper;
|
import net.szum123321.textile_backup.core.restore.RestoreHelper;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeParseException;
|
import java.time.format.DateTimeParseException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -88,10 +87,10 @@ public class RestoreBackupCommand {
|
||||||
throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message);
|
throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<File> backupFile = RestoreHelper.findFileAndLockIfPresent(dateTime, source.getMinecraftServer());
|
Optional<RestoreHelper.RestoreableFile> backupFile = RestoreHelper.findFileAndLockIfPresent(dateTime, source.getMinecraftServer());
|
||||||
|
|
||||||
if(backupFile.isPresent()) {
|
if(backupFile.isPresent()) {
|
||||||
Statics.LOGGER.info("Found file to restore {}", backupFile.get().getName());
|
Statics.LOGGER.info("Found file to restore {}", backupFile.get().getFile().getName());
|
||||||
} else {
|
} else {
|
||||||
Statics.LOGGER.sendInfo(source, "No file created on {} was found!", dateTime.format(Statics.defaultDateTimeFormatter));
|
Statics.LOGGER.sendInfo(source, "No file created on {} was found!", dateTime.format(Statics.defaultDateTimeFormatter));
|
||||||
|
|
||||||
|
|
|
@ -29,14 +29,13 @@ import net.szum123321.textile_backup.core.restore.decompressors.GenericTarDecomp
|
||||||
import net.szum123321.textile_backup.core.restore.decompressors.ZipDecompressor;
|
import net.szum123321.textile_backup.core.restore.decompressors.ZipDecompressor;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
|
|
||||||
public class RestoreBackupRunnable implements Runnable {
|
public class RestoreBackupRunnable implements Runnable {
|
||||||
private final MinecraftServer server;
|
private final MinecraftServer server;
|
||||||
private final File backupFile;
|
private final RestoreHelper.RestoreableFile backupFile;
|
||||||
private final String finalBackupComment;
|
private final String finalBackupComment;
|
||||||
|
|
||||||
public RestoreBackupRunnable(MinecraftServer server, File backupFile, String finalBackupComment) {
|
public RestoreBackupRunnable(MinecraftServer server, RestoreHelper.RestoreableFile backupFile, String finalBackupComment) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.backupFile = backupFile;
|
this.backupFile = backupFile;
|
||||||
this.finalBackupComment = finalBackupComment;
|
this.finalBackupComment = finalBackupComment;
|
||||||
|
@ -45,6 +44,7 @@ public class RestoreBackupRunnable implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Statics.LOGGER.info("Shutting down server...");
|
Statics.LOGGER.info("Shutting down server...");
|
||||||
|
|
||||||
server.stop(false);
|
server.stop(false);
|
||||||
awaitServerShutdown();
|
awaitServerShutdown();
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@ public class RestoreBackupRunnable implements Runnable {
|
||||||
File worldFile = Utilities.getWorldFolder(server);
|
File worldFile = Utilities.getWorldFolder(server);
|
||||||
|
|
||||||
Statics.LOGGER.info("Deleting old world...");
|
Statics.LOGGER.info("Deleting old world...");
|
||||||
|
|
||||||
if(!deleteDirectory(worldFile))
|
if(!deleteDirectory(worldFile))
|
||||||
Statics.LOGGER.error("Something went wrong while deleting old world!");
|
Statics.LOGGER.error("Something went wrong while deleting old world!");
|
||||||
|
|
||||||
|
@ -68,16 +69,15 @@ public class RestoreBackupRunnable implements Runnable {
|
||||||
|
|
||||||
Statics.LOGGER.info("Starting decompression...");
|
Statics.LOGGER.info("Starting decompression...");
|
||||||
|
|
||||||
if(Utilities.getFileExtension(backupFile).orElseThrow(() -> new NoSuchElementException("Couldn't get file extension!")) == ConfigHandler.ArchiveFormat.ZIP) {
|
if(backupFile.getArchiveFormat() == ConfigHandler.ArchiveFormat.ZIP)
|
||||||
ZipDecompressor.decompress(backupFile, worldFile);
|
ZipDecompressor.decompress(backupFile.getFile(), worldFile);
|
||||||
} else {
|
else
|
||||||
GenericTarDecompressor.decompress(backupFile, worldFile);
|
GenericTarDecompressor.decompress(backupFile.getFile(), worldFile);
|
||||||
}
|
|
||||||
|
|
||||||
if(Statics.CONFIG.deleteOldBackupAfterRestore) {
|
if(Statics.CONFIG.deleteOldBackupAfterRestore) {
|
||||||
Statics.LOGGER.info("Deleting old backup");
|
Statics.LOGGER.info("Deleting old backup");
|
||||||
|
|
||||||
if(!backupFile.delete())
|
if(!backupFile.getFile().delete())
|
||||||
Statics.LOGGER.info("Something went wrong while deleting old backup");
|
Statics.LOGGER.info("Something went wrong while deleting old backup");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue