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

Kai Reinhard
14.20.2021 5e39c0040ddde260831a5b9f73c0bbfec3738f94
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package de.micromata.borgbutler.data;
 
import de.micromata.borgbutler.config.BorgRepoConfig;
import de.micromata.borgbutler.json.borg.BorgCache;
import de.micromata.borgbutler.json.borg.BorgEncryption;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.SortedSet;
import java.util.TreeSet;
 
/**
 * Part of Borg json objects to refer objects to repositories.
 */
public class Repository implements Serializable {
    private static Logger log = LoggerFactory.getLogger(Repository.class);
    private static final long serialVersionUID = 1278802519434516280L;
    /**
     * The repo configured for borg.
     *
     * @see BorgRepoConfig#getRepo()
     */
    String name;
    /**
     * A name describing this config. Only used for displaying purposes. This is automatically set with the name
     * of the repository configuration.
     *
     * @see BorgRepoConfig#getDisplayName()
     */
    String displayName;
    private String id;
    /**
     * Date given by Borg server.
     */
    private String lastModified;
    /**
     * Last date of getting this object from Borg server.
     */
    private String lastCacheRefresh;
    private String location;
 
    private String securityDir;
    private BorgCache cache;
    private BorgEncryption encryption;
 
    /**
     * Might be null.
     */
    private SortedSet<Archive> archives;
 
    public Repository add(Archive archive) {
        synchronized (this) {
            if (this.archives == null) {
                this.archives = new TreeSet<>();
            }
        }
        synchronized (this.archives) {
            this.archives.add(archive);
        }
        return this;
    }
 
    public Archive getArchive(String idOrName) {
        if (archives == null) {
            log.warn("Can't get archive '" + idOrName + "' from repository '" + name + "'. Archives not yet loaded or don't exist.");
            return null;
        }
        synchronized (this.archives) {
            for (Archive archive : archives) {
                if (StringUtils.equals(idOrName, archive.getId()) || StringUtils.equals(idOrName, archive.getName())) {
                    return archive;
                }
            }
        }
        log.warn("Archive '" + idOrName + "' not found in repository '" + name + "'.");
        return null;
    }
 
    /**
     * Is <tt>borg list repo</tt> already called?
     *
     * @return
     */
    public boolean isArchivesLoaded() {
        return CollectionUtils.isNotEmpty(archives);
    }
 
    public Collection<Archive> getArchives() {
        if (this.archives == null) {
            return null;
        }
        synchronized (this.archives) {
            return Collections.unmodifiableSet(this.archives);
        }
    }
 
    public String getName() {
        return this.name;
    }
 
    public String getDisplayName() {
        return this.displayName;
    }
 
    public String getId() {
        return this.id;
    }
 
    public String getLastModified() {
        return this.lastModified;
    }
 
    public String getLastCacheRefresh() {
        return this.lastCacheRefresh;
    }
 
    public String getLocation() {
        return this.location;
    }
 
    public String getSecurityDir() {
        return this.securityDir;
    }
 
    public BorgCache getCache() {
        return this.cache;
    }
 
    public BorgEncryption getEncryption() {
        return this.encryption;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }
 
    public void setId(String id) {
        this.id = id;
    }
 
    public void setLastModified(String lastModified) {
        this.lastModified = lastModified;
    }
 
    public void setLastCacheRefresh(String lastCacheRefresh) {
        this.lastCacheRefresh = lastCacheRefresh;
    }
 
    public void setLocation(String location) {
        this.location = location;
    }
 
    public void setSecurityDir(String securityDir) {
        this.securityDir = securityDir;
    }
 
    public void setCache(BorgCache cache) {
        this.cache = cache;
    }
 
    public void setEncryption(BorgEncryption encryption) {
        this.encryption = encryption;
    }
 
    public void setArchives(SortedSet<Archive> archives) {
        this.archives = archives;
    }
}