Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit d41034a

Browse files
Merge pull request #29 from KastenKlicker/multipleUploadClients
Update Plugin, to support multiple upload servers
2 parents 7d17a7f + 5ec3c59 commit d41034a

8 files changed

Lines changed: 126 additions & 67 deletions

File tree

dependency-reduced-pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@
5757
<repositories>
5858
<repository>
5959
<id>papermc</id>
60-
<url>https://papermc.io/repo/repository/maven-public/</url>
60+
<url>https://repo.papermc.io/repository/maven-public/</url>
6161
</repository>
6262
</repositories>
6363
<dependencies>
6464
<dependency>
6565
<groupId>io.papermc.paper</groupId>
6666
<artifactId>paper-api</artifactId>
67-
<version>1.21.1-R0.1-SNAPSHOT</version>
67+
<version>1.21.4-R0.1-SNAPSHOT</version>
6868
<scope>provided</scope>
6969
</dependency>
7070
</dependencies>

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<repositories>
2727
<repository>
2828
<id>papermc</id>
29-
<url>https://papermc.io/repo/repository/maven-public/</url>
29+
<url>https://repo.papermc.io/repository/maven-public/</url>
3030
</repository>
3131
</repositories>
3232

@@ -35,7 +35,7 @@
3535
<dependency>
3636
<groupId>io.papermc.paper</groupId>
3737
<artifactId>paper-api</artifactId>
38-
<version>1.21.1-R0.1-SNAPSHOT</version>
38+
<version>1.21.4-R0.1-SNAPSHOT</version>
3939
<scope>provided</scope>
4040
</dependency>
4141

src/main/java/de/kastenklicker/secureserverbackup/BackupRunnable.java

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
package de.kastenklicker.secureserverbackup;
22

33
import java.io.File;
4+
import java.util.ArrayList;
45
import java.util.List;
6+
import java.util.Map;
7+
import java.util.Objects;
58

69
import de.kastenklicker.secureserverbackuplibrary.Backup;
710
import de.kastenklicker.secureserverbackuplibrary.upload.FTPSClient;
8-
import de.kastenklicker.secureserverbackuplibrary.upload.NullUploadClient;
911
import de.kastenklicker.secureserverbackuplibrary.upload.SFTPClient;
1012
import de.kastenklicker.secureserverbackuplibrary.upload.UploadClient;
1113
import org.bukkit.configuration.file.FileConfiguration;
1214
import org.bukkit.plugin.Plugin;
1315
import org.bukkit.scheduler.BukkitRunnable;
1416
import org.bukkit.scheduler.BukkitWorker;
17+
import org.jetbrains.annotations.NotNull;
1518

1619
public class BackupRunnable extends BukkitRunnable {
1720

1821
private final List<String> excludeFiles;
22+
private final List<String> includedFiles;
1923
private final File backupDirectory;
2024
private final File mainDirectory;
21-
private final UploadClient uploadClient;
25+
private final List<UploadClient> uploadClients = new ArrayList<>();
2226
private final long maxBackupDirectorySize;
2327

2428
private final BackupLogger backupLogger;
@@ -40,33 +44,46 @@ public BackupRunnable() {
4044

4145
// Get configs
4246
excludeFiles = configuration.getStringList("excludedFiles");
47+
48+
// Exclude session locks, because those are locked by paper
49+
excludeFiles.add("world/session.lock");
50+
excludeFiles.add("world_nether/session.lock");
51+
excludeFiles.add("world_the_end/session.lock");
52+
53+
includedFiles = configuration.getStringList("includedFiles");
54+
if (includedFiles.isEmpty()) {
55+
includedFiles.addAll(List.of(Objects.requireNonNull(mainDirectory.list())));
56+
}
4357
backupDirectory = new File(mainDirectory, configuration.getString("backupFolder", "backups"));
4458
maxBackupDirectorySize = configuration.getLong("maxBackupFolderSize")
4559
* (1000*1000*1000); // KB*MB*GB;
4660

47-
// Get upload information
48-
String hostname = configuration.getString("hostname");
49-
int port = configuration.getInt("port");
50-
String username = configuration.getString("username");
51-
String authentication = configuration.getString("authentication");
52-
String knownHosts = configuration.getString("knownHosts");
53-
int timeout = configuration.getInt("timeout")*1000;
54-
String remoteDirectory = configuration.getString("remoteDirectory");
55-
56-
switch (configuration.getString("uploadProtocol", "")) {
57-
case "sftp":
58-
if (knownHosts == null)
59-
throw new NullPointerException("Read null for knownHosts! Check your config.yml.");
60-
uploadClient = new SFTPClient(hostname, port, username, authentication,
61-
new File(knownHosts), timeout, remoteDirectory);
62-
break;
63-
64-
case "ftps":
65-
uploadClient = new FTPSClient(hostname, port, username, authentication, remoteDirectory);
66-
break;
67-
68-
default:
69-
uploadClient = new NullUploadClient();
61+
@NotNull List<Map<?, ?>> uploadServers = configuration.getMapList("uploadServers");
62+
63+
for (Map<?, ?> uploadServer : uploadServers) {
64+
65+
// Get upload information
66+
String protocol = (String) uploadServer.get("uploadProtocol");
67+
String hostname = (String) uploadServer.get("hostname");
68+
int port = (int) uploadServer.get("port");
69+
String username = (String) uploadServer.get("username");
70+
String authentication = (String) uploadServer.get("authentication");
71+
String knownHosts = (String) uploadServer.get("knownHosts");
72+
int timeout = (int) uploadServer.get("timeout")*1000;
73+
String remoteDirectory = (String) uploadServer.get("remoteDirectory");
74+
75+
switch (protocol) {
76+
case "sftp":
77+
if (knownHosts == null)
78+
throw new NullPointerException("Read null for knownHosts! Check your config.yml.");
79+
uploadClients.add(new SFTPClient(hostname, port, username, authentication,
80+
new File(knownHosts), timeout, remoteDirectory));
81+
break;
82+
83+
case "ftps":
84+
uploadClients.add(new FTPSClient(hostname, port, username, authentication, remoteDirectory));
85+
break;
86+
}
7087
}
7188
}
7289

@@ -98,8 +115,8 @@ public void run() {
98115
}
99116

100117
// Backup files
101-
Backup backup = new Backup(excludeFiles, backupDirectory,
102-
mainDirectory, uploadClient, maxBackupDirectorySize);
118+
Backup backup = new Backup(includedFiles,excludeFiles, backupDirectory,
119+
mainDirectory, uploadClients, maxBackupDirectorySize);
103120
try {
104121
backup.backup();
105122
} catch (Exception e) {

src/main/resources/config.yml

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,46 @@
44
backupFolder: "backups"
55
# Maximum backup size in Gigabyte
66
maxBackupFolderSize: 10
7-
excludeFiles: []
7+
excludeFiles: [] # The backup directory will never be part of the backup
8+
includedFiles: [] # If empty, all files, except the excluded ones, will be included
89
# Upload section
9-
# Possible value sftp, if empty the backup won't be uploaded
10-
uploadProtocol: ""
11-
hostname: ""
12-
port: 22
13-
username: ""
14-
# Password or private RSA Key without password for SFTP
15-
# It's recommended to use a dedicated RSA key pair for SFTP
16-
# Password for FTPS
17-
authentication: ""
18-
# For SFTP only
19-
# Either the path of the knownHosts file or the public host key
20-
# if empty the server will try to scan and the save the public host key at the first connection
21-
knownHosts: "plugins/SecureServerBackup/sftp_hostKey.pub"
22-
# Timeout in seconds
23-
timeout: 20
24-
# Make sure the remote directory already exists
25-
remoteDirectory: "myServerBackups"
10+
uploadServers:
11+
-
12+
# Possible value sftp & ftps if empty the backup won't be uploaded
13+
uploadProtocol: ""
14+
hostname: ""
15+
port: 22
16+
username: ""
17+
# Password or private RSA Key without password for SFTP
18+
# It's recommended to use a dedicated RSA key pair for SFTP
19+
# Password for FTPS
20+
authentication: ""
21+
# For SFTP only
22+
# Either the path of the knownHosts file or the public host key
23+
# if empty the server will try to scan and the save the public host key at the first connection
24+
knownHosts: "plugins/SecureServerBackup/sftp_hostKey.pub"
25+
# Timeout in seconds
26+
timeout: 20
27+
# Make sure the remote directory already exists
28+
remoteDirectory: "myServerBackups"
29+
-
30+
# Possible value sftp & ftps if empty the backup won't be uploaded
31+
uploadProtocol: ""
32+
hostname: ""
33+
port: 22
34+
username: ""
35+
# Password or private RSA Key without password for SFTP
36+
# It's recommended to use a dedicated RSA key pair for SFTP
37+
# Password for FTPS
38+
authentication: ""
39+
# For SFTP only
40+
# Either the path of the knownHosts file or the public host key
41+
# if empty the server will try to scan and the save the public host key at the first connection
42+
knownHosts: "plugins/SecureServerBackup/sftp_hostKey.pub"
43+
# Timeout in seconds
44+
timeout: 20
45+
# Make sure the remote directory already exists
46+
remoteDirectory: "myServerBackups"
2647
# Duration between backups, see more examples at:
2748
# https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/time/Duration.html#parse(java.lang.CharSequence)
2849
# Invalid values will disable autobackup
-2.47 KB
Binary file not shown.

target/classes/config.yml

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,46 @@
44
backupFolder: "backups"
55
# Maximum backup size in Gigabyte
66
maxBackupFolderSize: 10
7-
excludeFiles: []
7+
excludeFiles: [] # The backup directory will never be part of the backup
8+
includedFiles: [] # If empty, the all files will be saved
89
# Upload section
9-
# Possible value sftp, if empty the backup won't be uploaded
10-
uploadProtocol: ""
11-
hostname: ""
12-
port: 22
13-
username: ""
14-
# Password or private RSA Key without password for SFTP
15-
# It's recommended to use a dedicated RSA key pair for SFTP
16-
# Password for FTPS
17-
authentication: ""
18-
# For SFTP only
19-
# Either the path of the knownHosts file or the public host key
20-
# if empty the server will try to scan and the save the public host key at the first connection
21-
knownHosts: "plugins/SecureServerBackup/sftp_hostKey.pub"
22-
# Timeout in seconds
23-
timeout: 20
24-
# Make sure the remote directory already exists
25-
remoteDirectory: "myServerBackups"
10+
uploadServers:
11+
-
12+
# Possible value sftp & ftps if empty the backup won't be uploaded
13+
uploadProtocol: ""
14+
hostname: ""
15+
port: 22
16+
username: ""
17+
# Password or private RSA Key without password for SFTP
18+
# It's recommended to use a dedicated RSA key pair for SFTP
19+
# Password for FTPS
20+
authentication: ""
21+
# For SFTP only
22+
# Either the path of the knownHosts file or the public host key
23+
# if empty the server will try to scan and the save the public host key at the first connection
24+
knownHosts: "plugins/SecureServerBackup/sftp_hostKey.pub"
25+
# Timeout in seconds
26+
timeout: 20
27+
# Make sure the remote directory already exists
28+
remoteDirectory: "myServerBackups"
29+
-
30+
# Possible value sftp & ftps if empty the backup won't be uploaded
31+
uploadProtocol: ""
32+
hostname: ""
33+
port: 22
34+
username: ""
35+
# Password or private RSA Key without password for SFTP
36+
# It's recommended to use a dedicated RSA key pair for SFTP
37+
# Password for FTPS
38+
authentication: ""
39+
# For SFTP only
40+
# Either the path of the knownHosts file or the public host key
41+
# if empty the server will try to scan and the save the public host key at the first connection
42+
knownHosts: "plugins/SecureServerBackup/sftp_hostKey.pub"
43+
# Timeout in seconds
44+
timeout: 20
45+
# Make sure the remote directory already exists
46+
remoteDirectory: "myServerBackups"
2647
# Duration between backups, see more examples at:
2748
# https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/time/Duration.html#parse(java.lang.CharSequence)
2849
# Invalid values will disable autobackup
Binary file not shown.
665 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)