@@ -39,7 +39,7 @@ public static Path getBackupPath() {
3939 try {
4040 Files .createDirectories (path );
4141 } catch (IOException e ) {
42- QuickbackupmultiReforged . logger .error ("Create backup path error: {}" , e .getMessage ());
42+ logger .error ("Create backup path error: {}" , e .getMessage ());
4343 }
4444 }
4545 return path ;
@@ -48,7 +48,11 @@ public static Path getBackupPath() {
4848 public static List <StorageInfo > getBackupsList () {
4949 List <StorageInfo > backupList ;
5050 if (!QuickbackupmultiReforged .getModConfig ().isCacheDatabase ()) {
51- backupList = QuickbackupmultiReforged .getDatabase ().getAllStorageInfo ();
51+ backupList = QuickbackupmultiReforged .getDatabase ()
52+ .getAllStorageInfo ()
53+ .stream ()
54+ .filter (StorageInfo ::getUseIncrementalStorage )
55+ .toList ();
5256 } else {
5357 backupList = DatabaseCache .getStorageInfoCaches ();
5458 }
@@ -79,6 +83,48 @@ public static int getBackupIndex(String name) {
7983 return -1 ;
8084 }
8185
86+ private static void makeFullBackup () {
87+ if (QuickbackupmultiReforged .getModConfig ().getFullBackupInterval () == -1 ) {
88+ return ;
89+ }
90+
91+ if (!getBackupPath ().resolve ("full" ).toFile ().exists ()) {
92+ logger .info ("Do not have a full backup, make a full backup for future use..." );
93+ QuickbackupmultiReforged .getManager ().fullStorage (
94+ "FullBackup-" + (QuickbackupmultiReforged .getModContainer ().getLevelId ().isEmpty () ? "Server" : QuickbackupmultiReforged .getModContainer ().getLevelId ()),
95+ "Full backup" ,
96+ QuickbackupmultiReforged .getModContainer ().getCurrentSavePath ().toFile (),
97+ fileFilter ,
98+ folderFilter
99+ );
100+ } else {
101+ List <StorageInfo > storageInfoList = QuickbackupmultiReforged .getDatabase ().getAllStorageInfo ();
102+ List <StorageInfo > incrementalBackups = storageInfoList .stream ().filter (StorageInfo ::getUseIncrementalStorage ).toList ();
103+ List <StorageInfo > fullBackups = storageInfoList .stream ().filter (it -> !it .getUseIncrementalStorage ()).toList ();
104+ if (!incrementalBackups .isEmpty () && incrementalBackups .size () % QuickbackupmultiReforged .getModConfig ().getFullBackupInterval () == 0 ) {
105+ if (fullBackups .size () >= QuickbackupmultiReforged .getModConfig ().getSaveFullBackupCount ()) {
106+ fullBackups .stream ().min (Comparator .comparingLong (StorageInfo ::getTimestamp ))
107+ .ifPresent (oldestFullBackup -> {
108+ try {
109+ logger .info ("Delete oldest full backup: {}" , oldestFullBackup .getName ());
110+ FileUtils .deleteDirectory (getBackupPath ().resolve ("full" ).resolve (oldestFullBackup .getName ()).toFile ());
111+ } catch (IOException e ) {
112+ logger .error ("delete oldest full backup failed: " , e );
113+ }
114+ });
115+ }
116+ logger .info ("Make a full backup for future use..." );
117+ QuickbackupmultiReforged .getManager ().fullStorage (
118+ "FullBackup-" + (QuickbackupmultiReforged .getModContainer ().getLevelId ().isEmpty () ? "Server" : QuickbackupmultiReforged .getModContainer ().getLevelId ()),
119+ "Full backup" ,
120+ QuickbackupmultiReforged .getModContainer ().getCurrentSavePath ().toFile (),
121+ fileFilter ,
122+ folderFilter
123+ );
124+ }
125+ }
126+ }
127+
82128 public static void makeBackup (CommandSourceStack commandSource , String name , String desc ) {
83129 if (QuickbackupmultiReforged .getDatabase ().storageExists (name )) {
84130 commandSource .sendSystemMessage (Component .nullToEmpty (tr ("quickbackupmulti.make.fail_exists" )));
@@ -113,15 +159,17 @@ public static void makeBackup(CommandSourceStack commandSource, String name, Str
113159 } catch (Exception e ) {
114160 logger .error ("Make Backup Failed" , e );
115161 commandSource .sendSystemMessage (Component .nullToEmpty (tr ("quickbackupmulti.make.fail" , e .toString ())));
162+ } finally {
163+ makeFullBackup ();
116164 }
117165 }
118166
119167 public static void makeTempBackup () {
120- QuickbackupmultiReforged . logger .info ("Make a temp backup..." );
168+ logger .info ("Make a temp backup..." );
121169 QuickbackupmultiReforged .getManager ().incrementalStorageTemp (
122170 QuickbackupmultiReforged .getModContainer ().getCurrentSavePath ().toFile (), fileFilter , folderFilter
123171 );
124- QuickbackupmultiReforged . logger .info ("Make a temp backup success." );
172+ logger .info ("Make a temp backup success." );
125173 }
126174
127175 public static boolean deleteBackup (CommandSourceStack commandSource , String name ) {
@@ -183,7 +231,7 @@ public static void deleteWorld(String worldName) {
183231 database .deleteTableValue (storageInfo .getName (), DatabaseTables .STORAGE_INFO );
184232 }
185233 } catch (IOException e ) {
186- QuickbackupmultiReforged . logger .error ("Delete Failed" , e );
234+ logger .error ("Delete Failed" , e );
187235 } finally {
188236 database .closeDatabase ();
189237 }
0 commit comments