summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/operation/backup
diff options
context:
space:
mode:
authorKeuin <[email protected]>2020-08-02 18:31:50 +0800
committerkeuin <[email protected]>2020-08-02 18:31:50 +0800
commitd9c2af035ac2edb68bc8b6a1f94b7c772c3509c8 (patch)
tree4a27dd9a313090ae75d35e4d27d5bdd40b1eb218 /src/main/java/com/keuin/kbackupfabric/operation/backup
parentf09d420df609194a17e9d9ec63d710df8135aa8e (diff)
Refactor & object tree impl. stage 1
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/operation/backup')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/operation/backup/BackupMethod.java22
-rw-r--r--src/main/java/com/keuin/kbackupfabric/operation/backup/PrimitiveBackupMehtod.java42
2 files changed, 64 insertions, 0 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/operation/backup/BackupMethod.java b/src/main/java/com/keuin/kbackupfabric/operation/backup/BackupMethod.java
new file mode 100644
index 0000000..97c609d
--- /dev/null
+++ b/src/main/java/com/keuin/kbackupfabric/operation/backup/BackupMethod.java
@@ -0,0 +1,22 @@
+package com.keuin.kbackupfabric.operation.backup;
+
+import com.keuin.kbackupfabric.util.backup.builder.BackupFileNameBuilder;
+import com.keuin.kbackupfabric.util.backup.formatter.BackupFileNameFormatter;
+import com.sun.istack.internal.NotNull;
+
+import java.io.IOException;
+
+public interface BackupMethod {
+
+ /**
+ * Perform a backup with given method. The backup will be saved as the given name.
+ * Note: real file name is depended by the backup type.
+ * @param backupName the backup name.
+ */
+ void backup(@NotNull String backupName, @NotNull String levelPath, @NotNull String backupSaveDirectory) throws IOException;
+
+ BackupFileNameBuilder getBackupFileNameBuilder();
+
+ BackupFileNameFormatter getBackupFileNameFormatter();
+
+}
diff --git a/src/main/java/com/keuin/kbackupfabric/operation/backup/PrimitiveBackupMehtod.java b/src/main/java/com/keuin/kbackupfabric/operation/backup/PrimitiveBackupMehtod.java
new file mode 100644
index 0000000..3c2a608
--- /dev/null
+++ b/src/main/java/com/keuin/kbackupfabric/operation/backup/PrimitiveBackupMehtod.java
@@ -0,0 +1,42 @@
+package com.keuin.kbackupfabric.operation.backup;
+
+import com.keuin.kbackupfabric.exception.ZipUtilException;
+import com.keuin.kbackupfabric.metadata.BackupMetadata;
+import com.keuin.kbackupfabric.util.PrintUtil;
+import com.keuin.kbackupfabric.util.ZipUtil;
+import com.keuin.kbackupfabric.util.backup.builder.BackupFileNameBuilder;
+import com.keuin.kbackupfabric.util.backup.formatter.BackupFileNameFormatter;
+
+import java.io.File;
+import java.io.IOException;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+
+public class PrimitiveBackupMehtod implements BackupMethod {
+ @Override
+ public boolean backup(String backupName, String levelPath, String backupSaveDirectory) throws IOException {
+ try {
+ String backupFileName = BackupFileNameBuilder.primitiveZipBackup().build(LocalDateTime.now(),backupName);
+ BackupMetadata backupMetadata = new BackupMetadata(System.currentTimeMillis(), backupName);
+
+ PrintUtil.info(String.format("zip(srcPath=%s, destPath=%s)", levelPath, backupSaveDirectory));
+ PrintUtil.info("Compressing level ...");
+ ZipUtil.makeBackupZip(levelPath, backupSaveDirectory, backupFileName, backupMetadata);
+
+ } catch (ZipUtilException exception) {
+ PrintUtil.info("Infinite recursive of directory tree detected, backup was aborted.");
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public BackupFileNameBuilder getBackupFileNameBuilder() {
+ return BackupFileNameBuilder.primitiveZipBackup();
+ }
+
+ @Override
+ public BackupFileNameFormatter getBackupFileNameFormatter() {
+ return BFNF;
+ }
+}