Skip to content
Open
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
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.hierynomus</groupId>
<artifactId>sshj</artifactId>
<version>0.38.0</version>
</dependency>

</dependencies>

Expand Down
13 changes: 11 additions & 2 deletions src/net/server_backup/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public static void loadConfig() {
+ "\nBackupLimiter - Type '0' to disable this feature. If you don't type '0' the feature 'DeleteOldBackups' will be disabled and this feature ('BackupLimiter') will be enabled."
+ "\nKeepUniqueBackups - Type 'true' to disable the deletion of unique backups. The plugin will keep the newest backup of all backed up worlds or folders, no matter how old it is."
+ "\nBlacklist - A list of files/directories that will not be backed up."
+ "\nIMPORTANT FTP information: Set 'UploadBackup' to 'true' if you want to store your backups on a ftp server (sftp does not work at the moment - if you host your own server (e.g. vps/root server) you need to set up a ftp server on it)."
+ "\nIf you use ftp backups, you can set 'DeleteLocalBackup' to 'true' if you want the plugin to remove the created backup from your server once it has been uploaded to your ftp server."
+ "\nSet 'UploadBackup' to 'true' if you want to store your backups on a ftp/sftp server."
+ "\nIf you use ftp/sftp backups, you can set 'DeleteLocalBackup' to 'true' if you want the plugin to remove the created backup from your server once it has been uploaded to your ftp/sftp server."
+ "\nCompressBeforeUpload compresses the backup to a zip file before uploading it. Set it to 'false' if you want the files to be uploaded directly to your ftp server."
+ "\nJoin the discord server if you need help or have a question: https://discord.gg/rNzngsCWFC");
ServerBackup.getInstance().getConfig().options().copyDefaults(true);
Expand Down Expand Up @@ -119,6 +119,15 @@ public static void loadConfig() {
ServerBackup.getInstance().getConfig().addDefault("Ftp.Server.Password", "password");
ServerBackup.getInstance().getConfig().addDefault("Ftp.Server.BackupDirectory", "Backups/");

ServerBackup.getInstance().getConfig().addDefault("Sftp.UploadBackup", false);
ServerBackup.getInstance().getConfig().addDefault("Sftp.DeleteLocalBackup", false);
ServerBackup.getInstance().getConfig().addDefault("Sftp.Server.IP", "127.0.0.1");
ServerBackup.getInstance().getConfig().addDefault("Sftp.Server.Port", 21);
ServerBackup.getInstance().getConfig().addDefault("Sftp.Server.User", "username");
ServerBackup.getInstance().getConfig().addDefault("Sftp.Server.Password", "password");
ServerBackup.getInstance().getConfig().addDefault("Sftp.Server.Fingerprint", "SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
ServerBackup.getInstance().getConfig().addDefault("Sftp.Server.BackupDirectory", "Backups/");

ServerBackup.getInstance().getConfig().addDefault("DynamicBackup", false);
ServerBackup.getInstance().getConfig().addDefault("SendLogMessages", false);

Expand Down
10 changes: 10 additions & 0 deletions src/net/server_backup/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public static void loadMessages() {
messages.addDefault("Info.FtpUploadSuccess", "Ftp: Upload successfully. Backup stored on ftp server.");
messages.addDefault("Info.FtpDownload", "Ftp: Downloading backup [%file%] ...");
messages.addDefault("Info.FtpDownloadSuccess", "Ftp: Download successful. Backup downloaded from ftp server.");
messages.addDefault("Info.SftpUpload", "Sftp: Uploading backup [%file%] ...");
messages.addDefault("Info.SftpUploadSuccess", "Sftp: Upload successfully. Backup stored on sftp server.");
messages.addDefault("Info.SftpDownload", "Sftp: Downloading backup [%file%] ...");
messages.addDefault("Info.SftpDownloadSuccess", "Sftp: Download successful. Backup downloaded from sftp server.");

messages.addDefault("Error.NoPermission", "&cI'm sorry but you do not have permission to perform this command.");
messages.addDefault("Error.NoBackups", "No backups found.");
Expand All @@ -49,6 +53,7 @@ public static void loadMessages() {
messages.addDefault("Error.FolderExists", "There is already a folder named '%file%'.");
messages.addDefault("Error.ZipExists", "There is already a ZIP file named '%file%.zip'.");
messages.addDefault("Error.NoFtpBackups", "No ftp backups found.");
messages.addDefault("Error.NoSftpBackups", "No sftp backups found.");
messages.addDefault("Error.NoTasks", "No backup tasks are running.");
messages.addDefault("Error.AlreadyZip", "%file% is already a ZIP file.");
messages.addDefault("Error.NotAZip", "%file% is not a ZIP file.");
Expand All @@ -59,6 +64,11 @@ public static void loadMessages() {
messages.addDefault("Error.FtpLocalDeletionFailed", "Ftp: Local backup deletion failed because the uploaded file was not found on the ftp server. Try again.");
messages.addDefault("Error.FtpNotFound", "Ftp: ftp-backup %file% not found.");
messages.addDefault("Error.FtpConnectionFailed", "Ftp: Error while connecting to FTP server.");
messages.addDefault("Error.SftpUploadFailed", "Sftp: Error while uploading backup to sftp server. Check server details in config.yml (ip, port, user, password).");
messages.addDefault("Error.SftpDownloadFailed", "Sftp: Error while downloading backup to sftp server. Check server details in config.yml (ip, port, user, password).");
messages.addDefault("Error.SftpLocalDeletionFailed", "Sftp: Local backup deletion failed because the uploaded file was not found on the sftp server. Try again.");
messages.addDefault("Error.SftpNotFound", "Sftp: sftp-backup %file% not found.");
messages.addDefault("Error.SftpConnectionFailed", "Sftp: Error while connecting to SFTP server.");

Configuration.saveMessages();

Expand Down
91 changes: 91 additions & 0 deletions src/net/server_backup/commands/CommandSftp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package net.server_backup.commands;

import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.server_backup.ServerBackup;
import net.server_backup.core.OperationHandler;
import net.server_backup.utils.SftpManager;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;

public class CommandSftp {

public static void execute(CommandSender sender, String[] args) {
if (args[1].equalsIgnoreCase("list")) {
Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> {
SftpManager sftpm = new SftpManager(sender);

List<String> backups = sftpm.getSftpBackupList(false);

if (backups.size() == 0) {
sender.sendMessage(OperationHandler.processMessage("Error.NoSftpBackups"));

return;
}

try {
int page = Integer.valueOf(args[2]);

if (backups.size() < page * 10 - 9) {
sender.sendMessage("Try a lower value.");

return;
}

if (backups.size() <= page * 10 && backups.size() >= page * 10 - 10) {
sender.sendMessage("----- Sftp-Backup " + Integer.valueOf(page * 10 - 9) + "-"
+ backups.size() + "/" + backups.size() + " -----");
} else {
sender.sendMessage("----- Sftp-Backup " + Integer.valueOf(page * 10 - 9) + "-"
+ Integer.valueOf(page * 10) + "/" + backups.size() + " -----");
}
sender.sendMessage("");

for (int i = page * 10 - 10; i < backups.size() && i < page * 10; i++) {
if (sender instanceof Player) {
Player p = (Player) sender;

TextComponent msg = new TextComponent(backups.get(i));
msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new ComponentBuilder("Click to get Backup name").create()));
msg.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND,
backups.get(i).split(" ")[1]));

p.spigot().sendMessage(msg);
} else {
sender.sendMessage(backups.get(i));
}
}

int maxPages = backups.size() / 10;

if (backups.size() % 10 != 0) {
maxPages++;
}

sender.sendMessage("");
sender.sendMessage("--------- Page " + page + "/" + maxPages + " ---------");
} catch (Exception e) {
sender.sendMessage(OperationHandler.processMessage("Error.NotANumber").replaceAll("%input%", args[1]));
}
});
} else if (args[1].equalsIgnoreCase("download")) {
Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> {
SftpManager sftpm = new SftpManager(sender);

sftpm.downloadFileFromSftp(args[2]);
});
} else if (args[1].equalsIgnoreCase("upload")) {
Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> {
SftpManager sftpm = new SftpManager(sender);

sftpm.uploadFileToSftp(args[2], !ServerBackup.getInstance().getConfig().getBoolean("Sftp.CompressBeforeUpload"));
});
}
}
}
8 changes: 8 additions & 0 deletions src/net/server_backup/commands/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (args[1].equalsIgnoreCase("list")) {
Bukkit.dispatchCommand(sender, "backup ftp list 1");
}
} else if (args[0].equalsIgnoreCase("sftp")) {
if (args[1].equalsIgnoreCase("list")) {
Bukkit.dispatchCommand(sender, "backup sftp list 1");
}
} else if (args[0].equalsIgnoreCase("zip")) {
CommandZip.execute(sender, args);
} else if (args[0].equalsIgnoreCase("unzip")) {
Expand All @@ -54,6 +58,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
CommandSearch.execute(sender, args);
} else if (args[0].equalsIgnoreCase("ftp")) {
CommandFtp.execute(sender, args);
} else if (args[0].equalsIgnoreCase("sftp")) {
CommandSftp.execute(sender, args);
} else if (args[0].equalsIgnoreCase("dropbox")) {
CommandDropbox.execute(sender, args);
}
Expand Down Expand Up @@ -85,6 +91,8 @@ private void sendHelp(CommandSender sender) {
sender.sendMessage("");
sender.sendMessage("/backup ftp <download/upload/list> - download, upload or list ftp backup files");
sender.sendMessage("");
sender.sendMessage("/backup sftp <download/upload/list> - download, upload or list sftp backup files");
sender.sendMessage("");
sender.sendMessage("/backup dropbox upload <file> - upload a backup to dropbox");
sender.sendMessage("");
sender.sendMessage("/backup shutdown - shut downs the server after backup tasks are finished");
Expand Down
25 changes: 25 additions & 0 deletions src/net/server_backup/commands/TabCompleter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.server_backup.Configuration;
import net.server_backup.utils.FtpManager;
import net.server_backup.utils.SftpManager;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command;
Expand Down Expand Up @@ -30,6 +31,7 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String labe
commands.add("zip");
commands.add("unzip");
commands.add("ftp");
commands.add("sftp");
commands.add("dropbox");
commands.add("tasks");
commands.add("shutdown");
Expand Down Expand Up @@ -82,6 +84,10 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String labe
commands.add("list");
commands.add("download");
commands.add("upload");
} else if (args[0].equalsIgnoreCase("sftp")) {
commands.add("list");
commands.add("download");
commands.add("upload");
} else if (args[0].equalsIgnoreCase("dropbox")) {
commands.add("upload");
}
Expand All @@ -107,6 +113,25 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String labe
}
}

} else if (args[0].equalsIgnoreCase("sftp")) {
if (args[1].equalsIgnoreCase("download")) {
SftpManager sftpm = new SftpManager(sender);

List<String> backups = sftpm.getSftpBackupList(false);

for (String backup : backups) {
commands.add(backup.split(" ")[1]);
}
} else if (args[1].equalsIgnoreCase("upload")) {
File[] backups = new File(Configuration.backupDestination + "").listFiles();

for (File backup : backups) {
if (backup.getName().endsWith(".zip")) {
commands.add(backup.getName());
}
}
}

} else if (args[0].equalsIgnoreCase("dropbox")) {
File[] backups = new File(Configuration.backupDestination + "").listFiles();

Expand Down
6 changes: 6 additions & 0 deletions src/net/server_backup/core/ZipManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.server_backup.ServerBackup;
import net.server_backup.utils.DropboxManager;
import net.server_backup.utils.FtpManager;
import net.server_backup.utils.SftpManager;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -179,6 +180,11 @@ public void zip() throws IOException {
ftpm.uploadFileToFtp(targetFilePath, false);
}

if (ServerBackup.getInstance().getConfig().getBoolean("Sftp.UploadBackup")) {
SftpManager sftpm = new SftpManager(sender);
sftpm.uploadFileToSftp(targetFilePath, false);
}

if (ServerBackup.getInstance().getConfig().getBoolean("CloudBackup.Dropbox")) {
DropboxManager dm = new DropboxManager(sender);
dm.uploadToDropbox(targetFilePath);
Expand Down
Loading