mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Perform daily and weekly backups. Resolves #163
This commit is contained in:
parent
796ef3d359
commit
0435174342
@ -1,3 +1,3 @@
|
|||||||
#Build Number for ANT. Do not edit!
|
#Build Number for ANT. Do not edit!
|
||||||
#Sun May 11 18:05:04 CEST 2014
|
#Sun May 11 18:41:12 CEST 2014
|
||||||
build.number=826
|
build.number=830
|
||||||
|
@ -11,6 +11,7 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
|
||||||
import net.minecraft.util.org.apache.commons.io.FileUtils;
|
import net.minecraft.util.org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
@ -687,8 +688,8 @@ public class TFM_Util
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SAVED_FLAGS_FILE));
|
final FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SAVED_FLAGS_FILE));
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
final ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||||
oos.writeObject(flags);
|
oos.writeObject(flags);
|
||||||
oos.close();
|
oos.close();
|
||||||
fos.close();
|
fos.close();
|
||||||
@ -699,10 +700,54 @@ public class TFM_Util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createBackup(String file)
|
public static void createBackups(String file)
|
||||||
{
|
{
|
||||||
|
final String save = file.split("\\.")[0];
|
||||||
|
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, "backup.yml", false);
|
||||||
|
config.load();
|
||||||
|
|
||||||
|
// Daily
|
||||||
|
if (!config.isInt(save + ".daily"))
|
||||||
|
{
|
||||||
|
performBackup(file, "daily");
|
||||||
|
config.set(save + ".daily", TFM_Util.getUnixTime());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int lastBackupDaily = config.getInt(save + ".daily");
|
||||||
|
|
||||||
|
if (lastBackupDaily + 3600 * 24 < TFM_Util.getUnixTime())
|
||||||
|
{
|
||||||
|
performBackup(file, "daily");
|
||||||
|
config.set(save + ".daily", TFM_Util.getUnixTime());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Weekly
|
||||||
|
if (!config.isInt(save + ".weekly"))
|
||||||
|
{
|
||||||
|
performBackup(file, "weekly");
|
||||||
|
config.set(save + ".weekly", TFM_Util.getUnixTime());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int lastBackupWeekly = config.getInt(save + ".weekly");
|
||||||
|
|
||||||
|
if (lastBackupWeekly + 3600 * 24 * 7 < TFM_Util.getUnixTime())
|
||||||
|
{
|
||||||
|
performBackup(file, "weekly");
|
||||||
|
config.set(save + ".weekly", TFM_Util.getUnixTime());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void performBackup(String file, String type)
|
||||||
|
{
|
||||||
|
TFM_Log.info("Backing up " + file + " to " + file + "." + type + ".bak");
|
||||||
final File oldYaml = new File(TotalFreedomMod.plugin.getDataFolder(), file);
|
final File oldYaml = new File(TotalFreedomMod.plugin.getDataFolder(), file);
|
||||||
final File newYaml = new File(TotalFreedomMod.plugin.getDataFolder(), file + ".bak");
|
final File newYaml = new File(TotalFreedomMod.plugin.getDataFolder(), file + "." + type + ".bak");
|
||||||
FileUtil.copy(oldYaml, newYaml);
|
FileUtil.copy(oldYaml, newYaml);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -853,6 +898,8 @@ public class TFM_Util
|
|||||||
Field field = checkClass.getDeclaredField(name);
|
Field field = checkClass.getDeclaredField(name);
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
return (T) field.get(from);
|
return (T) field.get(from);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (NoSuchFieldException ex)
|
catch (NoSuchFieldException ex)
|
||||||
{
|
{
|
||||||
@ -861,7 +908,9 @@ public class TFM_Util
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (checkClass.getSuperclass() != Object.class && ((checkClass = checkClass.getSuperclass()) != null));
|
while (checkClass.getSuperclass() != Object.class
|
||||||
|
&& ((checkClass = checkClass.getSuperclass()) != null));
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -899,6 +948,8 @@ public class TFM_Util
|
|||||||
{
|
{
|
||||||
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
return packageName.substring(packageName.lastIndexOf('.') + 1);
|
return packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TFM_EntityWiper
|
public static class TFM_EntityWiper
|
||||||
|
@ -90,11 +90,11 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Admin list
|
// Admin list
|
||||||
TFM_Util.createBackup(SUPERADMIN_FILE);
|
TFM_Util.createBackups(SUPERADMIN_FILE);
|
||||||
TFM_AdminList.load();
|
TFM_AdminList.load();
|
||||||
|
|
||||||
// Permban list
|
// Permban list
|
||||||
TFM_Util.createBackup(PERMBAN_FILE);
|
TFM_Util.createBackups(PERMBAN_FILE);
|
||||||
TFM_PermbanList.load();
|
TFM_PermbanList.load();
|
||||||
|
|
||||||
// Playerlist and bans
|
// Playerlist and bans
|
||||||
|
Loading…
Reference in New Issue
Block a user