| | |
| | | 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; |
| | |
| | | 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; |
| | | } |
| | |
| | | .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() |
| | |
| | | .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() + "'."); |
| | |
| | | .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."); |
| | |
| | | .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) { |
| | |
| | | .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(); |