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

Kai Reinhard
29.52.2018 fcb7fffe9ab6b5d08bae9e7dbd703096b567e3d6
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
package de.micromata.borgbutler;
 
import de.micromata.borgbutler.config.BorgRepoConfig;
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;
 
/**
 * Represents a command to be queued for executing.
 */
public class BorgCommand {
    private Logger log = LoggerFactory.getLogger(BorgCommand.class);
 
    @Getter
    @Setter
    private File workingDir;
    @Getter
    private String[] args;
    @Getter
    private String[] params;
    @Getter
    @Setter
    private BorgRepoConfig repoConfig;
    @Getter
    @Setter
    private String command;
    @Getter
    @Setter
    private String archive;
    /**
     * For displaying and information purposes for the user only, when browsing the current command queue.
     */
    @Setter
    @Getter
    private String description;
    /**
     * The result of the call will be written to this String.
     */
    @Getter
    @Setter(AccessLevel.PACKAGE)
    private String response;
 
    BorgCommand setArgs(String... args) {
        this.args = args;
        return this;
    }
 
    BorgCommand setParams(String... params) {
        this.params = params;
        return this;
    }
 
    String getRepoArchive() {
        if (archive == null) {
            if (repoConfig == null) {
                return null;
            }
            return repoConfig.getRepo();
        }
        return repoConfig.getRepo() + "::" + archive;
    }
 
    /**
     *
     * @return Abbreviated response e. g. for logging an error.
     */
    public String getAbbreviatedResponse() {
        return StringUtils.abbreviate(response, 1000);
    }
}