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

Kai Reinhard
14.52.2019 d46ddab639561a6bdfae72e560bb2b1c4e1dd9bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package de.micromata.borgbutler.config;
 
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import de.micromata.borgbutler.demo.DemoRepos;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import java.io.File;
import java.util.ArrayList;
import java.util.List;
 
public class Configuration {
    private Logger log = LoggerFactory.getLogger(Configuration.class);
    /**
     * Default dir name for restoring archives.
     */
    private static final String RESTORE_DIRNAME = "restore";
 
    @Getter
    private String binariesDownloadUrl = "https://github.com/borgbackup/borg/releases/download/1.1.8/";
    @Getter
    private String[][] borgBinaries = {
            {"freebsd64", "FreeBSD 64"},
            {"linux32", "Linux 32"},
            {"linux64", "Linux 64"},
            {"macosx64", "MacOS X 64"}};
 
    @JsonIgnore
    @Setter(AccessLevel.PACKAGE)
    private File workingDir;
 
    /**
     * One of the values "macosx64", "linux64" etc. for using a binary provided by BorgButler or null / "manual" for
     * using a manual installed borg version.
     */
    @Getter
    private String borgBinary;
    /**
     * The path of the borg command to use.
     */
    @Getter
    @Setter
    private String borgCommand = "borg";
    /**
     * Default is 100 MB (approximately).
     */
    @Getter
    private int maxArchiveContentCacheCapacityMb = 100;
 
    @Getter
    @Setter
    private boolean showDemoRepos = true;
 
    /**
     * Default is restore inside BorgButler's home dir (~/.borgbutler/restore).
     */
    @Getter
    @JsonProperty("restoreDir")
    private String restoreDirPath;
    @JsonIgnore
    private File restoreHomeDir;
 
    private List<BorgRepoConfig> repoConfigs = new ArrayList<>();
 
    public void add(BorgRepoConfig repoConfig) {
        repoConfigs.add(repoConfig);
    }
 
    public BorgRepoConfig getRepoConfig(String idOrName) {
        if (idOrName == null) {
            return null;
        }
        for (BorgRepoConfig repoConfig : getRepoConfigs()) {
            if (StringUtils.equals(idOrName, repoConfig.getRepo()) || StringUtils.equals(idOrName, repoConfig.getId())) {
                return repoConfig;
            }
        }
        return null;
    }
 
    public File getRestoreHomeDir() {
        if (restoreHomeDir == null) {
            if (StringUtils.isNotBlank(restoreDirPath)) {
                restoreHomeDir = new File(restoreDirPath);
            } else {
                restoreHomeDir = new File(workingDir, RESTORE_DIRNAME);
            }
            if (!restoreHomeDir.exists()) {
                log.info("Creating dir '" + restoreHomeDir.getAbsolutePath() + "' for restoring backup files and directories.");
            }
        }
        return restoreHomeDir;
    }
 
    public void copyFrom(Configuration other) {
        this.borgCommand = other.borgCommand;
        this.maxArchiveContentCacheCapacityMb = other.maxArchiveContentCacheCapacityMb;
        this.showDemoRepos = other.showDemoRepos;
    }
 
    public List<BorgRepoConfig> getRepoConfigs() {
        if (!ConfigurationHandler.getConfiguration().isShowDemoRepos()) {
            return repoConfigs;
        }
        List<BorgRepoConfig> result = new ArrayList<>();
        result.addAll(repoConfigs);
        DemoRepos.addDemoRepos(result);
        return result;
    }
 
    List<BorgRepoConfig> _getRepoConfigs() {
        return repoConfigs;
    }
}