summaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
authorKeuin <[email protected]>2021-02-15 18:13:44 +0800
committerKeuin <[email protected]>2021-02-15 18:13:44 +0800
commitb171d46ce07a9ed9a426779fcff92dd1f56b3dd1 (patch)
tree3df106d0000c12a7749fd24e28d2fde69983ae39 /src/main/java/com
parent6d6f0b486ac42b6bd69ddb8862ee3af7b819f3a7 (diff)
Minor bugfix: incremental backup without `backups` directory created will fail.
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/autobackup/AutoBackupDispatcher.java (renamed from src/main/java/com/keuin/kbackupfabric/autobackup/AutoBackupScheduler.java)6
-rw-r--r--src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncCopyResult.java48
-rw-r--r--src/main/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethod.java13
3 files changed, 37 insertions, 30 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/autobackup/AutoBackupScheduler.java b/src/main/java/com/keuin/kbackupfabric/autobackup/AutoBackupDispatcher.java
index c35a35d..32d626e 100644
--- a/src/main/java/com/keuin/kbackupfabric/autobackup/AutoBackupScheduler.java
+++ b/src/main/java/com/keuin/kbackupfabric/autobackup/AutoBackupDispatcher.java
@@ -5,14 +5,14 @@ import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Logger;
-public class AutoBackupScheduler {
+public class AutoBackupDispatcher {
private Timer timer = null;
- private final Logger logger = Logger.getLogger(AutoBackupScheduler.class.getName());
+ private final Logger logger = Logger.getLogger(AutoBackupDispatcher.class.getName());
private boolean skipIfNoPlayerLoggedIn;
private final PlayerActivityTracker playerActivityTracker;
- public AutoBackupScheduler(int intervalSeconds, boolean skipIfNoPlayerLoggedIn, PlayerActivityTracker playerActivityTracker) {
+ public AutoBackupDispatcher(int intervalSeconds, boolean skipIfNoPlayerLoggedIn, PlayerActivityTracker playerActivityTracker) {
this.skipIfNoPlayerLoggedIn = skipIfNoPlayerLoggedIn;
this.playerActivityTracker = playerActivityTracker;
if (intervalSeconds > 0)
diff --git a/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncCopyResult.java b/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncCopyResult.java
index 6661a27..3323348 100644
--- a/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncCopyResult.java
+++ b/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncCopyResult.java
@@ -11,17 +11,17 @@ import java.util.Objects;
public class IncCopyResult {
private final int totalFiles;
- private final int filesCopied;
- private final long bytesCopied;
- private final long bytesTotal;
+ private final int copiedFiles;
+ private final long copiedBytes;
+ private final long totalBytes;
public static final IncCopyResult ZERO = new IncCopyResult(0, 0, 0, 0);
- public IncCopyResult(int totalFiles, int filesCopied, long bytesCopied, long bytesTotal) {
+ public IncCopyResult(int totalFiles, int copiedFiles, long copiedBytes, long totalBytes) {
this.totalFiles = totalFiles;
- this.filesCopied = filesCopied;
- this.bytesCopied = bytesCopied;
- this.bytesTotal = bytesTotal;
+ this.copiedFiles = copiedFiles;
+ this.copiedBytes = copiedBytes;
+ this.totalBytes = totalBytes;
}
/**
@@ -38,8 +38,8 @@ public class IncCopyResult {
*
* @return file count.
*/
- public int getFilesCopied() {
- return filesCopied;
+ public int getCopiedFiles() {
+ return copiedFiles;
}
/**
@@ -47,8 +47,8 @@ public class IncCopyResult {
*
* @return bytes.
*/
- public long getBytesCopied() {
- return bytesCopied;
+ public long getCopiedBytes() {
+ return copiedBytes;
}
/**
@@ -56,8 +56,8 @@ public class IncCopyResult {
*
* @return bytes.
*/
- public long getBytesTotal() {
- return bytesTotal;
+ public long getTotalBytes() {
+ return totalBytes;
}
/**
@@ -70,9 +70,9 @@ public class IncCopyResult {
Objects.requireNonNull(a);
return new IncCopyResult(
totalFiles + a.totalFiles,
- filesCopied + a.filesCopied,
- bytesCopied + a.bytesCopied,
- bytesTotal + a.bytesTotal
+ copiedFiles + a.copiedFiles,
+ copiedBytes + a.copiedBytes,
+ totalBytes + a.totalBytes
);
}
@@ -82,25 +82,25 @@ public class IncCopyResult {
if (o == null || getClass() != o.getClass()) return false;
IncCopyResult that = (IncCopyResult) o;
return totalFiles == that.totalFiles &&
- filesCopied == that.filesCopied &&
- bytesCopied == that.bytesCopied &&
- bytesTotal == that.bytesTotal;
+ copiedFiles == that.copiedFiles &&
+ copiedBytes == that.copiedBytes &&
+ totalBytes == that.totalBytes;
}
@Override
public int hashCode() {
- return Objects.hash(totalFiles, filesCopied, bytesCopied, bytesTotal);
+ return Objects.hash(totalFiles, copiedFiles, copiedBytes, totalBytes);
}
@Override
public String toString() {
return String.format(
"File(s) added: %d (%s in size, totally %d files). Total backup-ed files size: %s (%.2f%% reused)",
- filesCopied,
- BackupFilesystemUtil.getFriendlyFileSizeString(bytesCopied),
+ copiedFiles,
+ BackupFilesystemUtil.getFriendlyFileSizeString(copiedBytes),
totalFiles,
- BackupFilesystemUtil.getFriendlyFileSizeString(bytesTotal),
- (1 - 1.0f * bytesCopied / bytesTotal) * 100
+ BackupFilesystemUtil.getFriendlyFileSizeString(totalBytes),
+ (1 - 1.0f * copiedBytes / totalBytes) * 100
);
}
}
diff --git a/src/main/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethod.java b/src/main/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethod.java
index 5fe532a..0c202e1 100644
--- a/src/main/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethod.java
+++ b/src/main/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethod.java
@@ -75,6 +75,13 @@ public class ConfiguredIncrementalBackupMethod implements ConfiguredBackupMethod
// legacy index file
// ObjectCollectionSerializer.toFile(collection, new File(backupIndexFileSaveDirectory, backupIndexFileName));
+ // create directory
+ final File indexDirectoryFile = new File(backupIndexFileSaveDirectory);
+ if (indexDirectoryFile.isFile())
+ throw new IOException("There is a file which has the same name with index directory");
+ if (!indexDirectoryFile.isDirectory() && !indexDirectoryFile.mkdirs())
+ throw new IOException("Backup index save directory does not exist and we failed to create it");
+
// newer saved info (with metadata)
File indexFile = new File(backupIndexFileSaveDirectory, backupIndexFileName);
BackupFileNameEncoder.BackupBasicInformation info = IncrementalBackupFileNameEncoder.INSTANCE.decode(backupIndexFileName);
@@ -82,9 +89,9 @@ public class ConfiguredIncrementalBackupMethod implements ConfiguredBackupMethod
collection,
info.customName,
info.time.atZone(ZoneId.systemDefault()),
- copyResult.getBytesTotal(),
- copyResult.getBytesCopied(),
- copyResult.getFilesCopied(),
+ copyResult.getTotalBytes(),
+ copyResult.getCopiedBytes(),
+ copyResult.getCopiedFiles(),
copyResult.getTotalFiles()
));