Skip to content

Commit

Permalink
add Backup size info
Browse files Browse the repository at this point in the history
  • Loading branch information
IndianBartonka committed Oct 21, 2023
1 parent 6463f36 commit 34fa3e0
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/main/java/me/indian/bds/watchdog/module/BackupModule.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.indian.bds.watchdog.module;

import java.io.File;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -135,7 +136,10 @@ public void backup() {
ZipUtil.zipFolder(this.worldPath, backup.getPath());
final double backUpTime = ((System.currentTimeMillis() - startTime) / 1000.0);
this.watchDogConfig.getBackupConfig().setLastBackupTime(backUpTime);
this.serverProcess.tellrawToAllAndLogger(this.prefix, "&aUtworzono kopię zapasową w&b " + backUpTime + "&a sekund", LogState.INFO);
this.serverProcess.tellrawToAllAndLogger(this.prefix,
"&aUtworzono kopię zapasową w&b " + backUpTime + "&a sekund, waży ona " + this.getBackupSize(backup),
LogState.INFO);

this.discord.sendBackupDoneMessage();
this.status = "Utworzono backup";
this.loadAvailableBackups();
Expand Down Expand Up @@ -236,6 +240,19 @@ private void createWorldFile() {
}
}

private String getBackupSize(final File backup) {
long fileSizeBytes;
try {
fileSizeBytes = Files.size(backup.toPath());
} catch (final IOException exception) {
fileSizeBytes = -1;
}
final long gb = MathUtil.bytesToGB(fileSizeBytes);
final long mb = MathUtil.getMbFromBytesGb(fileSizeBytes);
final long kb = MathUtil.getKbFromBytesGb(fileSizeBytes);
return "&b" + gb + "&e GB &b" + mb + "&e MB &b" + kb + "&e KB";
}

public long calculateMillisUntilNextBackup() {
return Math.max(0, MathUtil.minutesToMillis(this.watchDogConfig.getBackupConfig().getBackupFrequency()) - (System.currentTimeMillis() - this.lastBackupMillis));
}
Expand Down

0 comments on commit 34fa3e0

Please sign in to comment.