Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
Index: net.sf.l2j;Config.JAVA =================================================================== --- net.sf.l2j;Config.JAVA (revision) +++ net.sf.l2j;Config.JAVA (working copy) + /** Auto Save Data Base */ + public static boolean ENABLE_BACKUP_BOOLEAN; + public static String NAME_DATA_BASE; + ENABLE_BACKUP_BOOLEAN = Boolean.parseBoolean(aCis.getProperty("AutoSaveDB", "True")); + NAME_DATA_BASE = aCis.getProperty("URL_DB", "aCis"); Index: Dev.AutoBackup;BackupDBSave.JAVA =================================================================== --- Dev.AutoBackup;BackupDBSave.JAVA (revision) +++ Dev.AutoBackup;BackupDBSave.JAVA (working copy) + package Dev.AutoBackup; + + import java.io.BufferedReader; + import java.io.File; + import java.io.FileInputStream; + import java.io.FileOutputStream; + import java.io.IOException; + import java.io.InputStreamReader; + import java.net.URL; + import java.sql.Connection; + import java.sql.PreparedStatement; + import java.sql.ResultSet; + import java.text.DateFormat; + import java.text.SimpleDateFormat; + import java.util.Date; + import java.util.zip.ZipEntry; + import java.util.zip.ZipOutputStream; + + import net.sf.l2j.commons.concurrent.ThreadPool; + + import net.sf.l2j.Config; + import net.sf.l2j.L2DatabaseFactory; + import net.sf.l2j.util.Mysql; + + + /** + * @author COMBATE + * + * note to RESTORE + * Unzip the file + * Then go to database via navicat and run Execute SQL File + * Then declick the option "Run multiple queries in each execution" to avoid conflict with locks of tables + */ + public class BackupDBSave + { + private String database_name = Config.NAME_DATA_BASE; + private boolean DEBUG_SYSTEM = false; + private long initializeAfterTime = 1000 * 60 * 60 * 1; // Start in 2 hour + private long checkEveryTime = 1000 * 60 * 60 * 1; // Every 6 hours + + protected BackupDBSave() + { + ThreadPool.scheduleAtFixedRate(() -> BackupDBToSql(), initializeAfterTime, checkEveryTime); + + System.out.println("Database Backup Manager: Loaded"); + } + + public void BackupDBToSql() + { + String pathOfMysql = "\""; + + Connection con = null; + PreparedStatement statement = null; + ResultSet rs = null; + + try + { + con = L2DatabaseFactory.getInstance().getConnection(); + statement = con.prepareStatement("SELECT @@basedir"); + rs = statement.executeQuery(); + + while (rs.next()) + { + pathOfMysql += rs.getString(1); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + finally + { + Mysql.closeQuietly(con, statement, rs); + } + + if (pathOfMysql.isEmpty()) + { + System.out.println("Error on backup database. Empty path of mysql."); + return; + } + + // Give the specific path (pathOfMysql out = C:\Program Files\MySQL\MySQL Server 5.7\) + pathOfMysql += "bin\\mysqldump" + "\""; + + if(DEBUG_SYSTEM) System.out.println("Path of mysql: " + pathOfMysql); + + // Initialize code for backup + try + { + // Section for path of system + URL applicationRootPathURL = getClass().getProtectionDomain().getCodeSource().getLocation(); + File applicationRootPath = new File(applicationRootPathURL.getPath()); + File myFile = new File(applicationRootPath.getParent()); + File lastMyFile = new File(myFile.getParent()); + + String dbUser = Config.DATABASE_LOGIN; + String dbPass = Config.DATABASE_PASSWORD; + + String commandOfMysqlDump = " " + database_name + " --single-transaction -u" + dbUser + " -p" + dbPass + " --skip-create-options --skip-comments --disable-keys > "; + + /* NOTE: Creating Path Constraints for folder saving */ + /* NOTE: Here the backup folder is created for saving inside it */ + String folderPath = "backup"; + + /* NOTE: Creating Folder if it does not exist */ + File f1 = new File(folderPath); + f1.mkdir(); + + /* NOTE: Creating Path Constraints for backup saving */ + /* NOTE: Here the backup is saved in a folder called backup with the name backup.sql */ + String pathUntilDirectory = (lastMyFile.getAbsolutePath() + "\\backup\\").replaceAll("%20", " "); + String savePath = ("\""+pathUntilDirectory + "backup.sql\"").replaceAll("%20", " "); + + /* NOTE: Used to create a cmd command */ + String commandToExecute = "cmd /c "+ pathOfMysql + commandOfMysqlDump + savePath; + + if (DEBUG_SYSTEM) + { + System.out.println("Save path of sql file: " + savePath); + System.out.println("Command To Execute: " + commandToExecute); + } + + /* NOTE: Executing the command here */ + Process runtimeProcess = Runtime.getRuntime().exec(new String[] {"cmd", "/c", commandToExecute }); + + if (DEBUG_SYSTEM) + { + BufferedReader stdInput = new BufferedReader(new InputStreamReader(runtimeProcess.getInputStream())); + BufferedReader stdError = new BufferedReader(new InputStreamReader(runtimeProcess.getErrorStream())); + + // read the output from the command + System.out.println("Here is the standard output of the command:\n"); + String s = null; + while ((s = stdInput.readLine()) != null) { + System.out.println(s); + } + + // read any errors from the attempted command + System.out.println("Here is the standard error of the command (if any):\n"); + while ((s = stdError.readLine()) != null) { + System.out.println(s); + } + } + + int processComplete = runtimeProcess.waitFor(); + + /* NOTE: processComplete=0 if correctly executed, will contain other values if not */ + if (processComplete == 0) + { + System.out.println("Backup to SQL Complete"); + + // Zip the sql file + zipAFile(pathUntilDirectory); + + // Delete the backup.sql file + deleteAFile(savePath.replaceAll("\"", "")); + } + else + { + System.out.println("Backup to SQL Failure"); + } + } + catch (IOException | InterruptedException ex) + { + System.out.println("Error at Backuprestore" + ex.getMessage()); + } + } + + @SuppressWarnings("resource") + private static void zipAFile(String pathToSave) + { + byte[] buffer = new byte[1024]; + + try + { + DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH-mm-ss"); + Date date = new Date(); + + FileOutputStream fos = new FileOutputStream(pathToSave + "Backup_"+dateFormat.format(date)+".zip"); + ZipOutputStream zos = new ZipOutputStream(fos); + ZipEntry ze = new ZipEntry("backup.sql"); + zos.putNextEntry(ze); + FileInputStream in = new FileInputStream(pathToSave + "\\backup.sql"); + + int len; + while ((len = in.read(buffer)) > 0) + { + zos.write(buffer, 0, len); + } + + in.close(); + zos.closeEntry(); + + // remember close it + zos.close(); + + System.out.println("Done the zip of backup."); + + } + catch (IOException ex) + { + ex.printStackTrace(); + } + + } + + private static void deleteAFile(String path) { + try{ + File file = new File(path); + System.out.println(file.delete() ? (file.getName() + " is deleted!") : ("Delete operation is failed.")); + + }catch(Exception e){ + + e.printStackTrace(); + + } + } + + public static BackupDBSave getInstance() + { + return SingletonHolder._instance; + } + + private static class SingletonHolder + { + protected static final BackupDBSave _instance = new BackupDBSave(); + } + } + Index: Dev.AutoBackup;Mysql.JAVA =================================================================== --- Dev.AutoBackup;Mysql.JAVA (revision) +++ Dev.AutoBackup;Mysql.JAVA (working copy) + package Dev.AutoBackup; + + + import java.sql.Connection; + import java.sql.PreparedStatement; + import java.sql.ResultSet; + import java.sql.SQLException; + import java.sql.Statement; + import java.util.logging.Logger; + + import net.sf.l2j.L2DatabaseFactory; + + /** + * @author COMBATE + * + */ + public abstract class Mysql + { + private static final Logger _log = Logger.getLogger(Mysql.class.getName()); + + /** + * Performs a simple sql queries where unnecessary control parameters <BR> + * NOTE: In this method, the parameters passed are not valid for SQL-injection! + * @param db + * @param query + * @param vars + * @return + */ + public static boolean setEx(L2DatabaseFactory db, String query, Object... vars) + { + Connection con = null; + Statement statement = null; + PreparedStatement pstatement = null; + boolean successed = true; + + try + { + if(db == null) + db = L2DatabaseFactory.getInstance(); + + con = db.getConnection(); + if(vars.length == 0) + { + statement = con.createStatement(); + statement.executeUpdate(query); + statement.close(); + } + else + { + pstatement = con.prepareStatement(query); + setVars(pstatement, vars); + pstatement.executeUpdate(); + pstatement.close(); + } + con.close(); + } + catch(Exception e) + { + _log.warning("Could not execute update '" + query + "': " + e); + e.printStackTrace(); + successed = false; + } + finally + { + closeQuietly(con, pstatement); + closeQuietly(statement); + } + return successed; + } + + public static void setVars(PreparedStatement statement, Object... vars) throws SQLException + { + Number n; + long long_val; + double double_val; + for(int i = 0; i < vars.length; i++) + if(vars[i] instanceof Number) + { + n = (Number) vars[i]; + long_val = n.longValue(); + double_val = n.doubleValue(); + if(long_val == double_val) + statement.setLong(i + 1, long_val); + else + statement.setDouble(i + 1, double_val); + } + else if(vars[i] instanceof String) + statement.setString(i + 1, (String) vars[i]); + } + + public static boolean set(String query, Object... vars) + { + return setEx(null, query, vars); + } + + public static boolean set(String query) + { + return setEx(null, query); + } + + public static void closeQuietly(Connection conn) + { + try { + close(conn); + } catch (SQLException e) { // NOPMD + // quiet + } + } + + public static void closeQuietly(Connection conn, Statement stmt, ResultSet rs) { + + try { + closeQuietly(rs); + } finally { + try { + closeQuietly(stmt); + } finally { + closeQuietly(conn); + } + } + } + + public static void closeQuietly(Connection conn, Statement stmt) + { + try { + closeQuietly(stmt); + } finally { + closeQuietly(conn); + } + } + + public static void closeQuietly(ResultSet rs) { + try { + close(rs); + } catch (SQLException e) { // NOPMD + // quiet + } + } + + public static void closeQuietly(Statement stmt) { + try { + close(stmt); + } catch (SQLException e) { // NOPMD + // quiet + } + } + + public static void close(Connection conn) throws SQLException { + if (conn != null) { + conn.close(); + } + } + + public static void close(ResultSet rs) throws SQLException { + if (rs != null) { + rs.close(); + } + } + + public static void close(Statement stmt) throws SQLException { + if (stmt != null) { + stmt.close(); + } + } + } + Index: net.sf.l2j.gameserver;GameServer.JAVA =================================================================== --- net.sf.l2j.gameserver;GameServer.JAVA (revision) +++ net.sf.l2j.gameserver;GameServer.JAVA (working copy) + import Dev.AutoBackup.BackupDBSave; + StringUtil.printSection("DataBase Auto Save"); + if (Config.ENABLE_BACKUP_BOOLEAN) { + BackupDBSave.getInstance(); + LOGGER.info("[DataBase Auto Save]: Enabled"); + }else + { + LOGGER.info("[DataBase Auto Save]: Desatived"); + } Index: gameserver.config.aCis.aCis.properties =================================================================== --- gameserver.config.aCis.aCis.properties (revision) +++ gameserver.config.aCis.aCis.properties (working copy) # Enable Auto Save DataBase AutoSaveDB = True #Name DataBase #Ex: l2jdb URL_DB = aCis
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Google Docs - Exploit
2 min ago | 0.28 KB
SwapEngine Bug [build 1.3]
29 min ago | 0.28 KB
December smells like money
CSS | 42 min ago | 0.28 KB
✅ Changelly.com Exploit
55 min ago | 0.28 KB
Untitled
C | 10 hours ago | 0.88 KB
acg
1 day ago | 0.05 KB
AI METHODS
2 days ago | 0.29 KB
Untitled
2 days ago | 0.29 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!