Configurable automatic database backups.
This commit is contained in:
3
L2J_Mobius_1.0_Ertheia/dist/backup/readme.txt
vendored
Normal file
3
L2J_Mobius_1.0_Ertheia/dist/backup/readme.txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
MySQL backups are stored in this folder.
|
||||||
|
Separate game and login server backups are possible.
|
||||||
|
Just enable the 'BackupDatabase' option in the equivalent server config file.
|
@@ -62,6 +62,24 @@ MaximumDbConnections = 500
|
|||||||
MaximumDbIdleTime = 0
|
MaximumDbIdleTime = 0
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Automatic Database Backup Settings
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Generate database backups when server restarts or shuts down.
|
||||||
|
BackupDatabase = False
|
||||||
|
|
||||||
|
# Path to MySQL bin folder. Only necessary on Windows.
|
||||||
|
MySqlBinLocation = C:/xampp/mysql/bin/
|
||||||
|
|
||||||
|
# Path where MySQL backups are stored.
|
||||||
|
BackupPath = ../backup/
|
||||||
|
|
||||||
|
# Maximum number of days that backups will be kept.
|
||||||
|
# Old files in backup folder will be deleted.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
BackupDays = 30
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Misc Server Settings
|
# Misc Server Settings
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
@@ -62,6 +62,24 @@ MaximumDbConnections = 50
|
|||||||
MaximumDbIdleTime = 0
|
MaximumDbIdleTime = 0
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Automatic Database Backup Settings
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Generate database backups when server restarts or shuts down.
|
||||||
|
BackupDatabase = False
|
||||||
|
|
||||||
|
# Path to MySQL bin folder. Only necessary on Windows.
|
||||||
|
MySqlBinLocation = C:/xampp/mysql/bin/
|
||||||
|
|
||||||
|
# Path where MySQL backups are stored.
|
||||||
|
BackupPath = ../backup/
|
||||||
|
|
||||||
|
# Maximum number of days that backups will be kept.
|
||||||
|
# Old backups will be deleted.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
BackupDays = 30
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Security
|
# Security
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
@@ -747,6 +747,10 @@ public final class Config
|
|||||||
public static String DATABASE_PASSWORD;
|
public static String DATABASE_PASSWORD;
|
||||||
public static int DATABASE_MAX_CONNECTIONS;
|
public static int DATABASE_MAX_CONNECTIONS;
|
||||||
public static int DATABASE_MAX_IDLE_TIME;
|
public static int DATABASE_MAX_IDLE_TIME;
|
||||||
|
public static boolean BACKUP_DATABASE;
|
||||||
|
public static String MYSQL_BIN_PATH;
|
||||||
|
public static String BACKUP_PATH;
|
||||||
|
public static int BACKUP_DAYS;
|
||||||
public static int MAXIMUM_ONLINE_USERS;
|
public static int MAXIMUM_ONLINE_USERS;
|
||||||
public static boolean HARDWARE_INFO_ENABLED;
|
public static boolean HARDWARE_INFO_ENABLED;
|
||||||
public static int MAX_PLAYERS_PER_HWID;
|
public static int MAX_PLAYERS_PER_HWID;
|
||||||
@@ -1267,6 +1271,11 @@ public final class Config
|
|||||||
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
|
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
|
||||||
DATABASE_MAX_IDLE_TIME = serverSettings.getInt("MaximumDbIdleTime", 0);
|
DATABASE_MAX_IDLE_TIME = serverSettings.getInt("MaximumDbIdleTime", 0);
|
||||||
|
|
||||||
|
BACKUP_DATABASE = serverSettings.getBoolean("BackupDatabase", false);
|
||||||
|
MYSQL_BIN_PATH = serverSettings.getString("MySqlBinLocation", "C:/xampp/mysql/bin/");
|
||||||
|
BACKUP_PATH = serverSettings.getString("BackupPath", "../backup/");
|
||||||
|
BACKUP_DAYS = serverSettings.getInt("BackupDays", 30);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DATAPACK_ROOT = new File(serverSettings.getString("DatapackRoot", ".").replaceAll("\\\\", "/")).getCanonicalFile();
|
DATAPACK_ROOT = new File(serverSettings.getString("DatapackRoot", ".").replaceAll("\\\\", "/")).getCanonicalFile();
|
||||||
@@ -2942,6 +2951,11 @@ public final class Config
|
|||||||
DATABASE_MAX_CONNECTIONS = ServerSettings.getInt("MaximumDbConnections", 10);
|
DATABASE_MAX_CONNECTIONS = ServerSettings.getInt("MaximumDbConnections", 10);
|
||||||
DATABASE_MAX_IDLE_TIME = ServerSettings.getInt("MaximumDbIdleTime", 0);
|
DATABASE_MAX_IDLE_TIME = ServerSettings.getInt("MaximumDbIdleTime", 0);
|
||||||
|
|
||||||
|
BACKUP_DATABASE = ServerSettings.getBoolean("BackupDatabase", false);
|
||||||
|
MYSQL_BIN_PATH = ServerSettings.getString("MySqlBinLocation", "C:/xampp/mysql/bin/");
|
||||||
|
BACKUP_PATH = ServerSettings.getString("BackupPath", "../backup/");
|
||||||
|
BACKUP_DAYS = ServerSettings.getInt("BackupDays", 30);
|
||||||
|
|
||||||
SHOW_LICENCE = ServerSettings.getBoolean("ShowLicence", true);
|
SHOW_LICENCE = ServerSettings.getBoolean("ShowLicence", true);
|
||||||
SHOW_PI_AGREEMENT = ServerSettings.getBoolean("ShowPIAgreement", false);
|
SHOW_PI_AGREEMENT = ServerSettings.getBoolean("ShowPIAgreement", false);
|
||||||
|
|
||||||
|
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the L2J Mobius project.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.l2jmobius.commons.database;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import com.l2jmobius.Config;
|
||||||
|
import com.l2jmobius.Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class DatabaseBackup
|
||||||
|
{
|
||||||
|
public static void performBackup()
|
||||||
|
{
|
||||||
|
// Delete old files.
|
||||||
|
if (Config.BACKUP_DAYS > 0)
|
||||||
|
{
|
||||||
|
final long cut = LocalDateTime.now().minusDays(Config.BACKUP_DAYS).toEpochSecond(ZoneOffset.UTC);
|
||||||
|
final Path path = Paths.get(Config.BACKUP_PATH);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.list(path).filter(n ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Files.getLastModifiedTime(n).to(TimeUnit.SECONDS) < cut;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}).forEach(n ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.delete(n);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dump to file.
|
||||||
|
final String mysqldumpPath = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0 ? Config.MYSQL_BIN_PATH : "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mysql://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Server.serverMode == Server.MODE_GAMESERVER ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date()));
|
||||||
|
process.waitFor();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -21,6 +21,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.commons.concurrent.ThreadPool;
|
import com.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import com.l2jmobius.commons.database.DatabaseBackup;
|
||||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
|
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
|
||||||
import com.l2jmobius.gameserver.data.sql.impl.OfflineTradersTable;
|
import com.l2jmobius.gameserver.data.sql.impl.OfflineTradersTable;
|
||||||
@@ -269,6 +270,12 @@ public class Shutdown extends Thread
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Backup database.
|
||||||
|
if (Config.BACKUP_DATABASE)
|
||||||
|
{
|
||||||
|
DatabaseBackup.performBackup();
|
||||||
|
}
|
||||||
|
|
||||||
// server will quit, when this function ends.
|
// server will quit, when this function ends.
|
||||||
if (getInstance()._shutdownMode == GM_RESTART)
|
if (getInstance()._shutdownMode == GM_RESTART)
|
||||||
{
|
{
|
||||||
|
@@ -30,6 +30,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.Server;
|
import com.l2jmobius.Server;
|
||||||
|
import com.l2jmobius.commons.database.DatabaseBackup;
|
||||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import com.l2jmobius.loginserver.network.ClientNetworkManager;
|
import com.l2jmobius.loginserver.network.ClientNetworkManager;
|
||||||
|
|
||||||
@@ -206,6 +207,10 @@ public final class LoginServer
|
|||||||
|
|
||||||
public void shutdown(boolean restart)
|
public void shutdown(boolean restart)
|
||||||
{
|
{
|
||||||
|
if (Config.BACKUP_DATABASE)
|
||||||
|
{
|
||||||
|
DatabaseBackup.performBackup();
|
||||||
|
}
|
||||||
Runtime.getRuntime().exit(restart ? 2 : 0);
|
Runtime.getRuntime().exit(restart ? 2 : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -101,6 +101,7 @@ Customs:
|
|||||||
-Sell buffs
|
-Sell buffs
|
||||||
-Starting location
|
-Starting location
|
||||||
-Vote reward
|
-Vote reward
|
||||||
|
-Automated database backups
|
||||||
|
|
||||||
Others:
|
Others:
|
||||||
-Reworked tax system
|
-Reworked tax system
|
||||||
|
3
L2J_Mobius_2.5_Underground/dist/backup/readme.txt
vendored
Normal file
3
L2J_Mobius_2.5_Underground/dist/backup/readme.txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
MySQL backups are stored in this folder.
|
||||||
|
Separate game and login server backups are possible.
|
||||||
|
Just enable the 'BackupDatabase' option in the equivalent server config file.
|
@@ -62,6 +62,24 @@ MaximumDbConnections = 500
|
|||||||
MaximumDbIdleTime = 0
|
MaximumDbIdleTime = 0
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Automatic Database Backup Settings
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Generate database backups when server restarts or shuts down.
|
||||||
|
BackupDatabase = False
|
||||||
|
|
||||||
|
# Path to MySQL bin folder. Only necessary on Windows.
|
||||||
|
MySqlBinLocation = C:/xampp/mysql/bin/
|
||||||
|
|
||||||
|
# Path where MySQL backups are stored.
|
||||||
|
BackupPath = ../backup/
|
||||||
|
|
||||||
|
# Maximum number of days that backups will be kept.
|
||||||
|
# Old files in backup folder will be deleted.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
BackupDays = 30
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Misc Server Settings
|
# Misc Server Settings
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
@@ -62,6 +62,24 @@ MaximumDbConnections = 50
|
|||||||
MaximumDbIdleTime = 0
|
MaximumDbIdleTime = 0
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Automatic Database Backup Settings
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Generate database backups when server restarts or shuts down.
|
||||||
|
BackupDatabase = False
|
||||||
|
|
||||||
|
# Path to MySQL bin folder. Only necessary on Windows.
|
||||||
|
MySqlBinLocation = C:/xampp/mysql/bin/
|
||||||
|
|
||||||
|
# Path where MySQL backups are stored.
|
||||||
|
BackupPath = ../backup/
|
||||||
|
|
||||||
|
# Maximum number of days that backups will be kept.
|
||||||
|
# Old backups will be deleted.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
BackupDays = 30
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Security
|
# Security
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
@@ -754,6 +754,10 @@ public final class Config
|
|||||||
public static String DATABASE_PASSWORD;
|
public static String DATABASE_PASSWORD;
|
||||||
public static int DATABASE_MAX_CONNECTIONS;
|
public static int DATABASE_MAX_CONNECTIONS;
|
||||||
public static int DATABASE_MAX_IDLE_TIME;
|
public static int DATABASE_MAX_IDLE_TIME;
|
||||||
|
public static boolean BACKUP_DATABASE;
|
||||||
|
public static String MYSQL_BIN_PATH;
|
||||||
|
public static String BACKUP_PATH;
|
||||||
|
public static int BACKUP_DAYS;
|
||||||
public static int MAXIMUM_ONLINE_USERS;
|
public static int MAXIMUM_ONLINE_USERS;
|
||||||
public static boolean HARDWARE_INFO_ENABLED;
|
public static boolean HARDWARE_INFO_ENABLED;
|
||||||
public static int MAX_PLAYERS_PER_HWID;
|
public static int MAX_PLAYERS_PER_HWID;
|
||||||
@@ -1274,6 +1278,11 @@ public final class Config
|
|||||||
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
|
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
|
||||||
DATABASE_MAX_IDLE_TIME = serverSettings.getInt("MaximumDbIdleTime", 0);
|
DATABASE_MAX_IDLE_TIME = serverSettings.getInt("MaximumDbIdleTime", 0);
|
||||||
|
|
||||||
|
BACKUP_DATABASE = serverSettings.getBoolean("BackupDatabase", false);
|
||||||
|
MYSQL_BIN_PATH = serverSettings.getString("MySqlBinLocation", "C:/xampp/mysql/bin/");
|
||||||
|
BACKUP_PATH = serverSettings.getString("BackupPath", "../backup/");
|
||||||
|
BACKUP_DAYS = serverSettings.getInt("BackupDays", 30);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DATAPACK_ROOT = new File(serverSettings.getString("DatapackRoot", ".").replaceAll("\\\\", "/")).getCanonicalFile();
|
DATAPACK_ROOT = new File(serverSettings.getString("DatapackRoot", ".").replaceAll("\\\\", "/")).getCanonicalFile();
|
||||||
@@ -2958,6 +2967,11 @@ public final class Config
|
|||||||
DATABASE_MAX_CONNECTIONS = ServerSettings.getInt("MaximumDbConnections", 10);
|
DATABASE_MAX_CONNECTIONS = ServerSettings.getInt("MaximumDbConnections", 10);
|
||||||
DATABASE_MAX_IDLE_TIME = ServerSettings.getInt("MaximumDbIdleTime", 0);
|
DATABASE_MAX_IDLE_TIME = ServerSettings.getInt("MaximumDbIdleTime", 0);
|
||||||
|
|
||||||
|
BACKUP_DATABASE = ServerSettings.getBoolean("BackupDatabase", false);
|
||||||
|
MYSQL_BIN_PATH = ServerSettings.getString("MySqlBinLocation", "C:/xampp/mysql/bin/");
|
||||||
|
BACKUP_PATH = ServerSettings.getString("BackupPath", "../backup/");
|
||||||
|
BACKUP_DAYS = ServerSettings.getInt("BackupDays", 30);
|
||||||
|
|
||||||
SHOW_LICENCE = ServerSettings.getBoolean("ShowLicence", true);
|
SHOW_LICENCE = ServerSettings.getBoolean("ShowLicence", true);
|
||||||
SHOW_PI_AGREEMENT = ServerSettings.getBoolean("ShowPIAgreement", false);
|
SHOW_PI_AGREEMENT = ServerSettings.getBoolean("ShowPIAgreement", false);
|
||||||
|
|
||||||
|
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the L2J Mobius project.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.l2jmobius.commons.database;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import com.l2jmobius.Config;
|
||||||
|
import com.l2jmobius.Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class DatabaseBackup
|
||||||
|
{
|
||||||
|
public static void performBackup()
|
||||||
|
{
|
||||||
|
// Delete old files.
|
||||||
|
if (Config.BACKUP_DAYS > 0)
|
||||||
|
{
|
||||||
|
final long cut = LocalDateTime.now().minusDays(Config.BACKUP_DAYS).toEpochSecond(ZoneOffset.UTC);
|
||||||
|
final Path path = Paths.get(Config.BACKUP_PATH);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.list(path).filter(n ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Files.getLastModifiedTime(n).to(TimeUnit.SECONDS) < cut;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}).forEach(n ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.delete(n);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dump to file.
|
||||||
|
final String mysqldumpPath = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0 ? Config.MYSQL_BIN_PATH : "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mysql://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Server.serverMode == Server.MODE_GAMESERVER ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date()));
|
||||||
|
process.waitFor();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -21,6 +21,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.commons.concurrent.ThreadPool;
|
import com.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import com.l2jmobius.commons.database.DatabaseBackup;
|
||||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
|
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
|
||||||
import com.l2jmobius.gameserver.data.sql.impl.OfflineTradersTable;
|
import com.l2jmobius.gameserver.data.sql.impl.OfflineTradersTable;
|
||||||
@@ -269,6 +270,12 @@ public class Shutdown extends Thread
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Backup database.
|
||||||
|
if (Config.BACKUP_DATABASE)
|
||||||
|
{
|
||||||
|
DatabaseBackup.performBackup();
|
||||||
|
}
|
||||||
|
|
||||||
// server will quit, when this function ends.
|
// server will quit, when this function ends.
|
||||||
if (getInstance()._shutdownMode == GM_RESTART)
|
if (getInstance()._shutdownMode == GM_RESTART)
|
||||||
{
|
{
|
||||||
|
@@ -30,6 +30,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.Server;
|
import com.l2jmobius.Server;
|
||||||
|
import com.l2jmobius.commons.database.DatabaseBackup;
|
||||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import com.l2jmobius.loginserver.network.ClientNetworkManager;
|
import com.l2jmobius.loginserver.network.ClientNetworkManager;
|
||||||
|
|
||||||
@@ -206,6 +207,10 @@ public final class LoginServer
|
|||||||
|
|
||||||
public void shutdown(boolean restart)
|
public void shutdown(boolean restart)
|
||||||
{
|
{
|
||||||
|
if (Config.BACKUP_DATABASE)
|
||||||
|
{
|
||||||
|
DatabaseBackup.performBackup();
|
||||||
|
}
|
||||||
Runtime.getRuntime().exit(restart ? 2 : 0);
|
Runtime.getRuntime().exit(restart ? 2 : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -115,6 +115,7 @@ Customs:
|
|||||||
-Sell buffs
|
-Sell buffs
|
||||||
-Starting location
|
-Starting location
|
||||||
-Vote reward
|
-Vote reward
|
||||||
|
-Automated database backups
|
||||||
|
|
||||||
Others:
|
Others:
|
||||||
-Reworked tax system
|
-Reworked tax system
|
||||||
|
3
L2J_Mobius_3.0_Helios/dist/backup/readme.txt
vendored
Normal file
3
L2J_Mobius_3.0_Helios/dist/backup/readme.txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
MySQL backups are stored in this folder.
|
||||||
|
Separate game and login server backups are possible.
|
||||||
|
Just enable the 'BackupDatabase' option in the equivalent server config file.
|
@@ -62,6 +62,24 @@ MaximumDbConnections = 500
|
|||||||
MaximumDbIdleTime = 0
|
MaximumDbIdleTime = 0
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Automatic Database Backup Settings
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Generate database backups when server restarts or shuts down.
|
||||||
|
BackupDatabase = False
|
||||||
|
|
||||||
|
# Path to MySQL bin folder. Only necessary on Windows.
|
||||||
|
MySqlBinLocation = C:/xampp/mysql/bin/
|
||||||
|
|
||||||
|
# Path where MySQL backups are stored.
|
||||||
|
BackupPath = ../backup/
|
||||||
|
|
||||||
|
# Maximum number of days that backups will be kept.
|
||||||
|
# Old files in backup folder will be deleted.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
BackupDays = 30
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Misc Server Settings
|
# Misc Server Settings
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
@@ -62,6 +62,24 @@ MaximumDbConnections = 50
|
|||||||
MaximumDbIdleTime = 0
|
MaximumDbIdleTime = 0
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Automatic Database Backup Settings
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Generate database backups when server restarts or shuts down.
|
||||||
|
BackupDatabase = False
|
||||||
|
|
||||||
|
# Path to MySQL bin folder. Only necessary on Windows.
|
||||||
|
MySqlBinLocation = C:/xampp/mysql/bin/
|
||||||
|
|
||||||
|
# Path where MySQL backups are stored.
|
||||||
|
BackupPath = ../backup/
|
||||||
|
|
||||||
|
# Maximum number of days that backups will be kept.
|
||||||
|
# Old backups will be deleted.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
BackupDays = 30
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Security
|
# Security
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
@@ -755,6 +755,10 @@ public final class Config
|
|||||||
public static String DATABASE_PASSWORD;
|
public static String DATABASE_PASSWORD;
|
||||||
public static int DATABASE_MAX_CONNECTIONS;
|
public static int DATABASE_MAX_CONNECTIONS;
|
||||||
public static int DATABASE_MAX_IDLE_TIME;
|
public static int DATABASE_MAX_IDLE_TIME;
|
||||||
|
public static boolean BACKUP_DATABASE;
|
||||||
|
public static String MYSQL_BIN_PATH;
|
||||||
|
public static String BACKUP_PATH;
|
||||||
|
public static int BACKUP_DAYS;
|
||||||
public static int MAXIMUM_ONLINE_USERS;
|
public static int MAXIMUM_ONLINE_USERS;
|
||||||
public static boolean HARDWARE_INFO_ENABLED;
|
public static boolean HARDWARE_INFO_ENABLED;
|
||||||
public static int MAX_PLAYERS_PER_HWID;
|
public static int MAX_PLAYERS_PER_HWID;
|
||||||
@@ -1282,6 +1286,11 @@ public final class Config
|
|||||||
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
|
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
|
||||||
DATABASE_MAX_IDLE_TIME = serverSettings.getInt("MaximumDbIdleTime", 0);
|
DATABASE_MAX_IDLE_TIME = serverSettings.getInt("MaximumDbIdleTime", 0);
|
||||||
|
|
||||||
|
BACKUP_DATABASE = serverSettings.getBoolean("BackupDatabase", false);
|
||||||
|
MYSQL_BIN_PATH = serverSettings.getString("MySqlBinLocation", "C:/xampp/mysql/bin/");
|
||||||
|
BACKUP_PATH = serverSettings.getString("BackupPath", "../backup/");
|
||||||
|
BACKUP_DAYS = serverSettings.getInt("BackupDays", 30);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DATAPACK_ROOT = new File(serverSettings.getString("DatapackRoot", ".").replaceAll("\\\\", "/")).getCanonicalFile();
|
DATAPACK_ROOT = new File(serverSettings.getString("DatapackRoot", ".").replaceAll("\\\\", "/")).getCanonicalFile();
|
||||||
@@ -2975,6 +2984,11 @@ public final class Config
|
|||||||
DATABASE_MAX_CONNECTIONS = ServerSettings.getInt("MaximumDbConnections", 10);
|
DATABASE_MAX_CONNECTIONS = ServerSettings.getInt("MaximumDbConnections", 10);
|
||||||
DATABASE_MAX_IDLE_TIME = ServerSettings.getInt("MaximumDbIdleTime", 0);
|
DATABASE_MAX_IDLE_TIME = ServerSettings.getInt("MaximumDbIdleTime", 0);
|
||||||
|
|
||||||
|
BACKUP_DATABASE = ServerSettings.getBoolean("BackupDatabase", false);
|
||||||
|
MYSQL_BIN_PATH = ServerSettings.getString("MySqlBinLocation", "C:/xampp/mysql/bin/");
|
||||||
|
BACKUP_PATH = ServerSettings.getString("BackupPath", "../backup/");
|
||||||
|
BACKUP_DAYS = ServerSettings.getInt("BackupDays", 30);
|
||||||
|
|
||||||
SHOW_LICENCE = ServerSettings.getBoolean("ShowLicence", true);
|
SHOW_LICENCE = ServerSettings.getBoolean("ShowLicence", true);
|
||||||
SHOW_PI_AGREEMENT = ServerSettings.getBoolean("ShowPIAgreement", false);
|
SHOW_PI_AGREEMENT = ServerSettings.getBoolean("ShowPIAgreement", false);
|
||||||
|
|
||||||
|
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the L2J Mobius project.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.l2jmobius.commons.database;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import com.l2jmobius.Config;
|
||||||
|
import com.l2jmobius.Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class DatabaseBackup
|
||||||
|
{
|
||||||
|
public static void performBackup()
|
||||||
|
{
|
||||||
|
// Delete old files.
|
||||||
|
if (Config.BACKUP_DAYS > 0)
|
||||||
|
{
|
||||||
|
final long cut = LocalDateTime.now().minusDays(Config.BACKUP_DAYS).toEpochSecond(ZoneOffset.UTC);
|
||||||
|
final Path path = Paths.get(Config.BACKUP_PATH);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.list(path).filter(n ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Files.getLastModifiedTime(n).to(TimeUnit.SECONDS) < cut;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}).forEach(n ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.delete(n);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dump to file.
|
||||||
|
final String mysqldumpPath = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0 ? Config.MYSQL_BIN_PATH : "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mysql://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Server.serverMode == Server.MODE_GAMESERVER ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date()));
|
||||||
|
process.waitFor();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -21,6 +21,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.commons.concurrent.ThreadPool;
|
import com.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import com.l2jmobius.commons.database.DatabaseBackup;
|
||||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
|
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
|
||||||
import com.l2jmobius.gameserver.data.sql.impl.OfflineTradersTable;
|
import com.l2jmobius.gameserver.data.sql.impl.OfflineTradersTable;
|
||||||
@@ -269,6 +270,12 @@ public class Shutdown extends Thread
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Backup database.
|
||||||
|
if (Config.BACKUP_DATABASE)
|
||||||
|
{
|
||||||
|
DatabaseBackup.performBackup();
|
||||||
|
}
|
||||||
|
|
||||||
// server will quit, when this function ends.
|
// server will quit, when this function ends.
|
||||||
if (getInstance()._shutdownMode == GM_RESTART)
|
if (getInstance()._shutdownMode == GM_RESTART)
|
||||||
{
|
{
|
||||||
|
@@ -30,6 +30,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.Server;
|
import com.l2jmobius.Server;
|
||||||
|
import com.l2jmobius.commons.database.DatabaseBackup;
|
||||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import com.l2jmobius.loginserver.network.ClientNetworkManager;
|
import com.l2jmobius.loginserver.network.ClientNetworkManager;
|
||||||
|
|
||||||
@@ -206,6 +207,10 @@ public final class LoginServer
|
|||||||
|
|
||||||
public void shutdown(boolean restart)
|
public void shutdown(boolean restart)
|
||||||
{
|
{
|
||||||
|
if (Config.BACKUP_DATABASE)
|
||||||
|
{
|
||||||
|
DatabaseBackup.performBackup();
|
||||||
|
}
|
||||||
Runtime.getRuntime().exit(restart ? 2 : 0);
|
Runtime.getRuntime().exit(restart ? 2 : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -124,6 +124,7 @@ Customs:
|
|||||||
-Sell buffs
|
-Sell buffs
|
||||||
-Starting location
|
-Starting location
|
||||||
-Vote reward
|
-Vote reward
|
||||||
|
-Automated database backups
|
||||||
|
|
||||||
Others:
|
Others:
|
||||||
-Reworked tax system
|
-Reworked tax system
|
||||||
|
3
L2J_Mobius_4.0_GrandCrusade/dist/backup/readme.txt
vendored
Normal file
3
L2J_Mobius_4.0_GrandCrusade/dist/backup/readme.txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
MySQL backups are stored in this folder.
|
||||||
|
Separate game and login server backups are possible.
|
||||||
|
Just enable the 'BackupDatabase' option in the equivalent server config file.
|
@@ -62,6 +62,24 @@ MaximumDbConnections = 500
|
|||||||
MaximumDbIdleTime = 0
|
MaximumDbIdleTime = 0
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Automatic Database Backup Settings
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Generate database backups when server restarts or shuts down.
|
||||||
|
BackupDatabase = False
|
||||||
|
|
||||||
|
# Path to MySQL bin folder. Only necessary on Windows.
|
||||||
|
MySqlBinLocation = C:/xampp/mysql/bin/
|
||||||
|
|
||||||
|
# Path where MySQL backups are stored.
|
||||||
|
BackupPath = ../backup/
|
||||||
|
|
||||||
|
# Maximum number of days that backups will be kept.
|
||||||
|
# Old files in backup folder will be deleted.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
BackupDays = 30
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Misc Server Settings
|
# Misc Server Settings
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
@@ -62,6 +62,24 @@ MaximumDbConnections = 50
|
|||||||
MaximumDbIdleTime = 0
|
MaximumDbIdleTime = 0
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Automatic Database Backup Settings
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Generate database backups when server restarts or shuts down.
|
||||||
|
BackupDatabase = False
|
||||||
|
|
||||||
|
# Path to MySQL bin folder. Only necessary on Windows.
|
||||||
|
MySqlBinLocation = C:/xampp/mysql/bin/
|
||||||
|
|
||||||
|
# Path where MySQL backups are stored.
|
||||||
|
BackupPath = ../backup/
|
||||||
|
|
||||||
|
# Maximum number of days that backups will be kept.
|
||||||
|
# Old backups will be deleted.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
BackupDays = 30
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Security
|
# Security
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
@@ -754,6 +754,10 @@ public final class Config
|
|||||||
public static String DATABASE_PASSWORD;
|
public static String DATABASE_PASSWORD;
|
||||||
public static int DATABASE_MAX_CONNECTIONS;
|
public static int DATABASE_MAX_CONNECTIONS;
|
||||||
public static int DATABASE_MAX_IDLE_TIME;
|
public static int DATABASE_MAX_IDLE_TIME;
|
||||||
|
public static boolean BACKUP_DATABASE;
|
||||||
|
public static String MYSQL_BIN_PATH;
|
||||||
|
public static String BACKUP_PATH;
|
||||||
|
public static int BACKUP_DAYS;
|
||||||
public static int MAXIMUM_ONLINE_USERS;
|
public static int MAXIMUM_ONLINE_USERS;
|
||||||
public static boolean HARDWARE_INFO_ENABLED;
|
public static boolean HARDWARE_INFO_ENABLED;
|
||||||
public static int MAX_PLAYERS_PER_HWID;
|
public static int MAX_PLAYERS_PER_HWID;
|
||||||
@@ -1281,6 +1285,11 @@ public final class Config
|
|||||||
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
|
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
|
||||||
DATABASE_MAX_IDLE_TIME = serverSettings.getInt("MaximumDbIdleTime", 0);
|
DATABASE_MAX_IDLE_TIME = serverSettings.getInt("MaximumDbIdleTime", 0);
|
||||||
|
|
||||||
|
BACKUP_DATABASE = serverSettings.getBoolean("BackupDatabase", false);
|
||||||
|
MYSQL_BIN_PATH = serverSettings.getString("MySqlBinLocation", "C:/xampp/mysql/bin/");
|
||||||
|
BACKUP_PATH = serverSettings.getString("BackupPath", "../backup/");
|
||||||
|
BACKUP_DAYS = serverSettings.getInt("BackupDays", 30);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DATAPACK_ROOT = new File(serverSettings.getString("DatapackRoot", ".").replaceAll("\\\\", "/")).getCanonicalFile();
|
DATAPACK_ROOT = new File(serverSettings.getString("DatapackRoot", ".").replaceAll("\\\\", "/")).getCanonicalFile();
|
||||||
@@ -2973,6 +2982,11 @@ public final class Config
|
|||||||
DATABASE_MAX_CONNECTIONS = ServerSettings.getInt("MaximumDbConnections", 10);
|
DATABASE_MAX_CONNECTIONS = ServerSettings.getInt("MaximumDbConnections", 10);
|
||||||
DATABASE_MAX_IDLE_TIME = ServerSettings.getInt("MaximumDbIdleTime", 0);
|
DATABASE_MAX_IDLE_TIME = ServerSettings.getInt("MaximumDbIdleTime", 0);
|
||||||
|
|
||||||
|
BACKUP_DATABASE = ServerSettings.getBoolean("BackupDatabase", false);
|
||||||
|
MYSQL_BIN_PATH = ServerSettings.getString("MySqlBinLocation", "C:/xampp/mysql/bin/");
|
||||||
|
BACKUP_PATH = ServerSettings.getString("BackupPath", "../backup/");
|
||||||
|
BACKUP_DAYS = ServerSettings.getInt("BackupDays", 30);
|
||||||
|
|
||||||
SHOW_LICENCE = ServerSettings.getBoolean("ShowLicence", true);
|
SHOW_LICENCE = ServerSettings.getBoolean("ShowLicence", true);
|
||||||
SHOW_PI_AGREEMENT = ServerSettings.getBoolean("ShowPIAgreement", false);
|
SHOW_PI_AGREEMENT = ServerSettings.getBoolean("ShowPIAgreement", false);
|
||||||
|
|
||||||
|
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the L2J Mobius project.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.l2jmobius.commons.database;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import com.l2jmobius.Config;
|
||||||
|
import com.l2jmobius.Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class DatabaseBackup
|
||||||
|
{
|
||||||
|
public static void performBackup()
|
||||||
|
{
|
||||||
|
// Delete old files.
|
||||||
|
if (Config.BACKUP_DAYS > 0)
|
||||||
|
{
|
||||||
|
final long cut = LocalDateTime.now().minusDays(Config.BACKUP_DAYS).toEpochSecond(ZoneOffset.UTC);
|
||||||
|
final Path path = Paths.get(Config.BACKUP_PATH);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.list(path).filter(n ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Files.getLastModifiedTime(n).to(TimeUnit.SECONDS) < cut;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}).forEach(n ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.delete(n);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dump to file.
|
||||||
|
final String mysqldumpPath = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0 ? Config.MYSQL_BIN_PATH : "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mysql://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Server.serverMode == Server.MODE_GAMESERVER ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date()));
|
||||||
|
process.waitFor();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -21,6 +21,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.commons.concurrent.ThreadPool;
|
import com.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import com.l2jmobius.commons.database.DatabaseBackup;
|
||||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
|
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
|
||||||
import com.l2jmobius.gameserver.data.sql.impl.OfflineTradersTable;
|
import com.l2jmobius.gameserver.data.sql.impl.OfflineTradersTable;
|
||||||
@@ -269,6 +270,12 @@ public class Shutdown extends Thread
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Backup database.
|
||||||
|
if (Config.BACKUP_DATABASE)
|
||||||
|
{
|
||||||
|
DatabaseBackup.performBackup();
|
||||||
|
}
|
||||||
|
|
||||||
// server will quit, when this function ends.
|
// server will quit, when this function ends.
|
||||||
if (getInstance()._shutdownMode == GM_RESTART)
|
if (getInstance()._shutdownMode == GM_RESTART)
|
||||||
{
|
{
|
||||||
|
@@ -30,6 +30,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.Server;
|
import com.l2jmobius.Server;
|
||||||
|
import com.l2jmobius.commons.database.DatabaseBackup;
|
||||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import com.l2jmobius.loginserver.network.ClientNetworkManager;
|
import com.l2jmobius.loginserver.network.ClientNetworkManager;
|
||||||
|
|
||||||
@@ -206,6 +207,10 @@ public final class LoginServer
|
|||||||
|
|
||||||
public void shutdown(boolean restart)
|
public void shutdown(boolean restart)
|
||||||
{
|
{
|
||||||
|
if (Config.BACKUP_DATABASE)
|
||||||
|
{
|
||||||
|
DatabaseBackup.performBackup();
|
||||||
|
}
|
||||||
Runtime.getRuntime().exit(restart ? 2 : 0);
|
Runtime.getRuntime().exit(restart ? 2 : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -128,6 +128,7 @@ Customs:
|
|||||||
-Sell buffs
|
-Sell buffs
|
||||||
-Starting location
|
-Starting location
|
||||||
-Vote reward
|
-Vote reward
|
||||||
|
-Automated database backups
|
||||||
|
|
||||||
Others:
|
Others:
|
||||||
-Reworked tax system
|
-Reworked tax system
|
||||||
|
3
L2J_Mobius_C6_Interlude/dist/backup/readme.txt
vendored
Normal file
3
L2J_Mobius_C6_Interlude/dist/backup/readme.txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
MySQL backups are stored in this folder.
|
||||||
|
Separate game and login server backups are possible.
|
||||||
|
Just enable the 'BackupDatabase' option in the equivalent server config file.
|
@@ -57,6 +57,25 @@ MaximumDbConnections = 50
|
|||||||
# Default: 0
|
# Default: 0
|
||||||
MaximumDbIdleTime = 0
|
MaximumDbIdleTime = 0
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Automatic Database Backup Settings
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Generate database backups when server restarts or shuts down.
|
||||||
|
BackupDatabase = False
|
||||||
|
|
||||||
|
# Path to MySQL bin folder. Only necessary on Windows.
|
||||||
|
MySqlBinLocation = C:/xampp/mysql/bin/
|
||||||
|
|
||||||
|
# Path where MySQL backups are stored.
|
||||||
|
BackupPath = ../backup/
|
||||||
|
|
||||||
|
# Maximum number of days that backups will be kept.
|
||||||
|
# Old backups will be deleted.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
BackupDays = 30
|
||||||
|
|
||||||
|
|
||||||
# Setting emulation off the kernel (package SendStatus)
|
# Setting emulation off the kernel (package SendStatus)
|
||||||
RemoteWhoLog = True
|
RemoteWhoLog = True
|
||||||
RemoteWhoSendTrash = True
|
RemoteWhoSendTrash = True
|
||||||
|
@@ -67,6 +67,25 @@ MaximumDbConnections = 50
|
|||||||
# Default: 0
|
# Default: 0
|
||||||
MaximumDbIdleTime = 0
|
MaximumDbIdleTime = 0
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Automatic Database Backup Settings
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Generate database backups when server restarts or shuts down.
|
||||||
|
BackupDatabase = False
|
||||||
|
|
||||||
|
# Path to MySQL bin folder. Only necessary on Windows.
|
||||||
|
MySqlBinLocation = C:/xampp/mysql/bin/
|
||||||
|
|
||||||
|
# Path where MySQL backups are stored.
|
||||||
|
BackupPath = ../backup/
|
||||||
|
|
||||||
|
# Maximum number of days that backups will be kept.
|
||||||
|
# Old backups will be deleted.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
BackupDays = 30
|
||||||
|
|
||||||
|
|
||||||
# Limit fast connections (input username / password)
|
# Limit fast connections (input username / password)
|
||||||
FastConnectionLimit = 15
|
FastConnectionLimit = 15
|
||||||
# Time of the normal connection (in ms)
|
# Time of the normal connection (in ms)
|
||||||
|
@@ -212,6 +212,10 @@ public final class Config
|
|||||||
public static String DATABASE_PASSWORD;
|
public static String DATABASE_PASSWORD;
|
||||||
public static int DATABASE_MAX_CONNECTIONS;
|
public static int DATABASE_MAX_CONNECTIONS;
|
||||||
public static int DATABASE_MAX_IDLE_TIME;
|
public static int DATABASE_MAX_IDLE_TIME;
|
||||||
|
public static boolean BACKUP_DATABASE;
|
||||||
|
public static String MYSQL_BIN_PATH;
|
||||||
|
public static String BACKUP_PATH;
|
||||||
|
public static int BACKUP_DAYS;
|
||||||
public static boolean RESERVE_HOST_ON_LOGIN = false;
|
public static boolean RESERVE_HOST_ON_LOGIN = false;
|
||||||
public static boolean RWHO_LOG;
|
public static boolean RWHO_LOG;
|
||||||
public static int RWHO_FORCE_INC;
|
public static int RWHO_FORCE_INC;
|
||||||
@@ -1367,6 +1371,11 @@ public final class Config
|
|||||||
DATABASE_MAX_CONNECTIONS = Integer.parseInt(serverSettings.getProperty("MaximumDbConnections", "10"));
|
DATABASE_MAX_CONNECTIONS = Integer.parseInt(serverSettings.getProperty("MaximumDbConnections", "10"));
|
||||||
DATABASE_MAX_IDLE_TIME = Integer.parseInt(serverSettings.getProperty("MaximumDbIdleTime", "0"));
|
DATABASE_MAX_IDLE_TIME = Integer.parseInt(serverSettings.getProperty("MaximumDbIdleTime", "0"));
|
||||||
|
|
||||||
|
BACKUP_DATABASE = Boolean.valueOf(serverSettings.getProperty("BackupDatabase", "false"));
|
||||||
|
MYSQL_BIN_PATH = serverSettings.getProperty("MySqlBinLocation", "C:/xampp/mysql/bin/");
|
||||||
|
BACKUP_PATH = serverSettings.getProperty("BackupPath", "../backup/");
|
||||||
|
BACKUP_DAYS = Integer.parseInt(serverSettings.getProperty("BackupDays", "30"));
|
||||||
|
|
||||||
DATAPACK_ROOT = new File(serverSettings.getProperty("DatapackRoot", ".")).getCanonicalFile();
|
DATAPACK_ROOT = new File(serverSettings.getProperty("DatapackRoot", ".")).getCanonicalFile();
|
||||||
|
|
||||||
final Random ppc = new Random();
|
final Random ppc = new Random();
|
||||||
@@ -3816,6 +3825,11 @@ public final class Config
|
|||||||
DATABASE_MAX_CONNECTIONS = Integer.parseInt(serverSettings.getProperty("MaximumDbConnections", "10"));
|
DATABASE_MAX_CONNECTIONS = Integer.parseInt(serverSettings.getProperty("MaximumDbConnections", "10"));
|
||||||
DATABASE_MAX_IDLE_TIME = Integer.parseInt(serverSettings.getProperty("MaximumDbIdleTime", "0"));
|
DATABASE_MAX_IDLE_TIME = Integer.parseInt(serverSettings.getProperty("MaximumDbIdleTime", "0"));
|
||||||
|
|
||||||
|
BACKUP_DATABASE = Boolean.valueOf(serverSettings.getProperty("BackupDatabase", "false"));
|
||||||
|
MYSQL_BIN_PATH = serverSettings.getProperty("MySqlBinLocation", "C:/xampp/mysql/bin/");
|
||||||
|
BACKUP_PATH = serverSettings.getProperty("BackupPath", "../backup/");
|
||||||
|
BACKUP_DAYS = Integer.parseInt(serverSettings.getProperty("BackupDays", "30"));
|
||||||
|
|
||||||
// Anti Brute force attack on login
|
// Anti Brute force attack on login
|
||||||
BRUT_AVG_TIME = Integer.parseInt(serverSettings.getProperty("BrutAvgTime", "30")); // in Seconds
|
BRUT_AVG_TIME = Integer.parseInt(serverSettings.getProperty("BrutAvgTime", "30")); // in Seconds
|
||||||
BRUT_LOGON_ATTEMPTS = Integer.parseInt(serverSettings.getProperty("BrutLogonAttempts", "15"));
|
BRUT_LOGON_ATTEMPTS = Integer.parseInt(serverSettings.getProperty("BrutLogonAttempts", "15"));
|
||||||
|
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the L2J Mobius project.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.l2jmobius.commons.database;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import com.l2jmobius.Config;
|
||||||
|
import com.l2jmobius.Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class DatabaseBackup
|
||||||
|
{
|
||||||
|
public static void performBackup()
|
||||||
|
{
|
||||||
|
// Delete old files.
|
||||||
|
if (Config.BACKUP_DAYS > 0)
|
||||||
|
{
|
||||||
|
final long cut = LocalDateTime.now().minusDays(Config.BACKUP_DAYS).toEpochSecond(ZoneOffset.UTC);
|
||||||
|
final Path path = Paths.get(Config.BACKUP_PATH);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.list(path).filter(n ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Files.getLastModifiedTime(n).to(TimeUnit.SECONDS) < cut;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}).forEach(n ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.delete(n);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dump to file.
|
||||||
|
final String mysqldumpPath = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0 ? Config.MYSQL_BIN_PATH : "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mysql://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Server.serverMode == Server.MODE_GAMESERVER ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date()));
|
||||||
|
process.waitFor();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -20,6 +20,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.commons.concurrent.ThreadPool;
|
import com.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import com.l2jmobius.commons.database.DatabaseBackup;
|
||||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import com.l2jmobius.gameserver.datatables.BufferTable;
|
import com.l2jmobius.gameserver.datatables.BufferTable;
|
||||||
import com.l2jmobius.gameserver.datatables.OfflineTradeTable;
|
import com.l2jmobius.gameserver.datatables.OfflineTradeTable;
|
||||||
@@ -480,6 +481,12 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
LOGGER.info("All database data committed.");
|
LOGGER.info("All database data committed.");
|
||||||
|
|
||||||
|
// Backup database.
|
||||||
|
if (Config.BACKUP_DATABASE)
|
||||||
|
{
|
||||||
|
DatabaseBackup.performBackup();
|
||||||
|
}
|
||||||
|
|
||||||
System.runFinalization();
|
System.runFinalization();
|
||||||
System.gc();
|
System.gc();
|
||||||
|
|
||||||
|
@@ -28,6 +28,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.Server;
|
import com.l2jmobius.Server;
|
||||||
|
import com.l2jmobius.commons.database.DatabaseBackup;
|
||||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import com.l2jmobius.commons.mmocore.NetcoreConfig;
|
import com.l2jmobius.commons.mmocore.NetcoreConfig;
|
||||||
import com.l2jmobius.commons.mmocore.SelectorConfig;
|
import com.l2jmobius.commons.mmocore.SelectorConfig;
|
||||||
@@ -189,6 +190,12 @@ public class LoginServer
|
|||||||
|
|
||||||
public void shutdown(boolean restart)
|
public void shutdown(boolean restart)
|
||||||
{
|
{
|
||||||
|
// Backup database.
|
||||||
|
if (Config.BACKUP_DATABASE)
|
||||||
|
{
|
||||||
|
DatabaseBackup.performBackup();
|
||||||
|
}
|
||||||
|
|
||||||
LoginController.getInstance().shutdown();
|
LoginController.getInstance().shutdown();
|
||||||
System.gc();
|
System.gc();
|
||||||
Runtime.getRuntime().exit(restart ? 2 : 0);
|
Runtime.getRuntime().exit(restart ? 2 : 0);
|
||||||
|
3
L2J_Mobius_CT_2.6_HighFive/dist/backup/readme.txt
vendored
Normal file
3
L2J_Mobius_CT_2.6_HighFive/dist/backup/readme.txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
MySQL backups are stored in this folder.
|
||||||
|
Separate game and login server backups are possible.
|
||||||
|
Just enable the 'BackupDatabase' option in the equivalent server config file.
|
@@ -62,6 +62,24 @@ MaximumDbConnections = 500
|
|||||||
MaximumDbIdleTime = 0
|
MaximumDbIdleTime = 0
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Automatic Database Backup Settings
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Generate database backups when server restarts or shuts down.
|
||||||
|
BackupDatabase = False
|
||||||
|
|
||||||
|
# Path to MySQL bin folder. Only necessary on Windows.
|
||||||
|
MySqlBinLocation = C:/xampp/mysql/bin/
|
||||||
|
|
||||||
|
# Path where MySQL backups are stored.
|
||||||
|
BackupPath = ../backup/
|
||||||
|
|
||||||
|
# Maximum number of days that backups will be kept.
|
||||||
|
# Old files in backup folder will be deleted.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
BackupDays = 30
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Misc Server Settings
|
# Misc Server Settings
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
@@ -62,6 +62,24 @@ MaximumDbConnections = 50
|
|||||||
MaximumDbIdleTime = 0
|
MaximumDbIdleTime = 0
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Automatic Database Backup Settings
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Generate database backups when server restarts or shuts down.
|
||||||
|
BackupDatabase = False
|
||||||
|
|
||||||
|
# Path to MySQL bin folder. Only necessary on Windows.
|
||||||
|
MySqlBinLocation = C:/xampp/mysql/bin/
|
||||||
|
|
||||||
|
# Path where MySQL backups are stored.
|
||||||
|
BackupPath = ../backup/
|
||||||
|
|
||||||
|
# Maximum number of days that backups will be kept.
|
||||||
|
# Old backups will be deleted.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
BackupDays = 30
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Security
|
# Security
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
@@ -859,6 +859,10 @@ public final class Config
|
|||||||
public static String DATABASE_PASSWORD;
|
public static String DATABASE_PASSWORD;
|
||||||
public static int DATABASE_MAX_CONNECTIONS;
|
public static int DATABASE_MAX_CONNECTIONS;
|
||||||
public static int DATABASE_MAX_IDLE_TIME;
|
public static int DATABASE_MAX_IDLE_TIME;
|
||||||
|
public static boolean BACKUP_DATABASE;
|
||||||
|
public static String MYSQL_BIN_PATH;
|
||||||
|
public static String BACKUP_PATH;
|
||||||
|
public static int BACKUP_DAYS;
|
||||||
public static int MAXIMUM_ONLINE_USERS;
|
public static int MAXIMUM_ONLINE_USERS;
|
||||||
public static String CNAME_TEMPLATE;
|
public static String CNAME_TEMPLATE;
|
||||||
public static String PET_NAME_TEMPLATE;
|
public static String PET_NAME_TEMPLATE;
|
||||||
@@ -1374,6 +1378,11 @@ public final class Config
|
|||||||
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
|
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
|
||||||
DATABASE_MAX_IDLE_TIME = serverSettings.getInt("MaximumDbIdleTime", 0);
|
DATABASE_MAX_IDLE_TIME = serverSettings.getInt("MaximumDbIdleTime", 0);
|
||||||
|
|
||||||
|
BACKUP_DATABASE = serverSettings.getBoolean("BackupDatabase", false);
|
||||||
|
MYSQL_BIN_PATH = serverSettings.getString("MySqlBinLocation", "C:/xampp/mysql/bin/");
|
||||||
|
BACKUP_PATH = serverSettings.getString("BackupPath", "../backup/");
|
||||||
|
BACKUP_DAYS = serverSettings.getInt("BackupDays", 30);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DATAPACK_ROOT = new File(serverSettings.getString("DatapackRoot", ".").replaceAll("\\\\", "/")).getCanonicalFile();
|
DATAPACK_ROOT = new File(serverSettings.getString("DatapackRoot", ".").replaceAll("\\\\", "/")).getCanonicalFile();
|
||||||
@@ -3332,6 +3341,11 @@ public final class Config
|
|||||||
DATABASE_MAX_CONNECTIONS = ServerSettings.getInt("MaximumDbConnections", 10);
|
DATABASE_MAX_CONNECTIONS = ServerSettings.getInt("MaximumDbConnections", 10);
|
||||||
DATABASE_MAX_IDLE_TIME = ServerSettings.getInt("MaximumDbIdleTime", 0);
|
DATABASE_MAX_IDLE_TIME = ServerSettings.getInt("MaximumDbIdleTime", 0);
|
||||||
|
|
||||||
|
BACKUP_DATABASE = ServerSettings.getBoolean("BackupDatabase", false);
|
||||||
|
MYSQL_BIN_PATH = ServerSettings.getString("MySqlBinLocation", "C:/xampp/mysql/bin/");
|
||||||
|
BACKUP_PATH = ServerSettings.getString("BackupPath", "../backup/");
|
||||||
|
BACKUP_DAYS = ServerSettings.getInt("BackupDays", 30);
|
||||||
|
|
||||||
SHOW_LICENCE = ServerSettings.getBoolean("ShowLicence", true);
|
SHOW_LICENCE = ServerSettings.getBoolean("ShowLicence", true);
|
||||||
|
|
||||||
AUTO_CREATE_ACCOUNTS = ServerSettings.getBoolean("AutoCreateAccounts", true);
|
AUTO_CREATE_ACCOUNTS = ServerSettings.getBoolean("AutoCreateAccounts", true);
|
||||||
|
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the L2J Mobius project.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.l2jmobius.commons.database;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import com.l2jmobius.Config;
|
||||||
|
import com.l2jmobius.Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class DatabaseBackup
|
||||||
|
{
|
||||||
|
public static void performBackup()
|
||||||
|
{
|
||||||
|
// Delete old files.
|
||||||
|
if (Config.BACKUP_DAYS > 0)
|
||||||
|
{
|
||||||
|
final long cut = LocalDateTime.now().minusDays(Config.BACKUP_DAYS).toEpochSecond(ZoneOffset.UTC);
|
||||||
|
final Path path = Paths.get(Config.BACKUP_PATH);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.list(path).filter(n ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Files.getLastModifiedTime(n).to(TimeUnit.SECONDS) < cut;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}).forEach(n ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.delete(n);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dump to file.
|
||||||
|
final String mysqldumpPath = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0 ? Config.MYSQL_BIN_PATH : "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mysql://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Server.serverMode == Server.MODE_GAMESERVER ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date()));
|
||||||
|
process.waitFor();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -21,6 +21,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.commons.concurrent.ThreadPool;
|
import com.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import com.l2jmobius.commons.database.DatabaseBackup;
|
||||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
|
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
|
||||||
import com.l2jmobius.gameserver.data.sql.impl.OfflineTradersTable;
|
import com.l2jmobius.gameserver.data.sql.impl.OfflineTradersTable;
|
||||||
@@ -270,6 +271,12 @@ public class Shutdown extends Thread
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Backup database.
|
||||||
|
if (Config.BACKUP_DATABASE)
|
||||||
|
{
|
||||||
|
DatabaseBackup.performBackup();
|
||||||
|
}
|
||||||
|
|
||||||
// server will quit, when this function ends.
|
// server will quit, when this function ends.
|
||||||
if (getInstance()._shutdownMode == GM_RESTART)
|
if (getInstance()._shutdownMode == GM_RESTART)
|
||||||
{
|
{
|
||||||
|
@@ -30,6 +30,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.Server;
|
import com.l2jmobius.Server;
|
||||||
|
import com.l2jmobius.commons.database.DatabaseBackup;
|
||||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import com.l2jmobius.loginserver.network.ClientNetworkManager;
|
import com.l2jmobius.loginserver.network.ClientNetworkManager;
|
||||||
|
|
||||||
@@ -206,6 +207,10 @@ public final class LoginServer
|
|||||||
|
|
||||||
public void shutdown(boolean restart)
|
public void shutdown(boolean restart)
|
||||||
{
|
{
|
||||||
|
if (Config.BACKUP_DATABASE)
|
||||||
|
{
|
||||||
|
DatabaseBackup.performBackup();
|
||||||
|
}
|
||||||
Runtime.getRuntime().exit(restart ? 2 : 0);
|
Runtime.getRuntime().exit(restart ? 2 : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -35,3 +35,4 @@ What is done
|
|||||||
-Dropped knownlists
|
-Dropped knownlists
|
||||||
-Faction System (Good vs Evil)
|
-Faction System (Good vs Evil)
|
||||||
-Fake players
|
-Fake players
|
||||||
|
-Automated database backups
|
||||||
|
3
L2J_Mobius_Classic_2.0_Saviors/dist/backup/readme.txt
vendored
Normal file
3
L2J_Mobius_Classic_2.0_Saviors/dist/backup/readme.txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
MySQL backups are stored in this folder.
|
||||||
|
Separate game and login server backups are possible.
|
||||||
|
Just enable the 'BackupDatabase' option in the equivalent server config file.
|
@@ -62,6 +62,24 @@ MaximumDbConnections = 500
|
|||||||
MaximumDbIdleTime = 0
|
MaximumDbIdleTime = 0
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Automatic Database Backup Settings
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Generate database backups when server restarts or shuts down.
|
||||||
|
BackupDatabase = False
|
||||||
|
|
||||||
|
# Path to MySQL bin folder. Only necessary on Windows.
|
||||||
|
MySqlBinLocation = C:/xampp/mysql/bin/
|
||||||
|
|
||||||
|
# Path where MySQL backups are stored.
|
||||||
|
BackupPath = ../backup/
|
||||||
|
|
||||||
|
# Maximum number of days that backups will be kept.
|
||||||
|
# Old files in backup folder will be deleted.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
BackupDays = 30
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Misc Server Settings
|
# Misc Server Settings
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
@@ -62,6 +62,24 @@ MaximumDbConnections = 50
|
|||||||
MaximumDbIdleTime = 0
|
MaximumDbIdleTime = 0
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Automatic Database Backup Settings
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Generate database backups when server restarts or shuts down.
|
||||||
|
BackupDatabase = False
|
||||||
|
|
||||||
|
# Path to MySQL bin folder. Only necessary on Windows.
|
||||||
|
MySqlBinLocation = C:/xampp/mysql/bin/
|
||||||
|
|
||||||
|
# Path where MySQL backups are stored.
|
||||||
|
BackupPath = ../backup/
|
||||||
|
|
||||||
|
# Maximum number of days that backups will be kept.
|
||||||
|
# Old backups will be deleted.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
BackupDays = 30
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Security
|
# Security
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
@@ -752,6 +752,10 @@ public final class Config
|
|||||||
public static String DATABASE_PASSWORD;
|
public static String DATABASE_PASSWORD;
|
||||||
public static int DATABASE_MAX_CONNECTIONS;
|
public static int DATABASE_MAX_CONNECTIONS;
|
||||||
public static int DATABASE_MAX_IDLE_TIME;
|
public static int DATABASE_MAX_IDLE_TIME;
|
||||||
|
public static boolean BACKUP_DATABASE;
|
||||||
|
public static String MYSQL_BIN_PATH;
|
||||||
|
public static String BACKUP_PATH;
|
||||||
|
public static int BACKUP_DAYS;
|
||||||
public static int MAXIMUM_ONLINE_USERS;
|
public static int MAXIMUM_ONLINE_USERS;
|
||||||
public static boolean HARDWARE_INFO_ENABLED;
|
public static boolean HARDWARE_INFO_ENABLED;
|
||||||
public static int MAX_PLAYERS_PER_HWID;
|
public static int MAX_PLAYERS_PER_HWID;
|
||||||
@@ -1211,6 +1215,11 @@ public final class Config
|
|||||||
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
|
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
|
||||||
DATABASE_MAX_IDLE_TIME = serverSettings.getInt("MaximumDbIdleTime", 0);
|
DATABASE_MAX_IDLE_TIME = serverSettings.getInt("MaximumDbIdleTime", 0);
|
||||||
|
|
||||||
|
BACKUP_DATABASE = serverSettings.getBoolean("BackupDatabase", false);
|
||||||
|
MYSQL_BIN_PATH = serverSettings.getString("MySqlBinLocation", "C:/xampp/mysql/bin/");
|
||||||
|
BACKUP_PATH = serverSettings.getString("BackupPath", "../backup/");
|
||||||
|
BACKUP_DAYS = serverSettings.getInt("BackupDays", 30);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DATAPACK_ROOT = new File(serverSettings.getString("DatapackRoot", ".").replaceAll("\\\\", "/")).getCanonicalFile();
|
DATAPACK_ROOT = new File(serverSettings.getString("DatapackRoot", ".").replaceAll("\\\\", "/")).getCanonicalFile();
|
||||||
@@ -2845,6 +2854,11 @@ public final class Config
|
|||||||
DATABASE_MAX_CONNECTIONS = ServerSettings.getInt("MaximumDbConnections", 10);
|
DATABASE_MAX_CONNECTIONS = ServerSettings.getInt("MaximumDbConnections", 10);
|
||||||
DATABASE_MAX_IDLE_TIME = ServerSettings.getInt("MaximumDbIdleTime", 0);
|
DATABASE_MAX_IDLE_TIME = ServerSettings.getInt("MaximumDbIdleTime", 0);
|
||||||
|
|
||||||
|
BACKUP_DATABASE = ServerSettings.getBoolean("BackupDatabase", false);
|
||||||
|
MYSQL_BIN_PATH = ServerSettings.getString("MySqlBinLocation", "C:/xampp/mysql/bin/");
|
||||||
|
BACKUP_PATH = ServerSettings.getString("BackupPath", "../backup/");
|
||||||
|
BACKUP_DAYS = ServerSettings.getInt("BackupDays", 30);
|
||||||
|
|
||||||
SHOW_LICENCE = ServerSettings.getBoolean("ShowLicence", true);
|
SHOW_LICENCE = ServerSettings.getBoolean("ShowLicence", true);
|
||||||
SHOW_PI_AGREEMENT = ServerSettings.getBoolean("ShowPIAgreement", false);
|
SHOW_PI_AGREEMENT = ServerSettings.getBoolean("ShowPIAgreement", false);
|
||||||
|
|
||||||
|
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the L2J Mobius project.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.l2jmobius.commons.database;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import com.l2jmobius.Config;
|
||||||
|
import com.l2jmobius.Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class DatabaseBackup
|
||||||
|
{
|
||||||
|
public static void performBackup()
|
||||||
|
{
|
||||||
|
// Delete old files.
|
||||||
|
if (Config.BACKUP_DAYS > 0)
|
||||||
|
{
|
||||||
|
final long cut = LocalDateTime.now().minusDays(Config.BACKUP_DAYS).toEpochSecond(ZoneOffset.UTC);
|
||||||
|
final Path path = Paths.get(Config.BACKUP_PATH);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.list(path).filter(n ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Files.getLastModifiedTime(n).to(TimeUnit.SECONDS) < cut;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}).forEach(n ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.delete(n);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dump to file.
|
||||||
|
final String mysqldumpPath = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0 ? Config.MYSQL_BIN_PATH : "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mysql://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Server.serverMode == Server.MODE_GAMESERVER ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date()));
|
||||||
|
process.waitFor();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -21,6 +21,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.commons.concurrent.ThreadPool;
|
import com.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import com.l2jmobius.commons.database.DatabaseBackup;
|
||||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
|
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
|
||||||
import com.l2jmobius.gameserver.data.sql.impl.OfflineTradersTable;
|
import com.l2jmobius.gameserver.data.sql.impl.OfflineTradersTable;
|
||||||
@@ -269,6 +270,12 @@ public class Shutdown extends Thread
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Backup database.
|
||||||
|
if (Config.BACKUP_DATABASE)
|
||||||
|
{
|
||||||
|
DatabaseBackup.performBackup();
|
||||||
|
}
|
||||||
|
|
||||||
// server will quit, when this function ends.
|
// server will quit, when this function ends.
|
||||||
if (getInstance()._shutdownMode == GM_RESTART)
|
if (getInstance()._shutdownMode == GM_RESTART)
|
||||||
{
|
{
|
||||||
|
@@ -30,6 +30,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.Server;
|
import com.l2jmobius.Server;
|
||||||
|
import com.l2jmobius.commons.database.DatabaseBackup;
|
||||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import com.l2jmobius.loginserver.network.ClientNetworkManager;
|
import com.l2jmobius.loginserver.network.ClientNetworkManager;
|
||||||
|
|
||||||
@@ -206,6 +207,10 @@ public final class LoginServer
|
|||||||
|
|
||||||
public void shutdown(boolean restart)
|
public void shutdown(boolean restart)
|
||||||
{
|
{
|
||||||
|
if (Config.BACKUP_DATABASE)
|
||||||
|
{
|
||||||
|
DatabaseBackup.performBackup();
|
||||||
|
}
|
||||||
Runtime.getRuntime().exit(restart ? 2 : 0);
|
Runtime.getRuntime().exit(restart ? 2 : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
L2J_Mobius_Classic_2.0_Zaken/dist/backup/readme.txt
vendored
Normal file
3
L2J_Mobius_Classic_2.0_Zaken/dist/backup/readme.txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
MySQL backups are stored in this folder.
|
||||||
|
Separate game and login server backups are possible.
|
||||||
|
Just enable the 'BackupDatabase' option in the equivalent server config file.
|
@@ -62,6 +62,24 @@ MaximumDbConnections = 500
|
|||||||
MaximumDbIdleTime = 0
|
MaximumDbIdleTime = 0
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Automatic Database Backup Settings
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Generate database backups when server restarts or shuts down.
|
||||||
|
BackupDatabase = False
|
||||||
|
|
||||||
|
# Path to MySQL bin folder. Only necessary on Windows.
|
||||||
|
MySqlBinLocation = C:/xampp/mysql/bin/
|
||||||
|
|
||||||
|
# Path where MySQL backups are stored.
|
||||||
|
BackupPath = ../backup/
|
||||||
|
|
||||||
|
# Maximum number of days that backups will be kept.
|
||||||
|
# Old files in backup folder will be deleted.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
BackupDays = 30
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Misc Server Settings
|
# Misc Server Settings
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
@@ -62,6 +62,24 @@ MaximumDbConnections = 50
|
|||||||
MaximumDbIdleTime = 0
|
MaximumDbIdleTime = 0
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Automatic Database Backup Settings
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Generate database backups when server restarts or shuts down.
|
||||||
|
BackupDatabase = False
|
||||||
|
|
||||||
|
# Path to MySQL bin folder. Only necessary on Windows.
|
||||||
|
MySqlBinLocation = C:/xampp/mysql/bin/
|
||||||
|
|
||||||
|
# Path where MySQL backups are stored.
|
||||||
|
BackupPath = ../backup/
|
||||||
|
|
||||||
|
# Maximum number of days that backups will be kept.
|
||||||
|
# Old backups will be deleted.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
BackupDays = 30
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Security
|
# Security
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
@@ -752,6 +752,10 @@ public final class Config
|
|||||||
public static String DATABASE_PASSWORD;
|
public static String DATABASE_PASSWORD;
|
||||||
public static int DATABASE_MAX_CONNECTIONS;
|
public static int DATABASE_MAX_CONNECTIONS;
|
||||||
public static int DATABASE_MAX_IDLE_TIME;
|
public static int DATABASE_MAX_IDLE_TIME;
|
||||||
|
public static boolean BACKUP_DATABASE;
|
||||||
|
public static String MYSQL_BIN_PATH;
|
||||||
|
public static String BACKUP_PATH;
|
||||||
|
public static int BACKUP_DAYS;
|
||||||
public static int MAXIMUM_ONLINE_USERS;
|
public static int MAXIMUM_ONLINE_USERS;
|
||||||
public static boolean HARDWARE_INFO_ENABLED;
|
public static boolean HARDWARE_INFO_ENABLED;
|
||||||
public static int MAX_PLAYERS_PER_HWID;
|
public static int MAX_PLAYERS_PER_HWID;
|
||||||
@@ -1215,6 +1219,11 @@ public final class Config
|
|||||||
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
|
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
|
||||||
DATABASE_MAX_IDLE_TIME = serverSettings.getInt("MaximumDbIdleTime", 0);
|
DATABASE_MAX_IDLE_TIME = serverSettings.getInt("MaximumDbIdleTime", 0);
|
||||||
|
|
||||||
|
BACKUP_DATABASE = serverSettings.getBoolean("BackupDatabase", false);
|
||||||
|
MYSQL_BIN_PATH = serverSettings.getString("MySqlBinLocation", "C:/xampp/mysql/bin/");
|
||||||
|
BACKUP_PATH = serverSettings.getString("BackupPath", "../backup/");
|
||||||
|
BACKUP_DAYS = serverSettings.getInt("BackupDays", 30);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DATAPACK_ROOT = new File(serverSettings.getString("DatapackRoot", ".").replaceAll("\\\\", "/")).getCanonicalFile();
|
DATAPACK_ROOT = new File(serverSettings.getString("DatapackRoot", ".").replaceAll("\\\\", "/")).getCanonicalFile();
|
||||||
@@ -2852,6 +2861,11 @@ public final class Config
|
|||||||
DATABASE_MAX_CONNECTIONS = ServerSettings.getInt("MaximumDbConnections", 10);
|
DATABASE_MAX_CONNECTIONS = ServerSettings.getInt("MaximumDbConnections", 10);
|
||||||
DATABASE_MAX_IDLE_TIME = ServerSettings.getInt("MaximumDbIdleTime", 0);
|
DATABASE_MAX_IDLE_TIME = ServerSettings.getInt("MaximumDbIdleTime", 0);
|
||||||
|
|
||||||
|
BACKUP_DATABASE = ServerSettings.getBoolean("BackupDatabase", false);
|
||||||
|
MYSQL_BIN_PATH = ServerSettings.getString("MySqlBinLocation", "C:/xampp/mysql/bin/");
|
||||||
|
BACKUP_PATH = ServerSettings.getString("BackupPath", "../backup/");
|
||||||
|
BACKUP_DAYS = ServerSettings.getInt("BackupDays", 30);
|
||||||
|
|
||||||
SHOW_LICENCE = ServerSettings.getBoolean("ShowLicence", true);
|
SHOW_LICENCE = ServerSettings.getBoolean("ShowLicence", true);
|
||||||
SHOW_PI_AGREEMENT = ServerSettings.getBoolean("ShowPIAgreement", false);
|
SHOW_PI_AGREEMENT = ServerSettings.getBoolean("ShowPIAgreement", false);
|
||||||
|
|
||||||
|
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the L2J Mobius project.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.l2jmobius.commons.database;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import com.l2jmobius.Config;
|
||||||
|
import com.l2jmobius.Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class DatabaseBackup
|
||||||
|
{
|
||||||
|
public static void performBackup()
|
||||||
|
{
|
||||||
|
// Delete old files.
|
||||||
|
if (Config.BACKUP_DAYS > 0)
|
||||||
|
{
|
||||||
|
final long cut = LocalDateTime.now().minusDays(Config.BACKUP_DAYS).toEpochSecond(ZoneOffset.UTC);
|
||||||
|
final Path path = Paths.get(Config.BACKUP_PATH);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.list(path).filter(n ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Files.getLastModifiedTime(n).to(TimeUnit.SECONDS) < cut;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}).forEach(n ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.delete(n);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dump to file.
|
||||||
|
final String mysqldumpPath = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0 ? Config.MYSQL_BIN_PATH : "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mysql://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Server.serverMode == Server.MODE_GAMESERVER ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date()));
|
||||||
|
process.waitFor();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -21,6 +21,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.commons.concurrent.ThreadPool;
|
import com.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import com.l2jmobius.commons.database.DatabaseBackup;
|
||||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
|
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
|
||||||
import com.l2jmobius.gameserver.data.sql.impl.OfflineTradersTable;
|
import com.l2jmobius.gameserver.data.sql.impl.OfflineTradersTable;
|
||||||
@@ -269,6 +270,12 @@ public class Shutdown extends Thread
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Backup database.
|
||||||
|
if (Config.BACKUP_DATABASE)
|
||||||
|
{
|
||||||
|
DatabaseBackup.performBackup();
|
||||||
|
}
|
||||||
|
|
||||||
// server will quit, when this function ends.
|
// server will quit, when this function ends.
|
||||||
if (getInstance()._shutdownMode == GM_RESTART)
|
if (getInstance()._shutdownMode == GM_RESTART)
|
||||||
{
|
{
|
||||||
|
@@ -30,6 +30,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.Server;
|
import com.l2jmobius.Server;
|
||||||
|
import com.l2jmobius.commons.database.DatabaseBackup;
|
||||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import com.l2jmobius.loginserver.network.ClientNetworkManager;
|
import com.l2jmobius.loginserver.network.ClientNetworkManager;
|
||||||
|
|
||||||
@@ -206,6 +207,10 @@ public final class LoginServer
|
|||||||
|
|
||||||
public void shutdown(boolean restart)
|
public void shutdown(boolean restart)
|
||||||
{
|
{
|
||||||
|
if (Config.BACKUP_DATABASE)
|
||||||
|
{
|
||||||
|
DatabaseBackup.performBackup();
|
||||||
|
}
|
||||||
Runtime.getRuntime().exit(restart ? 2 : 0);
|
Runtime.getRuntime().exit(restart ? 2 : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user