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

...
Kai Reinhard
19.12.2018 3167498290b9b988b8adbafc7a9c5faba73ba833
...
4 files modified
57 ■■■■ changed files
borgbutler-core/src/main/java/de/micromata/borgbutler/BorgCommands.java 47 ●●●● patch | view | raw | blame | history
borgbutler-core/src/main/java/de/micromata/borgbutler/BorgExecutorQueue.java 4 ●●●● patch | view | raw | blame | history
borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java 4 ●●● patch | view | raw | blame | history
borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ArchivesRest.java 2 ●●● patch | view | raw | blame | history
borgbutler-core/src/main/java/de/micromata/borgbutler/BorgCommands.java
@@ -1,7 +1,6 @@
package de.micromata.borgbutler;
import de.micromata.borgbutler.config.BorgRepoConfig;
import de.micromata.borgbutler.config.Definitions;
import de.micromata.borgbutler.data.Archive;
import de.micromata.borgbutler.data.Repository;
import de.micromata.borgbutler.json.JsonUtils;
@@ -21,6 +20,9 @@
import java.util.List;
import java.util.Scanner;
/**
 * Creates and executes  borg commands by calling system's borg application (Borg must be installed).
 */
public class BorgCommands {
    private static Logger log = LoggerFactory.getLogger(BorgCommands.class);
@@ -31,7 +33,11 @@
     * @return Parsed repo config returned by Borg command (without archives).
     */
    public static Repository info(BorgRepoConfig repoConfig) {
        BorgCommand command = new BorgCommand().setRepoConfig(repoConfig).setCommand("info").setParams("--json");
        BorgCommand command = new BorgCommand()
                .setRepoConfig(repoConfig)
                .setCommand("info")
                .setParams("--json")
                .setDescription("Loading info of repo '" + repoConfig.getDisplayName() + "'.");
        execute(command);
        if (command.getResultStatus() != BorgCommand.ResultStatus.OK) {
            return null;
@@ -59,7 +65,11 @@
     * @param repository Repository without archives, archives will be loaded.
     */
    public static void list(BorgRepoConfig repoConfig, Repository repository) {
        BorgCommand command = new BorgCommand().setRepoConfig(repoConfig).setCommand("list").setParams("--json");
        BorgCommand command = new BorgCommand()
                .setRepoConfig(repoConfig)
                .setCommand("list")
                .setParams("--json")
                .setDescription("Loading list of archives of repo '" + repoConfig.getDisplayName() + "'.");
        execute(command);
        if (command.getResultStatus() != BorgCommand.ResultStatus.OK) {
            log.error("Can't load archives from repo '" + repository.getName() + "'.");
@@ -95,8 +105,12 @@
     * @param repository Repository without archives.
     */
    public static void info(BorgRepoConfig repoConfig, Archive archive, Repository repository) {
        BorgCommand command = new BorgCommand().setRepoConfig(repoConfig).setCommand("info").setArchive(archive.getName())
                .setParams("--json");
        BorgCommand command = new BorgCommand()
                .setRepoConfig(repoConfig)
                .setCommand("info")
                .setArchive(archive.getName())
                .setParams("--json")
                .setDescription("Loading info of archive '" + archive.getName() + "' of repo '" + repoConfig.getDisplayName() + "'.");
        execute(command);
        if (command.getResultStatus() != BorgCommand.ResultStatus.OK) {
            return;
@@ -131,9 +145,13 @@
        ;
    }
    public static List<BorgFilesystemItem> listArchiveContent(BorgRepoConfig repoConfig, String archive) {
        BorgCommand command = new BorgCommand().setRepoConfig(repoConfig).setCommand("list").setArchive(archive)
                .setParams("--json-lines");
    public static List<BorgFilesystemItem> listArchiveContent(BorgRepoConfig repoConfig, Archive archive) {
        BorgCommand command = new BorgCommand()
                .setRepoConfig(repoConfig)
                .setCommand("list")
                .setArchive(archive.getName())
                .setParams("--json-lines")
                .setDescription("Loading list of files of archive '" + archive.getName() + "' of repo '" + repoConfig.getDisplayName() + "'.");
        execute(command);
        List<BorgFilesystemItem> content = new ArrayList<>();
        if (command.getResultStatus() != BorgCommand.ResultStatus.OK) {
@@ -161,13 +179,20 @@
     * @return Used sub directory with the restored content.
     * @throws IOException
     */
    public static File extractFiles(File restoreHomeDir, BorgRepoConfig repoConfig, String archive, String path) throws IOException {
    public static File extractFiles(File restoreHomeDir, BorgRepoConfig repoConfig, Archive archive, String path) throws IOException {
        File restoreDir = new File(restoreHomeDir, ReplaceUtils.encodeFilename(repoConfig.getDisplayName(), true));
        if (!restoreDir.exists()) {
            restoreDir.mkdirs();
        }
        BorgCommand command = new BorgCommand().setWorkingDir(restoreDir).setRepoConfig(repoConfig)
                .setCommand("extract").setArchive(archive).setArgs(path);
        BorgCommand command = new BorgCommand()
                .setWorkingDir(restoreDir)
                .setRepoConfig(repoConfig)
                .setCommand("extract")
                .setArchive(archive.getName())
                .setArgs(path)
                .setDescription("Extract content of archive '" + archive.getName()
                                + "' of repo '" + repoConfig.getDisplayName() + "': "
                        + path);
        execute(command);
        return restoreDir;
    }
borgbutler-core/src/main/java/de/micromata/borgbutler/BorgExecutorQueue.java
@@ -83,9 +83,13 @@
        PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
        executor.setStreamHandler(streamHandler);
        String borgCall = cmdLine.getExecutable() + " " + StringUtils.join(cmdLine.getArguments(), " ");
        if (StringUtils.isNotBlank(command.getDescription())) {
            log.info(command.getDescription());
        }
        log.info("Executing '" + borgCall + "'...");
        try {
            executor.execute(cmdLine, getEnvironment(command.getRepoConfig()));
            command.setResultStatus(BorgCommand.ResultStatus.OK);
        } catch (Exception ex) {
            log.error("Error while creating environment for borg call '" + borgCall + "': " + ex.getMessage(), ex);
            command.setResultStatus(BorgCommand.ResultStatus.ERROR);
borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java
@@ -68,8 +68,10 @@
        }
        if (repository == null || repository.getLocation() == null) {
            repository = BorgCommands.info(repoConfig);
            if (repository != null) {
            repoCacheAccess.put(repoConfig.getRepo(), repository);
        }
        }
        if (repository == null) {
            log.warn("Repo with name '" + repoConfig.getRepo() + "' not found.");
        } else {
@@ -262,7 +264,7 @@
        }
        List<BorgFilesystemItem> items = archiveFilelistCache.load(repoConfig, archive, filter);
        if (items == null && forceLoad) {
            List<BorgFilesystemItem> list = BorgCommands.listArchiveContent(repoConfig, archive.getName());
            List<BorgFilesystemItem> list = BorgCommands.listArchiveContent(repoConfig, archive);
            if (CollectionUtils.isNotEmpty(list)) {
                archiveFilelistCache.save(repoConfig, archive, list);
                items = new ArrayList<>();
borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ArchivesRest.java
@@ -120,7 +120,7 @@
        try {
            BorgFilesystemItem item = items.get(0);
            File restoreHomeDir = ConfigurationHandler.getConfiguration().getRestoreHomeDir();
            File restoreDir = BorgCommands.extractFiles(restoreHomeDir, repoConfig, archive.getName(), item.getPath());
            File restoreDir = BorgCommands.extractFiles(restoreHomeDir, repoConfig, archive, item.getPath());
            List<java.nio.file.Path> files = DirUtils.listFiles(restoreDir.toPath());
            if (CollectionUtils.isEmpty(files)) {
                log.error("No files extracted.");