summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/backup/incremental
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/backup/incremental')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManager.java26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManager.java b/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManager.java
index 7870620..53143f8 100644
--- a/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManager.java
+++ b/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManager.java
@@ -4,15 +4,18 @@ import com.keuin.kbackupfabric.backup.incremental.ObjectCollection2;
import com.keuin.kbackupfabric.backup.incremental.ObjectCollectionIterator;
import com.keuin.kbackupfabric.backup.incremental.ObjectElement;
import com.keuin.kbackupfabric.backup.incremental.identifier.ObjectIdentifier;
+import com.keuin.kbackupfabric.config.KBackupConfig;
import com.keuin.kbackupfabric.util.FilesystemUtil;
import com.keuin.kbackupfabric.util.PrintUtil;
+import com.keuin.kbackupfabric.util.cow.FileCopier;
+import com.keuin.kbackupfabric.util.cow.FileCowCopier;
+import com.keuin.kbackupfabric.util.cow.FileEagerCopier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.logging.Logger;
@@ -27,9 +30,26 @@ public class IncrementalBackupStorageManager {
private final Logger logger = Logger.getLogger(IncrementalBackupStorageManager.class.getName());
private final Path backupStorageBase;
private final Logger LOGGER = Logger.getLogger(IncrementalBackupStorageManager.class.getName());
+ private FileCopier copier;
public IncrementalBackupStorageManager(Path backupStorageBase) {
this.backupStorageBase = backupStorageBase;
+ if (KBackupConfig.getInstance().getIncbakCow()) {
+ // try to use cow copier, if failed, fallback to normal copier
+ try {
+ this.copier = FileCowCopier.getInstance();
+ } catch (Exception | UnsatisfiedLinkError ex) {
+ PrintUtil.error("Failed to initialize kbackup-cow: " + ex + ex.getMessage());
+ this.copier = new FileEagerCopier();
+ }
+ } else {
+ this.copier = new FileEagerCopier();
+ }
+ if (this.copier.isCow()) {
+ PrintUtil.info("Copy-on-write is enabled");
+ } else {
+ PrintUtil.info("Copy-on-write is disabled");
+ }
}
/**
@@ -85,7 +105,7 @@ public class IncrementalBackupStorageManager {
if (!contains(entry.getValue())) {
// element does not exist. copy.
logger.fine("Copy new file `" + copySourceFile.getName() + "`.");
- Files.copy(copySourceFile.toPath(), copyDestination.toPath());
+ copier.copy(copyDestination.getAbsolutePath(), copySourceFile.getAbsolutePath());
copyCount = copyCount.addWith(new IncCopyResult(1, 1, fileBytes, fileBytes));
} else {
// element exists (file reused). Just update the stat info
@@ -198,7 +218,7 @@ public class IncrementalBackupStorageManager {
}
}
- Files.copy(copySource.toPath(), copyTarget.toPath());
+ copier.copy(copyTarget.getAbsolutePath(), copySource.getAbsolutePath());
++copyCount;
}