Skip to content

Commit

Permalink
7.5.14
Browse files Browse the repository at this point in the history
- new: set backup output folder path
  • Loading branch information
Osiris-Team committed Mar 11, 2024
1 parent 0038b99 commit 20a2a47
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<groupId>com.osiris.autoplug.client</groupId>
<artifactId>autoplug-client</artifactId>
<version>7.5.13</version>
<version>7.5.14</version>
<packaging>jar</packaging>

<name>AutoPlug-Client</name>
Expand Down
21 changes: 7 additions & 14 deletions src/main/java/com/osiris/autoplug/client/configs/BackupConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Osiris-Team.
* Copyright (c) 2021-2024 Osiris-Team.
* All rights reserved.
*
* This software is copyrighted work, licensed under the terms
Expand All @@ -8,7 +8,7 @@

package com.osiris.autoplug.client.configs;

import com.osiris.autoplug.client.utils.GD;
import com.osiris.autoplug.client.utils.UtilsFile;
import com.osiris.dyml.Yaml;
import com.osiris.dyml.YamlSection;
import com.osiris.dyml.exceptions.*;
Expand All @@ -25,6 +25,7 @@ public class BackupConfig extends MyYaml {
public YamlSection backup;
public YamlSection backup_max_days;
public YamlSection backup_cool_down;
public YamlSection backup_path;
public YamlSection backup_exclude;
public YamlSection backup_exclude_list;
public YamlSection backup_include;
Expand Down Expand Up @@ -72,6 +73,8 @@ public BackupConfig() throws IOException, DuplicateKeyException, YamlReaderExcep
"The cool-down prevents exactly that from happening and saves you storage space and time.",
"Set to 0 to disable."
);
backup_path = put(name, "path").setDefValues("./autoplug/backups").setComments(
"Where to create your backups.");
backup_include = put(name, "include", "enable").setDefValues("true").setComments(
"Add specific files or folders you want to include in the backup, to the list below.",
"Windows/Linux formats are supported. './' stands for the servers root directory."
Expand Down Expand Up @@ -113,22 +116,12 @@ public BackupConfig() throws IOException, DuplicateKeyException, YamlReaderExcep
unlockFile();
}

private File pathToFile(String path) {
File file = null;
if (path.contains("./"))
path = path.replace("./", GD.WORKING_DIR.getAbsolutePath() + File.separator);
if (!path.contains("/") && !path.contains("\\"))
path = GD.WORKING_DIR.getAbsolutePath() + File.separator + path;

return new File(path);
}

public List<File> getExcludedFiles() {
List<File> files = new ArrayList<>();
for (String path :
backup_exclude_list.asStringList()) {
try {
files.add(pathToFile(path));
files.add(new UtilsFile().pathToFile(path));
} catch (Exception e) {
AL.warn(e);
}
Expand All @@ -141,7 +134,7 @@ public List<File> getIncludedFiles() {
for (String path :
backup_include_list.asStringList()) {
try {
files.add(pathToFile(path));
files.add(new UtilsFile().pathToFile(path));
} catch (Exception e) {
AL.warn(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Osiris-Team.
* Copyright (c) 2021-2024 Osiris-Team.
* All rights reserved.
*
* This software is copyrighted work, licensed under the terms
Expand All @@ -11,8 +11,8 @@
import com.osiris.autoplug.client.Server;
import com.osiris.autoplug.client.configs.BackupConfig;
import com.osiris.autoplug.client.configs.SystemConfig;
import com.osiris.autoplug.client.utils.GD;
import com.osiris.autoplug.client.utils.UtilsConfig;
import com.osiris.autoplug.client.utils.UtilsFile;
import com.osiris.autoplug.client.utils.tasks.CoolDownReport;
import com.osiris.betterthread.BThread;
import com.osiris.betterthread.BThreadManager;
Expand All @@ -37,7 +37,7 @@

public class TaskBackup extends BThread {

private final File autoplug_backups = new File(GD.WORKING_DIR + "/autoplug/backups");
private File autoplug_backups;
private final LocalDateTime date = LocalDateTime.now();
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH.mm");
private final String formattedDate = date.format(formatter);
Expand All @@ -51,7 +51,6 @@ public TaskBackup(String name, BThreadManager manager) {
@Override
public void runAtStart() throws Exception {
super.runAtStart();
autoplug_backups.mkdirs();
createBackup();
}

Expand Down Expand Up @@ -80,6 +79,9 @@ private void createBackup() throws Exception {
systemConfig.unlockFile();
}

autoplug_backups = new UtilsFile().pathToFile(config.backup_path.asString());
autoplug_backups.mkdirs();

String server_backup_dest = autoplug_backups.getAbsolutePath() + "/" + formattedDate + "-BACKUP.zip";
int max_days_server = config.backup_max_days.asInt();

Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/osiris/autoplug/client/utils/UtilsFile.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023 Osiris-Team.
* Copyright (c) 2022-2024 Osiris-Team.
* All rights reserved.
*
* This software is copyrighted work, licensed under the terms
Expand Down Expand Up @@ -44,4 +44,16 @@ public File renameFile(File file, String newName) {
file.delete(); // Delete old
return newFile;
}

public File pathToFile(String path) {
File file = null;
if (path.contains("./"))
path = path.replace("./", GD.WORKING_DIR.getAbsolutePath() + File.separator);
if (path.contains(".\\"))
path = path.replace(".\\", GD.WORKING_DIR.getAbsolutePath() + File.separator);
if (!path.contains("/") && !path.contains("\\"))
path = GD.WORKING_DIR.getAbsolutePath() + File.separator + path;

return new File(path);
}
}

0 comments on commit 20a2a47

Please sign in to comment.