-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: configurable CoW incremental backup
- Loading branch information
Showing
12 changed files
with
194 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/com/keuin/kbackupfabric/config/KBackupConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.keuin.kbackupfabric.config; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.ObjectWriter; | ||
import com.keuin.kbackupfabric.util.PrintUtil; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
|
||
public class KBackupConfig { | ||
|
||
private static KBackupConfig instance = getDefault(); | ||
private static final String CONFIG_FILE = "kbackup.json"; | ||
|
||
@JsonProperty("incbak_cow") | ||
private Boolean incbakCow; | ||
|
||
public static KBackupConfig getInstance() { | ||
return instance; | ||
} | ||
|
||
private static KBackupConfig getDefault() { | ||
return new KBackupConfig(false); | ||
} | ||
|
||
public static void load() throws IOException { | ||
File file = new File(CONFIG_FILE); | ||
ObjectMapper om = new ObjectMapper(); | ||
try { | ||
instance = om.readValue(file, KBackupConfig.class); | ||
} catch (FileNotFoundException ignored) { | ||
// generate default config file | ||
PrintUtil.info("Config file does not exist. Creating default config: " + CONFIG_FILE); | ||
instance = getDefault(); | ||
ObjectWriter w = om.writerWithDefaultPrettyPrinter(); | ||
w.writeValue(file, instance); | ||
} | ||
} | ||
|
||
public KBackupConfig() { | ||
} | ||
|
||
public KBackupConfig(Boolean incbakCow) { | ||
this.incbakCow = incbakCow; | ||
} | ||
|
||
public Boolean getIncbakCow() { | ||
return this.incbakCow; | ||
} | ||
|
||
public void setIncbakCow(Boolean incbakCow) { | ||
this.incbakCow = incbakCow; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/keuin/kbackupfabric/util/cow/FileCopier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.keuin.kbackupfabric.util.cow; | ||
|
||
import java.io.IOException; | ||
|
||
public interface FileCopier { | ||
void copy(String dst, String src) throws IOException; | ||
|
||
boolean isCow(); | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/keuin/kbackupfabric/util/cow/FileCowCopier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.keuin.kbackupfabric.util.cow; | ||
|
||
import com.keuin.kbackupfabric.util.PrintUtil; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
public final class FileCowCopier { | ||
private static final AtomicBoolean initialized = new AtomicBoolean(false); | ||
|
||
static { | ||
try { | ||
System.loadLibrary("kbackup_cow"); | ||
} catch (SecurityException | UnsatisfiedLinkError ignored) { | ||
} | ||
} | ||
|
||
public static native void init(); | ||
|
||
public static native void copy(String dst, String src) throws IOException; | ||
|
||
public static native String getVersion(); | ||
|
||
public static FileCopier getInstance() { | ||
if (initialized.compareAndSet(false, true)) { | ||
FileCowCopier.init(); | ||
PrintUtil.info("kbackup-cow version: " + FileCowCopier.getVersion()); | ||
} | ||
return new FileCopier() { | ||
@Override | ||
public void copy(String dst, String src) throws IOException { | ||
FileCowCopier.copy(dst, src); | ||
} | ||
|
||
@Override | ||
public boolean isCow() { | ||
return true; | ||
} | ||
}; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/keuin/kbackupfabric/util/cow/FileEagerCopier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.keuin.kbackupfabric.util.cow; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
|
||
public class FileEagerCopier implements FileCopier { | ||
@Override | ||
public void copy(String dst, String src) throws IOException { | ||
Files.copy(Paths.get(src), Paths.get(dst)); | ||
} | ||
|
||
@Override | ||
public boolean isCow() { | ||
return false; | ||
} | ||
} |