Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@
<repositories>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.1-R0.1-SNAPSHOT</version>
<version>1.21.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<repositories>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>

Expand All @@ -35,7 +35,7 @@
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.1-R0.1-SNAPSHOT</version>
<version>1.21.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> excludeFiles;
private final List<String> includedFiles;
private final File backupDirectory;
private final File mainDirectory;
private final UploadClient uploadClient;
private final List<UploadClient> uploadClients = new ArrayList<>();
private final long maxBackupDirectorySize;

private final BackupLogger backupLogger;
Expand All @@ -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<Map<?, ?>> 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;
}
}
}

Expand Down Expand Up @@ -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) {
Expand Down
57 changes: 39 additions & 18 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified target/SecureServerBackup-2.0.1.jar
Binary file not shown.
57 changes: 39 additions & 18 deletions target/classes/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file not shown.
Binary file modified target/original-SecureServerBackup-2.0.1.jar
Binary file not shown.
Loading