Wire up backup config

This commit is contained in:
nossr50 2019-03-19 08:39:37 -07:00
parent 883fca3cf3
commit bd0a4c75c0
5 changed files with 68 additions and 113 deletions

View File

@ -35,6 +35,9 @@ Version 2.2.0
Added config option for showing author patreon links in various commands Added config option for showing author patreon links in various commands
Automated backup config options will now be found in "automated_backups.conf" Automated backup config options will now be found in "automated_backups.conf"
"Last_24_Hours", "Daily_Last_Week", "Weekly_Past_Months" have been replaced with "Old-File-Age-Limit-In-Days" which does the same thing
mcMMO will not remove old backups unless at least 10 files are present in the backup folder, this doesn't guarantee that mcMMO won't remove old files, just prevents unnecessary operations
Added some failsafes to prevent mcMMO from saving too often
Command config options will now be found in "commands.conf" Command config options will now be found in "commands.conf"
Settings related to party chat have been moved to the party config file Settings related to party chat have been moved to the party config file

View File

@ -240,9 +240,9 @@ public class MainConfig extends ConfigValidated {
List<String> reason = new ArrayList<String>(); List<String> reason = new ArrayList<String>();
/* General Settings */ /* General Settings */
if (getSaveInterval() <= 0) { /*if (getSaveInterval() <= 0) {
reason.add(GENERAL + SAVE_INTERVAL + " should be greater than 0!"); reason.add(GENERAL + SAVE_INTERVAL + " should be greater than 0!");
} }*/
/* MySQL Settings */ /* MySQL Settings */
/*for (SQLDatabaseManager.PoolIdentifier identifier : SQLDatabaseManager.PoolIdentifier.values()) { /*for (SQLDatabaseManager.PoolIdentifier identifier : SQLDatabaseManager.PoolIdentifier.values()) {
@ -434,22 +434,10 @@ public class MainConfig extends ConfigValidated {
* GENERAL SETTINGS * GENERAL SETTINGS
*/ */
/* General Settings */
public String getLocale() {
if(hasNode(GENERAL, LOCALE))
return getStringValue(GENERAL, LOCALE);
else
return "en_US";
}
public boolean getShowProfileLoadedMessage() { public boolean getShowProfileLoadedMessage() {
return getBooleanValue(GENERAL, SHOW_PROFILE_LOADED); return getBooleanValue(GENERAL, SHOW_PROFILE_LOADED);
} }
public int getSaveInterval() {
return getIntValue(GENERAL, SAVE_INTERVAL);
}
public String getAdminChatPrefix() { public String getAdminChatPrefix() {
return getStringValue(COMMANDS, ADMINCHAT, CHAT_PREFIX_FORMAT); return getStringValue(COMMANDS, ADMINCHAT, CHAT_PREFIX_FORMAT);
} }
@ -491,78 +479,6 @@ public class MainConfig extends ConfigValidated {
return getIntValue(MOB_HEALTHBAR, DISPLAY_TIME); return getIntValue(MOB_HEALTHBAR, DISPLAY_TIME);
} }
/* Backups */
public boolean getBackupsEnabled() {
return getBooleanValue(BACKUPS, ENABLED);
}
public boolean getKeepLast24Hours() {
return getBooleanValue(BACKUPS, KEEP_LAST_24_HOURS);
}
public boolean getKeepDailyLastWeek() {
return getBooleanValue(BACKUPS, KEEP, DAILY_LAST_WEEK);
}
public boolean getKeepWeeklyPastMonth() {
return getBooleanValue(BACKUPS, KEEP, WEEKLY_PAST_MONTHS);
}
/* mySQL */
/*public boolean getUseMySQL() {
return getBooleanValue(MY_SQL, ENABLED);
}
public String getMySQLTablePrefix() {
return getStringValue(MY_SQL, DATABASE, TABLE_PREFIX, DATABASE_PREFIX);
}
public String getMySQLDatabaseName() {
return getStringValue(MY_SQL, DATABASE, NAME);
}
public String getMySQLUserName() {
return getStringValue(MY_SQL, DATABASE, USER_NAME);
}
public int getMySQLServerPort() {
return getIntValue(MY_SQL, SERVER, PORT);
}
public String getMySQLServerName() {
return getStringValue(MY_SQL, SERVER, ADDRESS, LOCALHOST);
}
public String getMySQLUserPassword() {
return getStringValue(MY_SQL, DATABASE, USER_PASSWORD);
}
public int getMySQLMaxConnections(SQLDatabaseManager.PoolIdentifier identifier) {
return getIntValue(MY_SQL, DATABASE, MAX_CONNECTIONS, StringUtils.getCapitalized(identifier.toString()));
}
public int getMySQLMaxPoolSize(SQLDatabaseManager.PoolIdentifier identifier) {
return getIntValue(MY_SQL, DATABASE, MAX_POOL_SIZE, StringUtils.getCapitalized(identifier.toString()));
}
public boolean getMySQLSSL() {
return getBooleanValue(MY_SQL, SERVER, SSL);
}*/
//TODO: Legit cannot tell what the point of this method was
/*ssadprivate String getStringIncludingInts(String[] key) {
String str = getStringValue(key);
if (str == null) {
str = String.valueOf(getIntValue(key));
}
if (str.equals("0")) {
str = "No value set for '" + key + "'";
}
return str;
}*/
/* Hardcore Mode */ /* Hardcore Mode */
public boolean getHardcoreStatLossEnabled(PrimarySkillType primarySkillType) { public boolean getHardcoreStatLossEnabled(PrimarySkillType primarySkillType) {
return getBooleanValue(HARDCORE, DEATH_STAT_LOSS, ENABLED, StringUtils.getCapitalized(primarySkillType.toString())); return getBooleanValue(HARDCORE, DEATH_STAT_LOSS, ENABLED, StringUtils.getCapitalized(primarySkillType.toString()));

View File

@ -1,7 +1,57 @@
package com.gmail.nossr50.config.hocon.backup; package com.gmail.nossr50.config.hocon.backup;
import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
@ConfigSerializable @ConfigSerializable
public class ConfigAutomatedBackups { public class ConfigAutomatedBackups {
public static final int SAVE_INTERVAL_MINUTES_DEFAULT = 10;
public static final boolean ZIP_BACKUPS_ENABLED_DEFAULT = true;
public static final int BACKUP_DAY_LIMIT_DEFAULT = 30;
//public static final int MINIMUM_BACKUP_COUNT_DEFAULT = 10;
@Setting(value = "Database-Save-Interval-Minutes", comment = "How often mcMMO player data gets saved." +
"\nThis value represents how many minutes in between saving mcMMO does." +
"\nSaving is done in ASYNC threads, so it has almost no impact on performance, however you should not be saving too often as its a bit pointless and takes resources away from your machine." +
"\nI recommend just leaving this at its default value." +
"\nDefault value: "+SAVE_INTERVAL_MINUTES_DEFAULT)
private int saveIntervalMinutes = SAVE_INTERVAL_MINUTES_DEFAULT;
@Setting(value = "Backup-Configs-And-FlatFile-Data", comment = "mcMMO will make backups of your configs and other important data for you." +
"\nNOTE: mcMMO will not be making backups of your SQL data, you will have to setup scripts for that yourself." +
"\nmcMMO does not backup FlatFile user data if you are using SQL" +
"\nYou can find the backups in the following directory inside your mcMMO folder - \\mcMMO\\backup" +
"\nAutomated backups are deleted regularly once they reach a certain age, see the other options in this config to change this." +
"\nBackups are made whenever you start your server for the first time and on each reload of the mcMMO plugin" +
"\nDefault value: "+ZIP_BACKUPS_ENABLED_DEFAULT)
private boolean zipBackupsEnabled = ZIP_BACKUPS_ENABLED_DEFAULT;
@Setting(value = "Old-File-Age-Limit-In-Days", comment = "How many days should backups be kept in days?" +
"\nBackups older than this are removed if the number of file backups is greater than \"Minimum-Backups\"." +
"\nDefault value: "+ BACKUP_DAY_LIMIT_DEFAULT)
private int backupDayLimit = BACKUP_DAY_LIMIT_DEFAULT;
/* @Setting(value = "Minimum-Backups", comment = "The amount of backup files you must have before deletion of older files would be considered." +
"\nThis does not prevent mcMMO from removing your old backups, it just prevents unnecessary removal of those files." +
"\nFor example, if this value was set to 10. Then if you had 9 old backups from not having your server on for a long time," +
"\n then once the 10th backup is created those 9 older files would be removed." +
"\nThis setting mostly prevents unnecessary operations rather than acting as a means to preserve a specific number of backups." +
"\nDefault value: "+MINIMUM_BACKUP_COUNT_DEFAULT)
private int minimumBackupCount = MINIMUM_BACKUP_COUNT_DEFAULT;*/
/* public int getMinimumBackupCount() {
return minimumBackupCount;
}*/
public int getSaveIntervalMinutes() {
return saveIntervalMinutes;
}
public boolean isZipBackupsEnabled() {
return zipBackupsEnabled;
}
public int getBackupDayLimit() {
return backupDayLimit;
}
} }

View File

@ -218,7 +218,7 @@ public class mcMMO extends JavaPlugin {
debug("Unregister all events..."); debug("Unregister all events...");
HandlerList.unregisterAll(this); // Cancel event registrations HandlerList.unregisterAll(this); // Cancel event registrations
if (MainConfig.getInstance().getBackupsEnabled()) { if (mcMMO.getConfigManager().getConfigAutomatedBackups().isZipBackupsEnabled()) {
// Remove other tasks BEFORE starting the Backup, or we just cancel it straight away. // Remove other tasks BEFORE starting the Backup, or we just cancel it straight away.
try { try {
ZipLibrary.mcMMOBackup(); ZipLibrary.mcMMOBackup();
@ -481,7 +481,7 @@ public class mcMMO extends JavaPlugin {
private void scheduleTasks() { private void scheduleTasks() {
// Periodic save timer (Saves every 10 minutes by default) // Periodic save timer (Saves every 10 minutes by default)
long saveIntervalTicks = MainConfig.getInstance().getSaveInterval() * 1200; long saveIntervalTicks = Math.max(1200, (getConfigManager().getConfigAutomatedBackups().getSaveIntervalMinutes() * 1200));
new SaveTimerTask().runTaskTimer(this, saveIntervalTicks, saveIntervalTicks); new SaveTimerTask().runTaskTimer(this, saveIntervalTicks, saveIntervalTicks);
// Cleanup the backups folder // Cleanup the backups folder

View File

@ -21,11 +21,17 @@ public class CleanBackupsTask extends BukkitRunnable {
List<File> toDelete = new ArrayList<File>(); List<File> toDelete = new ArrayList<File>();
int amountTotal = 0; int amountTotal = 0;
int amountDeleted = 0; int amountDeleted = 0;
int oldFileAgeLimit = mcMMO.getConfigManager().getConfigAutomatedBackups().getBackupDayLimit();
if (BACKUP_DIR.listFiles() == null) { if (BACKUP_DIR.listFiles() == null) {
return; return;
} }
//if(BACKUP_DIR.listFiles().length < mcMMO.getConfigManager().getConfigAutomatedBackups().getMinimumBackupCount())
//Don't remove files unless there is at least 10 of them
if(BACKUP_DIR.listFiles().length < 10)
return;
// Check files in backup folder from oldest to newest // Check files in backup folder from oldest to newest
for (File file : BACKUP_DIR.listFiles()) { for (File file : BACKUP_DIR.listFiles()) {
if (!file.isFile() || file.isDirectory()) { if (!file.isFile() || file.isDirectory()) {
@ -42,34 +48,14 @@ public class CleanBackupsTask extends BukkitRunnable {
continue; continue;
} }
Calendar cal = Calendar.getInstance(); long fileSaveTimeStamp = date.getTime();
cal.setTime(date); long currentTime = System.currentTimeMillis();
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
int weekOfYear = cal.get(Calendar.WEEK_OF_YEAR);
int year = cal.get(Calendar.YEAR);
if (isPast24Hours(date) && MainConfig.getInstance().getKeepLast24Hours()) { //File is not old enough so don't delete it
// Keep all files from the last 24 hours if((fileSaveTimeStamp + (oldFileAgeLimit * TimeUnit.MILLISECONDS.convert(24, TimeUnit.HOURS))) >= currentTime)
{
continue; continue;
} }
else if (isLastWeek(date) && !savedDays.contains(dayOfWeek) && MainConfig.getInstance().getKeepDailyLastWeek()) {
// Keep daily backups of the past week
savedDays.add(dayOfWeek);
continue;
}
else {
List<Integer> savedWeeks = savedYearsWeeks.get(year);
if (savedWeeks == null) {
savedWeeks = new ArrayList<Integer>();
savedYearsWeeks.put(year, savedWeeks);
}
if (!savedWeeks.contains(weekOfYear) && MainConfig.getInstance().getKeepWeeklyPastMonth()) {
// Keep one backup of each week
savedWeeks.add(weekOfYear);
continue;
}
}
amountDeleted++; amountDeleted++;
toDelete.add(file); toDelete.add(file);