fixes lmao
This commit is contained in:
parent
75e95e8430
commit
37f64392da
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -34,7 +34,7 @@ public class TaskBuilder {
|
|||
new SimpleDateFormat(
|
||||
getTaskConfig().getStringOrDefault("general.dateFormat", "yyyy-MM-dd HH-mm-ss"));
|
||||
String fileName =
|
||||
getTaskConfig().getStringOrDefault("filesystem.fileName", "{date} {taskName}") + ".zip";
|
||||
getTaskConfig().getStringOrDefault("filesystem.fileName", "{date} - {taskName}") + ".zip";
|
||||
|
||||
fileName =
|
||||
fileName
|
||||
|
@ -68,5 +68,9 @@ public class TaskBuilder {
|
|||
private void executeNextTask() {
|
||||
Task nextTask = taskList.poll();
|
||||
if (nextTask != null) nextTask.start();
|
||||
else {
|
||||
System.out.println("Backup completed!");
|
||||
System.out.println(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package net.horizoncode.sysbackup.tasks.impl;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import net.horizoncode.sysbackup.tasks.Task;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@Getter
|
||||
public class DatabaseTask extends Task {
|
||||
|
||||
private final DatabaseCredentials databaseCredentials;
|
||||
|
||||
private final File outputFile;
|
||||
|
||||
public DatabaseTask(DatabaseCredentials credentials, File outputFile) {
|
||||
this.databaseCredentials = credentials;
|
||||
this.outputFile = outputFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
try {
|
||||
String[] commandArgs =
|
||||
new String[] {
|
||||
"mysqldump",
|
||||
"-u " + getDatabaseCredentials().username,
|
||||
"-p" + new String(getDatabaseCredentials().password),
|
||||
getDatabaseCredentials().database
|
||||
};
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
Process process = runtime.exec(commandArgs);
|
||||
|
||||
InputStream inputStream = process.getInputStream();
|
||||
FileUtils.copyInputStreamToFile(
|
||||
inputStream,
|
||||
new File(
|
||||
outputFile.getParent(),
|
||||
String.format(
|
||||
"%s-%s.sql",
|
||||
getDatabaseCredentials().database, RandomStringUtils.random(16, true, true))));
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Builder
|
||||
private static class DatabaseCredentials {
|
||||
private final String username;
|
||||
private final char[] password;
|
||||
private final String database;
|
||||
}
|
||||
}
|
|
@ -3,12 +3,16 @@ package net.horizoncode.sysbackup.tasks.impl;
|
|||
import me.tongfei.progressbar.ProgressBar;
|
||||
import me.tongfei.progressbar.ProgressBarBuilder;
|
||||
import me.tongfei.progressbar.ProgressBarStyle;
|
||||
import me.tongfei.progressbar.TerminalUtils;
|
||||
import net.horizoncode.sysbackup.tasks.Task;
|
||||
import net.horizoncode.sysbackup.threading.ThreadPool;
|
||||
import net.lingala.zip4j.ZipFile;
|
||||
import net.lingala.zip4j.progress.ProgressMonitor;
|
||||
import org.jline.terminal.Terminal;
|
||||
import org.jline.terminal.TerminalBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class FileSystemTask extends Task {
|
||||
|
@ -37,6 +41,16 @@ public class FileSystemTask extends Task {
|
|||
.getPool()
|
||||
.submit(
|
||||
() -> {
|
||||
int terminalWidth = -1;
|
||||
try {
|
||||
Terminal terminal = TerminalBuilder.terminal();
|
||||
try (terminal) {
|
||||
terminalWidth = terminal.getWidth();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try (ZipFile zipFile = new ZipFile(outputZipFile)) {
|
||||
System.out.println("Indexing files...");
|
||||
ProgressMonitor progressMonitor = zipFile.getProgressMonitor();
|
||||
|
@ -47,10 +61,13 @@ public class FileSystemTask extends Task {
|
|||
.setStyle(ProgressBarStyle.ASCII)
|
||||
.setInitialMax(progressMonitor.getTotalWork())
|
||||
.setTaskName("Adding Files...");
|
||||
|
||||
if (terminalWidth != -1) pbb.setMaxRenderedLength(terminalWidth);
|
||||
|
||||
try (ProgressBar pb = pbb.build()) {
|
||||
while (!progressMonitor.getState().equals(ProgressMonitor.State.READY)) {
|
||||
pb.stepTo(progressMonitor.getWorkCompleted());
|
||||
Thread.sleep(1);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
pb.stepTo(progressMonitor.getTotalWork());
|
||||
} catch (Exception exception) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user