mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
29.22.2018 cdd5a70a92a808d063f32f1454e3584165beab53
borgbutler-core/src/main/java/de/micromata/borgbutler/BorgCommands.java
@@ -3,6 +3,7 @@
import de.micromata.borgbutler.config.BorgRepoConfig;
import de.micromata.borgbutler.data.Archive;
import de.micromata.borgbutler.data.Repository;
import de.micromata.borgbutler.jobs.JobResult;
import de.micromata.borgbutler.json.JsonUtils;
import de.micromata.borgbutler.json.borg.*;
import de.micromata.borgbutler.utils.DateUtils;
@@ -35,10 +36,11 @@
        BorgCommand command = new BorgCommand()
                .setParams("--version")
                .setDescription("Getting borg version.");
        String version = execute(command).getResult();
        if (command.getResultStatus() != BorgCommand.ResultStatus.OK) {
        JobResult<String> jobResult = execute(command).getResult();
        if (jobResult.getStatus() != JobResult.Status.OK) {
            return null;
        }
        String version = jobResult.getResultObject();
        log.info("Borg version: " + version);
        return version;
    }
@@ -55,10 +57,11 @@
                .setCommand("info")
                .setParams("--json")
                .setDescription("Loading info of repo '" + repoConfig.getDisplayName() + "'.");
        String result = execute(command).getResult();
        if (command.getResultStatus() != BorgCommand.ResultStatus.OK) {
        JobResult<String> jobResult = execute(command).getResult();
        if (jobResult.getStatus() != JobResult.Status.OK) {
            return null;
        }
        String result = jobResult.getResultObject();
        BorgRepoInfo repoInfo = JsonUtils.fromJson(BorgRepoInfo.class, result);
        BorgRepository borgRepository = repoInfo.getRepository();
        Repository repository = new Repository()
@@ -87,11 +90,12 @@
                .setCommand("list")
                .setParams("--json")
                .setDescription("Loading list of archives of repo '" + repoConfig.getDisplayName() + "'.");
        String result = execute(command).getResult();
        if (command.getResultStatus() != BorgCommand.ResultStatus.OK) {
        JobResult<String> jobResult = execute(command).getResult();
        if (jobResult.getStatus() != JobResult.Status.OK) {
            log.error("Can't load archives from repo '" + repository.getName() + "'.");
            return;
        }
        String result = jobResult.getResultObject();
        BorgRepoList repoList = JsonUtils.fromJson(BorgRepoList.class, result);
        if (repoList == null || CollectionUtils.isEmpty(repoList.getArchives())) {
            log.error("Can't load archives from repo '" + repository.getName() + "'.");
@@ -128,10 +132,11 @@
                .setArchive(archive.getName())
                .setParams("--json")
                .setDescription("Loading info of archive '" + archive.getName() + "' of repo '" + repoConfig.getDisplayName() + "'.");
        String result = execute(command).getResult();
        if (command.getResultStatus() != BorgCommand.ResultStatus.OK) {
        JobResult<String> jobResult = execute(command).getResult();
        if (jobResult.getStatus() != JobResult.Status.OK) {
            return;
        }
        String result = jobResult.getResultObject();
        BorgArchiveInfo archiveInfo = JsonUtils.fromJson(BorgArchiveInfo.class, result);
        if (archiveInfo == null) {
            log.error("Archive '" + command.getRepoArchive() + "' not found.");
@@ -158,8 +163,7 @@
                .setHostname(borgArchive.getHostname())
                .setUsername(borgArchive.getUsername())
                .setEnd(DateUtils.format(borgArchive.getEnd()))
                .setDuration(borgArchive.getDuration())
        ;
                .setDuration(borgArchive.getDuration());
    }
    public static List<BorgFilesystemItem> listArchiveContent(BorgRepoConfig repoConfig, Archive archive) {
@@ -169,11 +173,12 @@
                .setArchive(archive.getName())
                .setParams("--json-lines")
                .setDescription("Loading list of files of archive '" + archive.getName() + "' of repo '" + repoConfig.getDisplayName() + "'.");
        String result = execute(command).getResult();
        List<BorgFilesystemItem> content = new ArrayList<>();
        if (command.getResultStatus() != BorgCommand.ResultStatus.OK) {
        JobResult<String> jobResult = execute(command).getResult();
        if (jobResult.getStatus() != JobResult.Status.OK) {
            return content;
        }
        String result = jobResult.getResultObject();
        try (Scanner scanner = new Scanner(result)) {
            while (scanner.hasNextLine()) {
                String json = scanner.nextLine();