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

Kai Reinhard
10.31.2018 0fd7e38f2abf6064907449fcb1ee10be75e62cd2
JCS started.
2 files added
2 files modified
94 ■■■■■ changed files
borgbutler-core/build.gradle 2 ●●●●● patch | view | raw | blame | history
borgbutler-core/src/main/java/de/micromata/borgbutler/config/Configuration.java 7 ●●●●● patch | view | raw | blame | history
borgbutler-core/src/main/java/de/micromata/borgbutler/jcs/JCSCache.java 42 ●●●●● patch | view | raw | blame | history
borgbutler-core/src/main/resources/jcs-basic-config.properties 43 ●●●●● patch | view | raw | blame | history
borgbutler-core/build.gradle
@@ -11,6 +11,8 @@
    compile group: 'org.apache.commons', name: 'commons-exec', version: '1.3'
    compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.2'
    compile group: 'org.apache.commons', name: 'commons-compress', version: '1.18'
    compile group: 'org.apache.commons', name: 'commons-jcs-core', version: '2.2.1'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.6'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.9.6'
borgbutler-core/src/main/java/de/micromata/borgbutler/config/Configuration.java
@@ -9,6 +9,13 @@
public class Configuration {
    @Getter
    private String borgCommand = "borg";
    /**
     * Default is 200 MB (approximately).
     */
    @Getter
    @JsonProperty("cache_max_disc_size_mb")
    private int cacheMaxDiscSizeMB = 200;
    @Getter
    @JsonProperty("repo-configs")
    private List<BorgRepoConfig> repoConfigs = new ArrayList<>();
borgbutler-core/src/main/java/de/micromata/borgbutler/jcs/JCSCache.java
New file
@@ -0,0 +1,42 @@
package de.micromata.borgbutler.jcs;
import de.micromata.borgbutler.config.Configuration;
import de.micromata.borgbutler.config.ConfigurationHandler;
import org.apache.commons.jcs.JCS;
import org.apache.commons.jcs.access.CacheAccess;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class JCSCache {
    private static Logger log = LoggerFactory.getLogger(JCSCache.class);
    private static JCSCache instance = new JCSCache();
    private static final String CONFIG_FILE = "jcs-basic-config.properties";
    public static final String CACHE_DIR_NAME = "cache";
    private JCSCache() {
        Configuration configuration = ConfigurationHandler.getConfiguration();
        File cacheDir = new File(ConfigurationHandler.getInstance().getWorkingDir(), CACHE_DIR_NAME);
        if (!cacheDir.exists()) {
            log.info("Creating cache dir: " + cacheDir.getAbsolutePath());
            cacheDir.mkdir();
        }
        Properties props = new Properties();
        try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(CONFIG_FILE)) {
            props.load(inputStream);
        } catch (IOException ex) {
            log.error("Error while loading jcs config file '" + CONFIG_FILE + "': " + ex.getMessage(), ex);
        }
        CacheAccess<String, String> jcs = JCS.getInstance("default");
        props.setProperty("jcs.auxiliary.DC.attributes.DiskPath", cacheDir.getAbsolutePath());
        props.setProperty("jcs.auxiliary.DC2.attributes.DiskPath", cacheDir.getAbsolutePath());
        int cacheMaxDiscSizeMB = configuration.getCacheMaxDiscSizeMB();
        props.setProperty("jcs.auxiliary.DC2.attributes.MaxKeySize", String.valueOf(cacheMaxDiscSizeMB * 1000));
        JCS.setConfigProperties(props);
    }
}
borgbutler-core/src/main/resources/jcs-basic-config.properties
New file
@@ -0,0 +1,43 @@
# It's not the standard cache.ccf, because some properties should be changed programatically.
# DEFAULT CACHE REGION
jcs.default=DC
jcs.default.cacheattributes=org.apache.commons.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=1000
jcs.default.cacheattributes.MemoryCacheName=org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache
jcs.default.elementattributes=org.apache.commons.jcs.engine.ElementAttributes
jcs.default.elementattributes.IsEternal=true
jcs.default.elementattributes.IsSpool=true
# PRE-DEFINED CACHE REGIONS
# For file system content (over million of entries for one borg backup archive.
jcs.region.archiveContent=DC2
jcs.region.archiveContent.cacheattributes=org.apache.commons.jcs.engine.CompositeCacheAttributes
jcs.region.archiveContent.cacheattributes.MaxObjects=1000
jcs.region.archiveContent.cacheattributes.MemoryCacheName=org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.archiveContent.cacheattributes.UseMemoryShrinker=true
jcs.region.archiveContent.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.region.archiveContent.cacheattributes.ShrinkerIntervalSeconds=60
# Only a few archive contents should be spooled (saved to disc):
jcs.region.archiveContent.cacheattributes.MaxSpoolPerRun=5
jcs.region.archiveContent.elementattributes=org.apache.commons.jcs.engine.ElementAttributes
jcs.region.archiveContent.elementattributes.IsEternal=false
# AVAILABLE AUXILIARY CACHES
jcs.auxiliary.DC=org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
jcs.auxiliary.DC.attributes=org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
jcs.auxiliary.DC.attributes.maxKeySize=1000
jcs.auxiliary.DC.attributes.OptimizeOnShutdown=true
# jcs.auxiliary.DC.attributes.DiskPath=${user.dir}/.borgbutler/cache # Will be configured in ~/.borgbutler.json
jcs.auxiliary.DC2=org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
jcs.auxiliary.DC2.attributes=org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
jcs.auxiliary.DC2.attributes.maxKeySize=10
jcs.auxiliary.DC2.attributes.OptimizeOnShutdown=true
jcs.auxiliary.DC2.attributes.DiskLimitType=SIZE
# jcs.auxiliary.DC2.attributes.MaxKeySize=10000 (KB): Will be configured in ~/.borgbutler.json!
# jcs.auxiliary.DC2.attributes.DiskPath=${user.dir}/.borgbutler/cache # Will be configured in ~/.borgbutler.json