diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index c9ce7ff..4471236 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -57,14 +57,14 @@ papermc - https://papermc.io/repo/repository/maven-public/ + https://repo.papermc.io/repository/maven-public/ io.papermc.paper paper-api - 1.21.1-R0.1-SNAPSHOT + 1.21.4-R0.1-SNAPSHOT provided diff --git a/pom.xml b/pom.xml index 41fffcc..5159e2a 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ papermc - https://papermc.io/repo/repository/maven-public/ + https://repo.papermc.io/repository/maven-public/ @@ -35,7 +35,7 @@ io.papermc.paper paper-api - 1.21.1-R0.1-SNAPSHOT + 1.21.4-R0.1-SNAPSHOT provided diff --git a/src/main/java/de/kastenklicker/secureserverbackup/BackupRunnable.java b/src/main/java/de/kastenklicker/secureserverbackup/BackupRunnable.java index 973f0dc..4cb2565 100644 --- a/src/main/java/de/kastenklicker/secureserverbackup/BackupRunnable.java +++ b/src/main/java/de/kastenklicker/secureserverbackup/BackupRunnable.java @@ -1,24 +1,28 @@ package de.kastenklicker.secureserverbackup; import java.io.File; +import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.Objects; import de.kastenklicker.secureserverbackuplibrary.Backup; import de.kastenklicker.secureserverbackuplibrary.upload.FTPSClient; -import de.kastenklicker.secureserverbackuplibrary.upload.NullUploadClient; import de.kastenklicker.secureserverbackuplibrary.upload.SFTPClient; import de.kastenklicker.secureserverbackuplibrary.upload.UploadClient; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitWorker; +import org.jetbrains.annotations.NotNull; public class BackupRunnable extends BukkitRunnable { private final List excludeFiles; + private final List includedFiles; private final File backupDirectory; private final File mainDirectory; - private final UploadClient uploadClient; + private final List uploadClients = new ArrayList<>(); private final long maxBackupDirectorySize; private final BackupLogger backupLogger; @@ -40,33 +44,46 @@ public BackupRunnable() { // Get configs excludeFiles = configuration.getStringList("excludedFiles"); + + // Exclude session locks, because those are locked by paper + excludeFiles.add("world/session.lock"); + excludeFiles.add("world_nether/session.lock"); + excludeFiles.add("world_the_end/session.lock"); + + includedFiles = configuration.getStringList("includedFiles"); + if (includedFiles.isEmpty()) { + includedFiles.addAll(List.of(Objects.requireNonNull(mainDirectory.list()))); + } backupDirectory = new File(mainDirectory, configuration.getString("backupFolder", "backups")); maxBackupDirectorySize = configuration.getLong("maxBackupFolderSize") * (1000*1000*1000); // KB*MB*GB; - // Get upload information - String hostname = configuration.getString("hostname"); - int port = configuration.getInt("port"); - String username = configuration.getString("username"); - String authentication = configuration.getString("authentication"); - String knownHosts = configuration.getString("knownHosts"); - int timeout = configuration.getInt("timeout")*1000; - String remoteDirectory = configuration.getString("remoteDirectory"); - - switch (configuration.getString("uploadProtocol", "")) { - case "sftp": - if (knownHosts == null) - throw new NullPointerException("Read null for knownHosts! Check your config.yml."); - uploadClient = new SFTPClient(hostname, port, username, authentication, - new File(knownHosts), timeout, remoteDirectory); - break; - - case "ftps": - uploadClient = new FTPSClient(hostname, port, username, authentication, remoteDirectory); - break; - - default: - uploadClient = new NullUploadClient(); + @NotNull List> uploadServers = configuration.getMapList("uploadServers"); + + for (Map uploadServer : uploadServers) { + + // Get upload information + String protocol = (String) uploadServer.get("uploadProtocol"); + String hostname = (String) uploadServer.get("hostname"); + int port = (int) uploadServer.get("port"); + String username = (String) uploadServer.get("username"); + String authentication = (String) uploadServer.get("authentication"); + String knownHosts = (String) uploadServer.get("knownHosts"); + int timeout = (int) uploadServer.get("timeout")*1000; + String remoteDirectory = (String) uploadServer.get("remoteDirectory"); + + switch (protocol) { + case "sftp": + if (knownHosts == null) + throw new NullPointerException("Read null for knownHosts! Check your config.yml."); + uploadClients.add(new SFTPClient(hostname, port, username, authentication, + new File(knownHosts), timeout, remoteDirectory)); + break; + + case "ftps": + uploadClients.add(new FTPSClient(hostname, port, username, authentication, remoteDirectory)); + break; + } } } @@ -98,8 +115,8 @@ public void run() { } // Backup files - Backup backup = new Backup(excludeFiles, backupDirectory, - mainDirectory, uploadClient, maxBackupDirectorySize); + Backup backup = new Backup(includedFiles,excludeFiles, backupDirectory, + mainDirectory, uploadClients, maxBackupDirectorySize); try { backup.backup(); } catch (Exception e) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 31d77a6..c85c563 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -4,25 +4,46 @@ backupFolder: "backups" # Maximum backup size in Gigabyte maxBackupFolderSize: 10 -excludeFiles: [] +excludeFiles: [] # The backup directory will never be part of the backup +includedFiles: [] # If empty, all files, except the excluded ones, will be included # Upload section -# Possible value sftp, if empty the backup won't be uploaded -uploadProtocol: "" -hostname: "" -port: 22 -username: "" -# Password or private RSA Key without password for SFTP -# It's recommended to use a dedicated RSA key pair for SFTP -# Password for FTPS -authentication: "" -# For SFTP only -# Either the path of the knownHosts file or the public host key -# if empty the server will try to scan and the save the public host key at the first connection -knownHosts: "plugins/SecureServerBackup/sftp_hostKey.pub" -# Timeout in seconds -timeout: 20 -# Make sure the remote directory already exists -remoteDirectory: "myServerBackups" +uploadServers: + - + # Possible value sftp & ftps if empty the backup won't be uploaded + uploadProtocol: "" + hostname: "" + port: 22 + username: "" + # Password or private RSA Key without password for SFTP + # It's recommended to use a dedicated RSA key pair for SFTP + # Password for FTPS + authentication: "" + # For SFTP only + # Either the path of the knownHosts file or the public host key + # if empty the server will try to scan and the save the public host key at the first connection + knownHosts: "plugins/SecureServerBackup/sftp_hostKey.pub" + # Timeout in seconds + timeout: 20 + # Make sure the remote directory already exists + remoteDirectory: "myServerBackups" + - + # Possible value sftp & ftps if empty the backup won't be uploaded + uploadProtocol: "" + hostname: "" + port: 22 + username: "" + # Password or private RSA Key without password for SFTP + # It's recommended to use a dedicated RSA key pair for SFTP + # Password for FTPS + authentication: "" + # For SFTP only + # Either the path of the knownHosts file or the public host key + # if empty the server will try to scan and the save the public host key at the first connection + knownHosts: "plugins/SecureServerBackup/sftp_hostKey.pub" + # Timeout in seconds + timeout: 20 + # Make sure the remote directory already exists + remoteDirectory: "myServerBackups" # Duration between backups, see more examples at: # https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/time/Duration.html#parse(java.lang.CharSequence) # Invalid values will disable autobackup diff --git a/target/SecureServerBackup-2.0.1.jar b/target/SecureServerBackup-2.0.1.jar index 59e7179..f7b8ee6 100644 Binary files a/target/SecureServerBackup-2.0.1.jar and b/target/SecureServerBackup-2.0.1.jar differ diff --git a/target/classes/config.yml b/target/classes/config.yml index 31d77a6..77ce4d3 100644 --- a/target/classes/config.yml +++ b/target/classes/config.yml @@ -4,25 +4,46 @@ backupFolder: "backups" # Maximum backup size in Gigabyte maxBackupFolderSize: 10 -excludeFiles: [] +excludeFiles: [] # The backup directory will never be part of the backup +includedFiles: [] # If empty, the all files will be saved # Upload section -# Possible value sftp, if empty the backup won't be uploaded -uploadProtocol: "" -hostname: "" -port: 22 -username: "" -# Password or private RSA Key without password for SFTP -# It's recommended to use a dedicated RSA key pair for SFTP -# Password for FTPS -authentication: "" -# For SFTP only -# Either the path of the knownHosts file or the public host key -# if empty the server will try to scan and the save the public host key at the first connection -knownHosts: "plugins/SecureServerBackup/sftp_hostKey.pub" -# Timeout in seconds -timeout: 20 -# Make sure the remote directory already exists -remoteDirectory: "myServerBackups" +uploadServers: + - + # Possible value sftp & ftps if empty the backup won't be uploaded + uploadProtocol: "" + hostname: "" + port: 22 + username: "" + # Password or private RSA Key without password for SFTP + # It's recommended to use a dedicated RSA key pair for SFTP + # Password for FTPS + authentication: "" + # For SFTP only + # Either the path of the knownHosts file or the public host key + # if empty the server will try to scan and the save the public host key at the first connection + knownHosts: "plugins/SecureServerBackup/sftp_hostKey.pub" + # Timeout in seconds + timeout: 20 + # Make sure the remote directory already exists + remoteDirectory: "myServerBackups" + - + # Possible value sftp & ftps if empty the backup won't be uploaded + uploadProtocol: "" + hostname: "" + port: 22 + username: "" + # Password or private RSA Key without password for SFTP + # It's recommended to use a dedicated RSA key pair for SFTP + # Password for FTPS + authentication: "" + # For SFTP only + # Either the path of the knownHosts file or the public host key + # if empty the server will try to scan and the save the public host key at the first connection + knownHosts: "plugins/SecureServerBackup/sftp_hostKey.pub" + # Timeout in seconds + timeout: 20 + # Make sure the remote directory already exists + remoteDirectory: "myServerBackups" # Duration between backups, see more examples at: # https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/time/Duration.html#parse(java.lang.CharSequence) # Invalid values will disable autobackup diff --git a/target/classes/de/kastenklicker/secureserverbackup/BackupRunnable.class b/target/classes/de/kastenklicker/secureserverbackup/BackupRunnable.class index 92d2fae..c9106c0 100644 Binary files a/target/classes/de/kastenklicker/secureserverbackup/BackupRunnable.class and b/target/classes/de/kastenklicker/secureserverbackup/BackupRunnable.class differ diff --git a/target/original-SecureServerBackup-2.0.1.jar b/target/original-SecureServerBackup-2.0.1.jar index 0ae293d..6916286 100644 Binary files a/target/original-SecureServerBackup-2.0.1.jar and b/target/original-SecureServerBackup-2.0.1.jar differ