From d2ed161dda1e7220d3235cb4c276ce13db396ad5 Mon Sep 17 00:00:00 2001
From: MobiusDev <8391001+MobiusDevelopment@users.noreply.github.com>
Date: Tue, 1 May 2018 07:23:13 +0000
Subject: [PATCH] Configurable automatic database backups.
---
L2J_Mobius_1.0_Ertheia/dist/backup/readme.txt | 3 +
.../dist/game/config/Server.ini | 18 ++++
.../dist/login/config/LoginServer.ini | 18 ++++
.../java/com/l2jmobius/Config.java | 14 ++++
.../commons/database/DatabaseBackup.java | 82 +++++++++++++++++++
.../com/l2jmobius/gameserver/Shutdown.java | 7 ++
.../l2jmobius/loginserver/LoginServer.java | 5 ++
L2J_Mobius_1.0_Ertheia/readme.txt | 1 +
.../dist/backup/readme.txt | 3 +
.../dist/game/config/Server.ini | 18 ++++
.../dist/login/config/LoginServer.ini | 18 ++++
.../java/com/l2jmobius/Config.java | 14 ++++
.../commons/database/DatabaseBackup.java | 82 +++++++++++++++++++
.../com/l2jmobius/gameserver/Shutdown.java | 7 ++
.../l2jmobius/loginserver/LoginServer.java | 5 ++
L2J_Mobius_2.5_Underground/readme.txt | 1 +
L2J_Mobius_3.0_Helios/dist/backup/readme.txt | 3 +
.../dist/game/config/Server.ini | 18 ++++
.../dist/login/config/LoginServer.ini | 18 ++++
.../java/com/l2jmobius/Config.java | 14 ++++
.../commons/database/DatabaseBackup.java | 82 +++++++++++++++++++
.../com/l2jmobius/gameserver/Shutdown.java | 7 ++
.../l2jmobius/loginserver/LoginServer.java | 5 ++
L2J_Mobius_3.0_Helios/readme.txt | 1 +
.../dist/backup/readme.txt | 3 +
.../dist/game/config/Server.ini | 18 ++++
.../dist/login/config/LoginServer.ini | 18 ++++
.../java/com/l2jmobius/Config.java | 14 ++++
.../commons/database/DatabaseBackup.java | 82 +++++++++++++++++++
.../com/l2jmobius/gameserver/Shutdown.java | 7 ++
.../l2jmobius/loginserver/LoginServer.java | 5 ++
L2J_Mobius_4.0_GrandCrusade/readme.txt | 1 +
.../dist/backup/readme.txt | 3 +
.../dist/game/config/network/gameserver.ini | 19 +++++
.../dist/login/config/network/loginserver.ini | 19 +++++
.../java/com/l2jmobius/Config.java | 14 ++++
.../commons/database/DatabaseBackup.java | 82 +++++++++++++++++++
.../com/l2jmobius/gameserver/Shutdown.java | 7 ++
.../l2jmobius/loginserver/LoginServer.java | 7 ++
.../dist/backup/readme.txt | 3 +
.../dist/game/config/Server.ini | 18 ++++
.../dist/login/config/LoginServer.ini | 18 ++++
.../java/com/l2jmobius/Config.java | 14 ++++
.../commons/database/DatabaseBackup.java | 82 +++++++++++++++++++
.../com/l2jmobius/gameserver/Shutdown.java | 7 ++
.../l2jmobius/loginserver/LoginServer.java | 5 ++
L2J_Mobius_CT_2.6_HighFive/readme.txt | 1 +
.../dist/backup/readme.txt | 3 +
.../dist/game/config/Server.ini | 18 ++++
.../dist/login/config/LoginServer.ini | 18 ++++
.../java/com/l2jmobius/Config.java | 14 ++++
.../commons/database/DatabaseBackup.java | 82 +++++++++++++++++++
.../com/l2jmobius/gameserver/Shutdown.java | 7 ++
.../l2jmobius/loginserver/LoginServer.java | 5 ++
.../dist/backup/readme.txt | 3 +
.../dist/game/config/Server.ini | 18 ++++
.../dist/login/config/LoginServer.ini | 18 ++++
.../java/com/l2jmobius/Config.java | 14 ++++
.../commons/database/DatabaseBackup.java | 82 +++++++++++++++++++
.../com/l2jmobius/gameserver/Shutdown.java | 7 ++
.../l2jmobius/loginserver/LoginServer.java | 5 ++
61 files changed, 1185 insertions(+)
create mode 100644 L2J_Mobius_1.0_Ertheia/dist/backup/readme.txt
create mode 100644 L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/commons/database/DatabaseBackup.java
create mode 100644 L2J_Mobius_2.5_Underground/dist/backup/readme.txt
create mode 100644 L2J_Mobius_2.5_Underground/java/com/l2jmobius/commons/database/DatabaseBackup.java
create mode 100644 L2J_Mobius_3.0_Helios/dist/backup/readme.txt
create mode 100644 L2J_Mobius_3.0_Helios/java/com/l2jmobius/commons/database/DatabaseBackup.java
create mode 100644 L2J_Mobius_4.0_GrandCrusade/dist/backup/readme.txt
create mode 100644 L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/commons/database/DatabaseBackup.java
create mode 100644 L2J_Mobius_C6_Interlude/dist/backup/readme.txt
create mode 100644 L2J_Mobius_C6_Interlude/java/com/l2jmobius/commons/database/DatabaseBackup.java
create mode 100644 L2J_Mobius_CT_2.6_HighFive/dist/backup/readme.txt
create mode 100644 L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/commons/database/DatabaseBackup.java
create mode 100644 L2J_Mobius_Classic_2.0_Saviors/dist/backup/readme.txt
create mode 100644 L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/commons/database/DatabaseBackup.java
create mode 100644 L2J_Mobius_Classic_2.0_Zaken/dist/backup/readme.txt
create mode 100644 L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/commons/database/DatabaseBackup.java
diff --git a/L2J_Mobius_1.0_Ertheia/dist/backup/readme.txt b/L2J_Mobius_1.0_Ertheia/dist/backup/readme.txt
new file mode 100644
index 0000000000..06e762e22e
--- /dev/null
+++ b/L2J_Mobius_1.0_Ertheia/dist/backup/readme.txt
@@ -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.
\ No newline at end of file
diff --git a/L2J_Mobius_1.0_Ertheia/dist/game/config/Server.ini b/L2J_Mobius_1.0_Ertheia/dist/game/config/Server.ini
index 22839a96aa..5c4982e3d4 100644
--- a/L2J_Mobius_1.0_Ertheia/dist/game/config/Server.ini
+++ b/L2J_Mobius_1.0_Ertheia/dist/game/config/Server.ini
@@ -62,6 +62,24 @@ MaximumDbConnections = 500
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
# ---------------------------------------------------------------------------
diff --git a/L2J_Mobius_1.0_Ertheia/dist/login/config/LoginServer.ini b/L2J_Mobius_1.0_Ertheia/dist/login/config/LoginServer.ini
index b754361001..a92d26ab05 100644
--- a/L2J_Mobius_1.0_Ertheia/dist/login/config/LoginServer.ini
+++ b/L2J_Mobius_1.0_Ertheia/dist/login/config/LoginServer.ini
@@ -62,6 +62,24 @@ MaximumDbConnections = 50
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
# ---------------------------------------------------------------------------
diff --git a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/Config.java b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/Config.java
index 44eda3078d..1ce14e1091 100644
--- a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/Config.java
@@ -747,6 +747,10 @@ public final class Config
public static String DATABASE_PASSWORD;
public static int DATABASE_MAX_CONNECTIONS;
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 boolean HARDWARE_INFO_ENABLED;
public static int MAX_PLAYERS_PER_HWID;
@@ -1267,6 +1271,11 @@ public final class Config
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
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
{
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_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_PI_AGREEMENT = ServerSettings.getBoolean("ShowPIAgreement", false);
diff --git a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/commons/database/DatabaseBackup.java b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/commons/database/DatabaseBackup.java
new file mode 100644
index 0000000000..97aee034ba
--- /dev/null
+++ b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/commons/database/DatabaseBackup.java
@@ -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 .
+ */
+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)
+ {
+ }
+ }
+}
diff --git a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/Shutdown.java b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/Shutdown.java
index 547750542b..0c900c0861 100644
--- a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/Shutdown.java
+++ b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/Shutdown.java
@@ -21,6 +21,7 @@ import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
+import com.l2jmobius.commons.database.DatabaseBackup;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
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.
if (getInstance()._shutdownMode == GM_RESTART)
{
diff --git a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/loginserver/LoginServer.java b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/loginserver/LoginServer.java
index 7120942e51..6c2062e622 100644
--- a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/loginserver/LoginServer.java
+++ b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/loginserver/LoginServer.java
@@ -30,6 +30,7 @@ import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.Server;
+import com.l2jmobius.commons.database.DatabaseBackup;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.loginserver.network.ClientNetworkManager;
@@ -206,6 +207,10 @@ public final class LoginServer
public void shutdown(boolean restart)
{
+ if (Config.BACKUP_DATABASE)
+ {
+ DatabaseBackup.performBackup();
+ }
Runtime.getRuntime().exit(restart ? 2 : 0);
}
}
diff --git a/L2J_Mobius_1.0_Ertheia/readme.txt b/L2J_Mobius_1.0_Ertheia/readme.txt
index 442c60205e..40300675f2 100644
--- a/L2J_Mobius_1.0_Ertheia/readme.txt
+++ b/L2J_Mobius_1.0_Ertheia/readme.txt
@@ -101,6 +101,7 @@ Customs:
-Sell buffs
-Starting location
-Vote reward
+-Automated database backups
Others:
-Reworked tax system
diff --git a/L2J_Mobius_2.5_Underground/dist/backup/readme.txt b/L2J_Mobius_2.5_Underground/dist/backup/readme.txt
new file mode 100644
index 0000000000..06e762e22e
--- /dev/null
+++ b/L2J_Mobius_2.5_Underground/dist/backup/readme.txt
@@ -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.
\ No newline at end of file
diff --git a/L2J_Mobius_2.5_Underground/dist/game/config/Server.ini b/L2J_Mobius_2.5_Underground/dist/game/config/Server.ini
index 04f1d99480..69046e6178 100644
--- a/L2J_Mobius_2.5_Underground/dist/game/config/Server.ini
+++ b/L2J_Mobius_2.5_Underground/dist/game/config/Server.ini
@@ -62,6 +62,24 @@ MaximumDbConnections = 500
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
# ---------------------------------------------------------------------------
diff --git a/L2J_Mobius_2.5_Underground/dist/login/config/LoginServer.ini b/L2J_Mobius_2.5_Underground/dist/login/config/LoginServer.ini
index b754361001..a92d26ab05 100644
--- a/L2J_Mobius_2.5_Underground/dist/login/config/LoginServer.ini
+++ b/L2J_Mobius_2.5_Underground/dist/login/config/LoginServer.ini
@@ -62,6 +62,24 @@ MaximumDbConnections = 50
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
# ---------------------------------------------------------------------------
diff --git a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/Config.java b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/Config.java
index c113f13be0..436c7acaef 100644
--- a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/Config.java
@@ -754,6 +754,10 @@ public final class Config
public static String DATABASE_PASSWORD;
public static int DATABASE_MAX_CONNECTIONS;
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 boolean HARDWARE_INFO_ENABLED;
public static int MAX_PLAYERS_PER_HWID;
@@ -1274,6 +1278,11 @@ public final class Config
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
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
{
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_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_PI_AGREEMENT = ServerSettings.getBoolean("ShowPIAgreement", false);
diff --git a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/commons/database/DatabaseBackup.java b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/commons/database/DatabaseBackup.java
new file mode 100644
index 0000000000..97aee034ba
--- /dev/null
+++ b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/commons/database/DatabaseBackup.java
@@ -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 .
+ */
+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)
+ {
+ }
+ }
+}
diff --git a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/Shutdown.java b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/Shutdown.java
index 547750542b..0c900c0861 100644
--- a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/Shutdown.java
+++ b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/Shutdown.java
@@ -21,6 +21,7 @@ import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
+import com.l2jmobius.commons.database.DatabaseBackup;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
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.
if (getInstance()._shutdownMode == GM_RESTART)
{
diff --git a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/loginserver/LoginServer.java b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/loginserver/LoginServer.java
index 7120942e51..6c2062e622 100644
--- a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/loginserver/LoginServer.java
+++ b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/loginserver/LoginServer.java
@@ -30,6 +30,7 @@ import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.Server;
+import com.l2jmobius.commons.database.DatabaseBackup;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.loginserver.network.ClientNetworkManager;
@@ -206,6 +207,10 @@ public final class LoginServer
public void shutdown(boolean restart)
{
+ if (Config.BACKUP_DATABASE)
+ {
+ DatabaseBackup.performBackup();
+ }
Runtime.getRuntime().exit(restart ? 2 : 0);
}
}
diff --git a/L2J_Mobius_2.5_Underground/readme.txt b/L2J_Mobius_2.5_Underground/readme.txt
index d21474e98a..0691919395 100644
--- a/L2J_Mobius_2.5_Underground/readme.txt
+++ b/L2J_Mobius_2.5_Underground/readme.txt
@@ -115,6 +115,7 @@ Customs:
-Sell buffs
-Starting location
-Vote reward
+-Automated database backups
Others:
-Reworked tax system
diff --git a/L2J_Mobius_3.0_Helios/dist/backup/readme.txt b/L2J_Mobius_3.0_Helios/dist/backup/readme.txt
new file mode 100644
index 0000000000..06e762e22e
--- /dev/null
+++ b/L2J_Mobius_3.0_Helios/dist/backup/readme.txt
@@ -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.
\ No newline at end of file
diff --git a/L2J_Mobius_3.0_Helios/dist/game/config/Server.ini b/L2J_Mobius_3.0_Helios/dist/game/config/Server.ini
index 8b77469911..02b01315c7 100644
--- a/L2J_Mobius_3.0_Helios/dist/game/config/Server.ini
+++ b/L2J_Mobius_3.0_Helios/dist/game/config/Server.ini
@@ -62,6 +62,24 @@ MaximumDbConnections = 500
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
# ---------------------------------------------------------------------------
diff --git a/L2J_Mobius_3.0_Helios/dist/login/config/LoginServer.ini b/L2J_Mobius_3.0_Helios/dist/login/config/LoginServer.ini
index b754361001..a92d26ab05 100644
--- a/L2J_Mobius_3.0_Helios/dist/login/config/LoginServer.ini
+++ b/L2J_Mobius_3.0_Helios/dist/login/config/LoginServer.ini
@@ -62,6 +62,24 @@ MaximumDbConnections = 50
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
# ---------------------------------------------------------------------------
diff --git a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/Config.java b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/Config.java
index 3daaa0b01b..a4e05e7f84 100644
--- a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/Config.java
@@ -755,6 +755,10 @@ public final class Config
public static String DATABASE_PASSWORD;
public static int DATABASE_MAX_CONNECTIONS;
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 boolean HARDWARE_INFO_ENABLED;
public static int MAX_PLAYERS_PER_HWID;
@@ -1282,6 +1286,11 @@ public final class Config
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
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
{
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_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_PI_AGREEMENT = ServerSettings.getBoolean("ShowPIAgreement", false);
diff --git a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/commons/database/DatabaseBackup.java b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/commons/database/DatabaseBackup.java
new file mode 100644
index 0000000000..97aee034ba
--- /dev/null
+++ b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/commons/database/DatabaseBackup.java
@@ -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 .
+ */
+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)
+ {
+ }
+ }
+}
diff --git a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/Shutdown.java b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/Shutdown.java
index 547750542b..0c900c0861 100644
--- a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/Shutdown.java
+++ b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/Shutdown.java
@@ -21,6 +21,7 @@ import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
+import com.l2jmobius.commons.database.DatabaseBackup;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
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.
if (getInstance()._shutdownMode == GM_RESTART)
{
diff --git a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/loginserver/LoginServer.java b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/loginserver/LoginServer.java
index 7120942e51..6c2062e622 100644
--- a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/loginserver/LoginServer.java
+++ b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/loginserver/LoginServer.java
@@ -30,6 +30,7 @@ import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.Server;
+import com.l2jmobius.commons.database.DatabaseBackup;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.loginserver.network.ClientNetworkManager;
@@ -206,6 +207,10 @@ public final class LoginServer
public void shutdown(boolean restart)
{
+ if (Config.BACKUP_DATABASE)
+ {
+ DatabaseBackup.performBackup();
+ }
Runtime.getRuntime().exit(restart ? 2 : 0);
}
}
diff --git a/L2J_Mobius_3.0_Helios/readme.txt b/L2J_Mobius_3.0_Helios/readme.txt
index 9eae5478ab..743f3af5c7 100644
--- a/L2J_Mobius_3.0_Helios/readme.txt
+++ b/L2J_Mobius_3.0_Helios/readme.txt
@@ -124,6 +124,7 @@ Customs:
-Sell buffs
-Starting location
-Vote reward
+-Automated database backups
Others:
-Reworked tax system
diff --git a/L2J_Mobius_4.0_GrandCrusade/dist/backup/readme.txt b/L2J_Mobius_4.0_GrandCrusade/dist/backup/readme.txt
new file mode 100644
index 0000000000..06e762e22e
--- /dev/null
+++ b/L2J_Mobius_4.0_GrandCrusade/dist/backup/readme.txt
@@ -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.
\ No newline at end of file
diff --git a/L2J_Mobius_4.0_GrandCrusade/dist/game/config/Server.ini b/L2J_Mobius_4.0_GrandCrusade/dist/game/config/Server.ini
index b0e39d9933..4528e242ce 100644
--- a/L2J_Mobius_4.0_GrandCrusade/dist/game/config/Server.ini
+++ b/L2J_Mobius_4.0_GrandCrusade/dist/game/config/Server.ini
@@ -62,6 +62,24 @@ MaximumDbConnections = 500
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
# ---------------------------------------------------------------------------
diff --git a/L2J_Mobius_4.0_GrandCrusade/dist/login/config/LoginServer.ini b/L2J_Mobius_4.0_GrandCrusade/dist/login/config/LoginServer.ini
index b754361001..a92d26ab05 100644
--- a/L2J_Mobius_4.0_GrandCrusade/dist/login/config/LoginServer.ini
+++ b/L2J_Mobius_4.0_GrandCrusade/dist/login/config/LoginServer.ini
@@ -62,6 +62,24 @@ MaximumDbConnections = 50
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
# ---------------------------------------------------------------------------
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/Config.java b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/Config.java
index 138b3d4f37..d6007721e8 100644
--- a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/Config.java
@@ -754,6 +754,10 @@ public final class Config
public static String DATABASE_PASSWORD;
public static int DATABASE_MAX_CONNECTIONS;
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 boolean HARDWARE_INFO_ENABLED;
public static int MAX_PLAYERS_PER_HWID;
@@ -1281,6 +1285,11 @@ public final class Config
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
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
{
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_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_PI_AGREEMENT = ServerSettings.getBoolean("ShowPIAgreement", false);
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/commons/database/DatabaseBackup.java b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/commons/database/DatabaseBackup.java
new file mode 100644
index 0000000000..97aee034ba
--- /dev/null
+++ b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/commons/database/DatabaseBackup.java
@@ -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 .
+ */
+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)
+ {
+ }
+ }
+}
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/Shutdown.java b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/Shutdown.java
index 547750542b..0c900c0861 100644
--- a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/Shutdown.java
+++ b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/Shutdown.java
@@ -21,6 +21,7 @@ import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
+import com.l2jmobius.commons.database.DatabaseBackup;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
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.
if (getInstance()._shutdownMode == GM_RESTART)
{
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/loginserver/LoginServer.java b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/loginserver/LoginServer.java
index 7120942e51..6c2062e622 100644
--- a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/loginserver/LoginServer.java
+++ b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/loginserver/LoginServer.java
@@ -30,6 +30,7 @@ import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.Server;
+import com.l2jmobius.commons.database.DatabaseBackup;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.loginserver.network.ClientNetworkManager;
@@ -206,6 +207,10 @@ public final class LoginServer
public void shutdown(boolean restart)
{
+ if (Config.BACKUP_DATABASE)
+ {
+ DatabaseBackup.performBackup();
+ }
Runtime.getRuntime().exit(restart ? 2 : 0);
}
}
diff --git a/L2J_Mobius_4.0_GrandCrusade/readme.txt b/L2J_Mobius_4.0_GrandCrusade/readme.txt
index f2dc600cdf..fb18e1c90f 100644
--- a/L2J_Mobius_4.0_GrandCrusade/readme.txt
+++ b/L2J_Mobius_4.0_GrandCrusade/readme.txt
@@ -128,6 +128,7 @@ Customs:
-Sell buffs
-Starting location
-Vote reward
+-Automated database backups
Others:
-Reworked tax system
diff --git a/L2J_Mobius_C6_Interlude/dist/backup/readme.txt b/L2J_Mobius_C6_Interlude/dist/backup/readme.txt
new file mode 100644
index 0000000000..06e762e22e
--- /dev/null
+++ b/L2J_Mobius_C6_Interlude/dist/backup/readme.txt
@@ -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.
\ No newline at end of file
diff --git a/L2J_Mobius_C6_Interlude/dist/game/config/network/gameserver.ini b/L2J_Mobius_C6_Interlude/dist/game/config/network/gameserver.ini
index 1803f9b23a..441c81821e 100644
--- a/L2J_Mobius_C6_Interlude/dist/game/config/network/gameserver.ini
+++ b/L2J_Mobius_C6_Interlude/dist/game/config/network/gameserver.ini
@@ -57,6 +57,25 @@ MaximumDbConnections = 50
# Default: 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)
RemoteWhoLog = True
RemoteWhoSendTrash = True
diff --git a/L2J_Mobius_C6_Interlude/dist/login/config/network/loginserver.ini b/L2J_Mobius_C6_Interlude/dist/login/config/network/loginserver.ini
index 4f38c93329..654a413b40 100644
--- a/L2J_Mobius_C6_Interlude/dist/login/config/network/loginserver.ini
+++ b/L2J_Mobius_C6_Interlude/dist/login/config/network/loginserver.ini
@@ -67,6 +67,25 @@ MaximumDbConnections = 50
# Default: 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)
FastConnectionLimit = 15
# Time of the normal connection (in ms)
diff --git a/L2J_Mobius_C6_Interlude/java/com/l2jmobius/Config.java b/L2J_Mobius_C6_Interlude/java/com/l2jmobius/Config.java
index 94c9549efa..df364e936f 100644
--- a/L2J_Mobius_C6_Interlude/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_C6_Interlude/java/com/l2jmobius/Config.java
@@ -212,6 +212,10 @@ public final class Config
public static String DATABASE_PASSWORD;
public static int DATABASE_MAX_CONNECTIONS;
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 RWHO_LOG;
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_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();
final Random ppc = new Random();
@@ -3816,6 +3825,11 @@ public final class Config
DATABASE_MAX_CONNECTIONS = Integer.parseInt(serverSettings.getProperty("MaximumDbConnections", "10"));
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
BRUT_AVG_TIME = Integer.parseInt(serverSettings.getProperty("BrutAvgTime", "30")); // in Seconds
BRUT_LOGON_ATTEMPTS = Integer.parseInt(serverSettings.getProperty("BrutLogonAttempts", "15"));
diff --git a/L2J_Mobius_C6_Interlude/java/com/l2jmobius/commons/database/DatabaseBackup.java b/L2J_Mobius_C6_Interlude/java/com/l2jmobius/commons/database/DatabaseBackup.java
new file mode 100644
index 0000000000..97aee034ba
--- /dev/null
+++ b/L2J_Mobius_C6_Interlude/java/com/l2jmobius/commons/database/DatabaseBackup.java
@@ -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 .
+ */
+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)
+ {
+ }
+ }
+}
diff --git a/L2J_Mobius_C6_Interlude/java/com/l2jmobius/gameserver/Shutdown.java b/L2J_Mobius_C6_Interlude/java/com/l2jmobius/gameserver/Shutdown.java
index 13f63ffef3..8c5701c7f0 100644
--- a/L2J_Mobius_C6_Interlude/java/com/l2jmobius/gameserver/Shutdown.java
+++ b/L2J_Mobius_C6_Interlude/java/com/l2jmobius/gameserver/Shutdown.java
@@ -20,6 +20,7 @@ import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
+import com.l2jmobius.commons.database.DatabaseBackup;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.datatables.BufferTable;
import com.l2jmobius.gameserver.datatables.OfflineTradeTable;
@@ -480,6 +481,12 @@ public class Shutdown extends Thread
LOGGER.info("All database data committed.");
+ // Backup database.
+ if (Config.BACKUP_DATABASE)
+ {
+ DatabaseBackup.performBackup();
+ }
+
System.runFinalization();
System.gc();
diff --git a/L2J_Mobius_C6_Interlude/java/com/l2jmobius/loginserver/LoginServer.java b/L2J_Mobius_C6_Interlude/java/com/l2jmobius/loginserver/LoginServer.java
index bc3eafd0ce..af1bc1668f 100644
--- a/L2J_Mobius_C6_Interlude/java/com/l2jmobius/loginserver/LoginServer.java
+++ b/L2J_Mobius_C6_Interlude/java/com/l2jmobius/loginserver/LoginServer.java
@@ -28,6 +28,7 @@ import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.Server;
+import com.l2jmobius.commons.database.DatabaseBackup;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.commons.mmocore.NetcoreConfig;
import com.l2jmobius.commons.mmocore.SelectorConfig;
@@ -189,6 +190,12 @@ public class LoginServer
public void shutdown(boolean restart)
{
+ // Backup database.
+ if (Config.BACKUP_DATABASE)
+ {
+ DatabaseBackup.performBackup();
+ }
+
LoginController.getInstance().shutdown();
System.gc();
Runtime.getRuntime().exit(restart ? 2 : 0);
diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/backup/readme.txt b/L2J_Mobius_CT_2.6_HighFive/dist/backup/readme.txt
new file mode 100644
index 0000000000..06e762e22e
--- /dev/null
+++ b/L2J_Mobius_CT_2.6_HighFive/dist/backup/readme.txt
@@ -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.
\ No newline at end of file
diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/config/Server.ini b/L2J_Mobius_CT_2.6_HighFive/dist/game/config/Server.ini
index 10794be8d8..5d08617152 100644
--- a/L2J_Mobius_CT_2.6_HighFive/dist/game/config/Server.ini
+++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/config/Server.ini
@@ -62,6 +62,24 @@ MaximumDbConnections = 500
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
# ---------------------------------------------------------------------------
diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/login/config/LoginServer.ini b/L2J_Mobius_CT_2.6_HighFive/dist/login/config/LoginServer.ini
index c86307a75c..6024930f80 100644
--- a/L2J_Mobius_CT_2.6_HighFive/dist/login/config/LoginServer.ini
+++ b/L2J_Mobius_CT_2.6_HighFive/dist/login/config/LoginServer.ini
@@ -62,6 +62,24 @@ MaximumDbConnections = 50
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
# ---------------------------------------------------------------------------
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/Config.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/Config.java
index ac939482a2..a507962a3d 100644
--- a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/Config.java
@@ -859,6 +859,10 @@ public final class Config
public static String DATABASE_PASSWORD;
public static int DATABASE_MAX_CONNECTIONS;
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 String CNAME_TEMPLATE;
public static String PET_NAME_TEMPLATE;
@@ -1374,6 +1378,11 @@ public final class Config
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
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
{
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_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);
AUTO_CREATE_ACCOUNTS = ServerSettings.getBoolean("AutoCreateAccounts", true);
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/commons/database/DatabaseBackup.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/commons/database/DatabaseBackup.java
new file mode 100644
index 0000000000..97aee034ba
--- /dev/null
+++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/commons/database/DatabaseBackup.java
@@ -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 .
+ */
+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)
+ {
+ }
+ }
+}
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/Shutdown.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/Shutdown.java
index e2c38225e5..5cef32d8f2 100644
--- a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/Shutdown.java
+++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/Shutdown.java
@@ -21,6 +21,7 @@ import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
+import com.l2jmobius.commons.database.DatabaseBackup;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
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.
if (getInstance()._shutdownMode == GM_RESTART)
{
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/loginserver/LoginServer.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/loginserver/LoginServer.java
index 205f70ebfa..642659a03d 100644
--- a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/loginserver/LoginServer.java
+++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/loginserver/LoginServer.java
@@ -30,6 +30,7 @@ import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.Server;
+import com.l2jmobius.commons.database.DatabaseBackup;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.loginserver.network.ClientNetworkManager;
@@ -206,6 +207,10 @@ public final class LoginServer
public void shutdown(boolean restart)
{
+ if (Config.BACKUP_DATABASE)
+ {
+ DatabaseBackup.performBackup();
+ }
Runtime.getRuntime().exit(restart ? 2 : 0);
}
}
diff --git a/L2J_Mobius_CT_2.6_HighFive/readme.txt b/L2J_Mobius_CT_2.6_HighFive/readme.txt
index d552d42179..29f2b861b3 100644
--- a/L2J_Mobius_CT_2.6_HighFive/readme.txt
+++ b/L2J_Mobius_CT_2.6_HighFive/readme.txt
@@ -35,3 +35,4 @@ What is done
-Dropped knownlists
-Faction System (Good vs Evil)
-Fake players
+-Automated database backups
diff --git a/L2J_Mobius_Classic_2.0_Saviors/dist/backup/readme.txt b/L2J_Mobius_Classic_2.0_Saviors/dist/backup/readme.txt
new file mode 100644
index 0000000000..06e762e22e
--- /dev/null
+++ b/L2J_Mobius_Classic_2.0_Saviors/dist/backup/readme.txt
@@ -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.
\ No newline at end of file
diff --git a/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/Server.ini b/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/Server.ini
index 8b3305d448..9cb6f04606 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/Server.ini
+++ b/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/Server.ini
@@ -62,6 +62,24 @@ MaximumDbConnections = 500
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
# ---------------------------------------------------------------------------
diff --git a/L2J_Mobius_Classic_2.0_Saviors/dist/login/config/LoginServer.ini b/L2J_Mobius_Classic_2.0_Saviors/dist/login/config/LoginServer.ini
index 32fa0f89e3..3cc61b6803 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/dist/login/config/LoginServer.ini
+++ b/L2J_Mobius_Classic_2.0_Saviors/dist/login/config/LoginServer.ini
@@ -62,6 +62,24 @@ MaximumDbConnections = 50
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
# ---------------------------------------------------------------------------
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/Config.java b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/Config.java
index ce0e026a94..193113757b 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/Config.java
@@ -752,6 +752,10 @@ public final class Config
public static String DATABASE_PASSWORD;
public static int DATABASE_MAX_CONNECTIONS;
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 boolean HARDWARE_INFO_ENABLED;
public static int MAX_PLAYERS_PER_HWID;
@@ -1211,6 +1215,11 @@ public final class Config
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
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
{
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_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_PI_AGREEMENT = ServerSettings.getBoolean("ShowPIAgreement", false);
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/commons/database/DatabaseBackup.java b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/commons/database/DatabaseBackup.java
new file mode 100644
index 0000000000..97aee034ba
--- /dev/null
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/commons/database/DatabaseBackup.java
@@ -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 .
+ */
+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)
+ {
+ }
+ }
+}
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/Shutdown.java b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/Shutdown.java
index 547750542b..0c900c0861 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/Shutdown.java
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/Shutdown.java
@@ -21,6 +21,7 @@ import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
+import com.l2jmobius.commons.database.DatabaseBackup;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
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.
if (getInstance()._shutdownMode == GM_RESTART)
{
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/loginserver/LoginServer.java b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/loginserver/LoginServer.java
index 7120942e51..6c2062e622 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/loginserver/LoginServer.java
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/loginserver/LoginServer.java
@@ -30,6 +30,7 @@ import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.Server;
+import com.l2jmobius.commons.database.DatabaseBackup;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.loginserver.network.ClientNetworkManager;
@@ -206,6 +207,10 @@ public final class LoginServer
public void shutdown(boolean restart)
{
+ if (Config.BACKUP_DATABASE)
+ {
+ DatabaseBackup.performBackup();
+ }
Runtime.getRuntime().exit(restart ? 2 : 0);
}
}
diff --git a/L2J_Mobius_Classic_2.0_Zaken/dist/backup/readme.txt b/L2J_Mobius_Classic_2.0_Zaken/dist/backup/readme.txt
new file mode 100644
index 0000000000..06e762e22e
--- /dev/null
+++ b/L2J_Mobius_Classic_2.0_Zaken/dist/backup/readme.txt
@@ -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.
\ No newline at end of file
diff --git a/L2J_Mobius_Classic_2.0_Zaken/dist/game/config/Server.ini b/L2J_Mobius_Classic_2.0_Zaken/dist/game/config/Server.ini
index d2fc771b9d..8aaa954f5f 100644
--- a/L2J_Mobius_Classic_2.0_Zaken/dist/game/config/Server.ini
+++ b/L2J_Mobius_Classic_2.0_Zaken/dist/game/config/Server.ini
@@ -62,6 +62,24 @@ MaximumDbConnections = 500
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
# ---------------------------------------------------------------------------
diff --git a/L2J_Mobius_Classic_2.0_Zaken/dist/login/config/LoginServer.ini b/L2J_Mobius_Classic_2.0_Zaken/dist/login/config/LoginServer.ini
index 32fa0f89e3..3cc61b6803 100644
--- a/L2J_Mobius_Classic_2.0_Zaken/dist/login/config/LoginServer.ini
+++ b/L2J_Mobius_Classic_2.0_Zaken/dist/login/config/LoginServer.ini
@@ -62,6 +62,24 @@ MaximumDbConnections = 50
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
# ---------------------------------------------------------------------------
diff --git a/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/Config.java b/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/Config.java
index bad877ff32..5fc034a1b0 100644
--- a/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/Config.java
@@ -752,6 +752,10 @@ public final class Config
public static String DATABASE_PASSWORD;
public static int DATABASE_MAX_CONNECTIONS;
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 boolean HARDWARE_INFO_ENABLED;
public static int MAX_PLAYERS_PER_HWID;
@@ -1215,6 +1219,11 @@ public final class Config
DATABASE_MAX_CONNECTIONS = serverSettings.getInt("MaximumDbConnections", 10);
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
{
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_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_PI_AGREEMENT = ServerSettings.getBoolean("ShowPIAgreement", false);
diff --git a/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/commons/database/DatabaseBackup.java b/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/commons/database/DatabaseBackup.java
new file mode 100644
index 0000000000..97aee034ba
--- /dev/null
+++ b/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/commons/database/DatabaseBackup.java
@@ -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 .
+ */
+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)
+ {
+ }
+ }
+}
diff --git a/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/gameserver/Shutdown.java b/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/gameserver/Shutdown.java
index 547750542b..0c900c0861 100644
--- a/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/gameserver/Shutdown.java
+++ b/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/gameserver/Shutdown.java
@@ -21,6 +21,7 @@ import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
+import com.l2jmobius.commons.database.DatabaseBackup;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
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.
if (getInstance()._shutdownMode == GM_RESTART)
{
diff --git a/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/loginserver/LoginServer.java b/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/loginserver/LoginServer.java
index 7120942e51..6c2062e622 100644
--- a/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/loginserver/LoginServer.java
+++ b/L2J_Mobius_Classic_2.0_Zaken/java/com/l2jmobius/loginserver/LoginServer.java
@@ -30,6 +30,7 @@ import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.Server;
+import com.l2jmobius.commons.database.DatabaseBackup;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.loginserver.network.ClientNetworkManager;
@@ -206,6 +207,10 @@ public final class LoginServer
public void shutdown(boolean restart)
{
+ if (Config.BACKUP_DATABASE)
+ {
+ DatabaseBackup.performBackup();
+ }
Runtime.getRuntime().exit(restart ? 2 : 0);
}
}