Backup manager update : improved code handling file filtering + refactored PaperBackupManager + new Bungee backup manager
This commit is contained in:
@@ -27,6 +27,12 @@
|
||||
<version>${bungeecord.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>fr.pandacube.lib</groupId>
|
||||
<artifactId>pandalib-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -0,0 +1,16 @@
|
||||
package fr.pandacube.lib.bungee.backup;
|
||||
|
||||
import fr.pandacube.lib.core.backup.BackupCleaner;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BungeeBackupConfig {
|
||||
public boolean workdirBackupEnabled = true;
|
||||
public boolean logsBackupEnabled = true;
|
||||
public String scheduling = "0 2 * * *"; // cron format, here is everyday at 2am
|
||||
public File backupDirectory = null;
|
||||
public BackupCleaner workdirBackupCleaner = BackupCleaner.KEEPING_1_EVERY_N_MONTH(3).merge(BackupCleaner.KEEPING_N_LAST(5));
|
||||
public List<String> workdirIgnoreList = new ArrayList<>();
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
package fr.pandacube.lib.bungee.backup;
|
||||
|
||||
import fr.pandacube.lib.core.backup.BackupManager;
|
||||
import fr.pandacube.lib.core.backup.BackupProcess;
|
||||
import fr.pandacube.lib.core.backup.RotatedLogsBackupProcess;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class BungeeBackupManager extends BackupManager {
|
||||
|
||||
BungeeBackupConfig config;
|
||||
|
||||
public BungeeBackupManager(BungeeBackupConfig config) {
|
||||
super(config.backupDirectory);
|
||||
setConfig(config);
|
||||
|
||||
addProcess(new BungeeWorkdirProcess(this));
|
||||
addProcess(new RotatedLogsBackupProcess(this, false, new File("logs"), "[0-9]{4}-[0-9]{2}-[0-9]{2}(-[0-9]+)?\\.log\\.gz"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addProcess(BackupProcess process) {
|
||||
updateProcessConfig(process);
|
||||
super.addProcess(process);
|
||||
}
|
||||
|
||||
public void setConfig(BungeeBackupConfig config) {
|
||||
this.config = config;
|
||||
backupQueue.forEach(this::updateProcessConfig);
|
||||
}
|
||||
|
||||
|
||||
public void updateProcessConfig(BackupProcess process) {
|
||||
if (process instanceof BungeeWorkdirProcess) {
|
||||
process.setEnabled(config.workdirBackupEnabled);
|
||||
process.setBackupCleaner(config.workdirBackupCleaner);
|
||||
process.setScheduling(config.scheduling);
|
||||
process.setIgnoreList(config.workdirIgnoreList);
|
||||
}
|
||||
else if (process instanceof RotatedLogsBackupProcess) {
|
||||
process.setEnabled(config.logsBackupEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
package fr.pandacube.lib.bungee.backup;
|
||||
|
||||
import fr.pandacube.lib.core.backup.BackupProcess;
|
||||
import fr.pandacube.lib.util.Log;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
public class BungeeWorkdirProcess extends BackupProcess {
|
||||
|
||||
protected BungeeWorkdirProcess(BungeeBackupManager bm) {
|
||||
super(bm, "workdir");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BungeeBackupManager getBackupManager() {
|
||||
return (BungeeBackupManager) super.getBackupManager();
|
||||
}
|
||||
|
||||
|
||||
public BiPredicate<File, String> getFilenameFilter() {
|
||||
return new BiPredicate<File, String>() {
|
||||
@Override
|
||||
public boolean test(File file, String path) {
|
||||
if (new File(getSourceDir(), "logs").equals(file))
|
||||
return false;
|
||||
if (file.isFile() && file.getName().endsWith(".lck"))
|
||||
return false;
|
||||
return BungeeWorkdirProcess.super.getFilenameFilter().test(file, path);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public File getSourceDir() {
|
||||
return new File(".");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBackupStart() { }
|
||||
|
||||
@Override
|
||||
protected void onBackupEnd(boolean success) {
|
||||
if (success)
|
||||
setDirtySinceNow();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected File getTargetDir() {
|
||||
return new File(getBackupManager().getBackupDirectory(), "workdir");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDisplayName() {
|
||||
return "workdir";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void displayNextSchedule() {
|
||||
Log.info("[Backup] " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET + " next backup on "
|
||||
+ DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(new Date(getNext())));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user