Perform daily and weekly backups. Resolves #163

This commit is contained in:
unknown 2014-05-11 18:41:58 +02:00
parent 796ef3d359
commit 0435174342
3 changed files with 60 additions and 9 deletions

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Sun May 11 18:05:04 CEST 2014
build.number=826
#Sun May 11 18:41:12 CEST 2014
build.number=830

View File

@ -11,6 +11,7 @@ import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
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.lang3.StringUtils;
@ -687,8 +688,8 @@ public class TFM_Util
try
{
FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SAVED_FLAGS_FILE));
ObjectOutputStream oos = new ObjectOutputStream(fos);
final FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SAVED_FLAGS_FILE));
final ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(flags);
oos.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 newYaml = new File(TotalFreedomMod.plugin.getDataFolder(), file + ".bak");
final File newYaml = new File(TotalFreedomMod.plugin.getDataFolder(), file + "." + type + ".bak");
FileUtil.copy(oldYaml, newYaml);
}
@ -853,6 +898,8 @@ public class TFM_Util
Field field = checkClass.getDeclaredField(name);
field.setAccessible(true);
return (T) field.get(from);
}
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;
}
@ -899,6 +948,8 @@ public class TFM_Util
{
String packageName = Bukkit.getServer().getClass().getPackage().getName();
return packageName.substring(packageName.lastIndexOf('.') + 1);
}
public static class TFM_EntityWiper

View File

@ -90,11 +90,11 @@ public class TotalFreedomMod extends JavaPlugin
}
// Admin list
TFM_Util.createBackup(SUPERADMIN_FILE);
TFM_Util.createBackups(SUPERADMIN_FILE);
TFM_AdminList.load();
// Permban list
TFM_Util.createBackup(PERMBAN_FILE);
TFM_Util.createBackups(PERMBAN_FILE);
TFM_PermbanList.load();
// Playerlist and bans