11package de .kastenklicker .secureserverbackup ;
22
33import java .io .File ;
4+ import java .util .ArrayList ;
45import java .util .List ;
6+ import java .util .Map ;
7+ import java .util .Objects ;
58
69import de .kastenklicker .secureserverbackuplibrary .Backup ;
710import de .kastenklicker .secureserverbackuplibrary .upload .FTPSClient ;
8- import de .kastenklicker .secureserverbackuplibrary .upload .NullUploadClient ;
911import de .kastenklicker .secureserverbackuplibrary .upload .SFTPClient ;
1012import de .kastenklicker .secureserverbackuplibrary .upload .UploadClient ;
1113import org .bukkit .configuration .file .FileConfiguration ;
1214import org .bukkit .plugin .Plugin ;
1315import org .bukkit .scheduler .BukkitRunnable ;
1416import org .bukkit .scheduler .BukkitWorker ;
17+ import org .jetbrains .annotations .NotNull ;
1518
1619public 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 ) {
0 commit comments