ChaoticTrials / SimpleBackups

A simple mod to create scheduled backups
https://modrinth.com/mod/simple-backups
Apache License 2.0
10 stars 7 forks source link

Symlinks not supported. `java.nio.file.FileAlreadyExistsException` #38

Open ModestTG opened 6 days ago

ModestTG commented 6 days ago

Minecraft version

1.20.x

Simple Backups version

1.20.1-3.1.7

(Neo)Forge version

1.20.1-47.3.7

The latest.log file

https://pastebin.com/RjrXW5wv

Issue description

I am trying to run backups on my ATM9 server. I want to save my backups onto a NAS folder, so I tried to symlink a folder inside the /data directory to my NAS folder. When I do that, I get a java.nio.file.FileAlreadyExistsException on that directory. Perhaps this isn't an actual issue and I should just reference the NAS folder directly. I've been trying to work through some file permissions to get that to work but in the meantime I thought I would try a symlink.

Steps to reproduce

  1. Create a symlink to your backup location
    ln -s /path/to/backup/folder /path/inside/minecraft/data/folder
  2. ensure the simplebackups-common.toml is configured with outPath pointed to /path/inside/minecraft/data/folder
  3. from rcon-cli, run simplebackups backup start.

Other information

No response

MelanX commented 6 days ago

Would you like to test this updated test version? SimpleBackups-1.20.1-3.1.9-test.zip

Here's what I changed:

Index: src/main/java/de/melanx/simplebackups/config/CommonConfig.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/java/de/melanx/simplebackups/config/CommonConfig.java b/src/main/java/de/melanx/simplebackups/config/CommonConfig.java
--- a/src/main/java/de/melanx/simplebackups/config/CommonConfig.java    (revision 2489fe982aa691930e04f796411d696108c002f9)
+++ b/src/main/java/de/melanx/simplebackups/config/CommonConfig.java    (date 1727109200454)
@@ -1,10 +1,13 @@
 package de.melanx.simplebackups.config;

+import de.melanx.simplebackups.SimpleBackups;
 import de.melanx.simplebackups.StorageSize;
 import net.minecraftforge.common.ForgeConfigSpec;

 import javax.annotation.Nullable;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.zip.Deflater;
@@ -109,6 +112,15 @@

     public static Path getOutputPath(@Nullable String levelId) {
         Path base = Paths.get(outputPath.get());
+        if (Files.isSymbolicLink(base)) {
+            try {
+                base = Files.readSymbolicLink(base);
+            } catch (IOException e) {
+                SimpleBackups.LOGGER.error("Failed to read symbolic link at: {}", base);
+                throw new RuntimeException(e);
+            }
+        }
+
         boolean withSubDir = levelId != null && !levelId.isEmpty() && createSubDirs.get();
         try {
             return withSubDir ? base.toRealPath().resolve(levelId) : base.toRealPath();

It worked on my end, and I hope that it will also fix your issue. I'm not very familiar with symlinks and using them properly.

ModestTG commented 6 days ago

Wow, what a quick update! I was able to test it. I symlinked /data/simplebackups to /tmp/mcback, and set the appropriate config. When I triggered simplebackups backup start, the backup appears to start (I get the chat popup in the MC client), but I don't see any debug message that the backup has started and no actual backup lives on /tmp/mcback. So the code change appears to be evaluating the symlink correctly, but no actual backup seems to be taking place.

Edit: I tried some other directories and I got a lot of java.nio.file.AccessDeniedException errors where I assume my container isn't playing nice with permissions on my filesystem. The only location that worked based on permissions was /tmp/mcback, and I wasn't able to see any backup created or debug message. Thanks again for looking into this! I personally was able to workaround this by just mounting my backup location as a volume inside the MC server container so it worked out that way. But I'll still help you test if you need it!