-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to only backup claimed chunks (#101)
* switch backups to common compress lib & add max folder size config * Change uncompressed backup to a STORED zip instead of folder * disabled by default * stringbuilder be gone * custom-named backups should be deleted by default * iterator isn't necessary anymore * add option to only backup claimed chunks * no need to remap the ChunkDimPos' to long * much more optimized solution for mapping claims to their region file * update configs * update configs * make backups fall back to using native java zip if commons compress is somehow missing --------- Co-authored-by: Martin Robertz <dream-master@gmx.net>
- Loading branch information
1 parent
9b013ce
commit b82a106
Showing
9 changed files
with
314 additions
and
60 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
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
46 changes: 46 additions & 0 deletions
46
src/main/java/serverutils/lib/util/compression/CommonsCompressor.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,46 @@ | ||
package serverutils.lib.util.compression; | ||
|
||
import static serverutils.ServerUtilitiesConfig.backups; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.zip.ZipEntry; | ||
|
||
import org.apache.commons.compress.archivers.ArchiveEntry; | ||
import org.apache.commons.compress.archivers.ArchiveOutputStream; | ||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; | ||
import org.apache.commons.io.IOUtils; | ||
|
||
public class CommonsCompressor implements ICompress { | ||
|
||
private ArchiveOutputStream output; | ||
|
||
@Override | ||
public void createOutputStream(File file) throws IOException { | ||
ZipArchiveOutputStream zaos = new ZipArchiveOutputStream(file); | ||
if (backups.compression_level == 0) { | ||
zaos.setMethod(ZipEntry.STORED); | ||
} else { | ||
zaos.setLevel(backups.compression_level); | ||
} | ||
output = zaos; | ||
} | ||
|
||
@Override | ||
public void addFileToArchive(File file, String name) throws IOException { | ||
ArchiveEntry entry = output.createArchiveEntry(file, name); | ||
output.putArchiveEntry(entry); | ||
try (FileInputStream fis = new FileInputStream(file)) { | ||
IOUtils.copy(fis, output); | ||
} | ||
output.closeArchiveEntry(); | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
if (output != null) { | ||
output.close(); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/serverutils/lib/util/compression/ICompress.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,11 @@ | ||
package serverutils.lib.util.compression; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
public interface ICompress extends AutoCloseable { | ||
|
||
void createOutputStream(File file) throws IOException; | ||
|
||
void addFileToArchive(File file, String name) throws IOException; | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/serverutils/lib/util/compression/LegacyCompressor.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,46 @@ | ||
package serverutils.lib.util.compression; | ||
|
||
import static serverutils.ServerUtilitiesConfig.backups; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipOutputStream; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
|
||
public class LegacyCompressor implements ICompress { | ||
|
||
private ZipOutputStream output; | ||
|
||
@Override | ||
public void createOutputStream(File file) throws IOException { | ||
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file)); | ||
if (backups.compression_level == 0) { | ||
zos.setMethod(ZipOutputStream.STORED); | ||
} else { | ||
zos.setLevel(backups.compression_level); | ||
} | ||
|
||
output = zos; | ||
} | ||
|
||
@Override | ||
public void addFileToArchive(File file, String name) throws IOException { | ||
ZipEntry entry = new ZipEntry(name); | ||
output.putNextEntry(entry); | ||
try (FileInputStream fis = new FileInputStream(file)) { | ||
IOUtils.copy(fis, output); | ||
} | ||
output.closeEntry(); | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
if (output != null) { | ||
output.close(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.