B4J Question Can't use MySQLDump to backup data - any suggestions on how to do this within my B4J code

Fr Simon Rundell

Member
Licensed User
Longtime User
I have a School Library App written in B4J and want to implement a backup from within the system. In my development environment a jShell call to mysqldump worked really well to export a .sql full backup. Unfortunately in the production environment, the account running the App does not have permissions to run mysqldump, so I'm thinking I could just execute mysql queries to generate the same output.

Has anyone done anything like this? Any advice on the best way to set about this?

Fr. Simon
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Not per se unfortunately. but you can use a library like this one:

You may need to wrap it tho.
 
Upvote 0

Fr Simon Rundell

Member
Licensed User
Longtime User
UPDATE:

I managed to compile the mysql-backup4j into a jar file and now I'm working on instantiating it as an #AdditionalJar

From what I can make out from the java examples on Seun Matt's website, (https://smattme.com/blog/technology...atabase-programmatically-using-mysql-backup4j), I need to set up some properties as configuration,

They are these:
Configuration as defined in Java:
//required properties for exporting of db
Properties properties = new Properties();
properties.setProperty(MysqlExportService.DB_NAME, "database-name");
properties.setProperty(MysqlExportService.DB_USERNAME, "root");
properties.setProperty(MysqlExportService.DB_PASSWORD, "root");
        
//properties relating to email config
properties.setProperty(MysqlExportService.EMAIL_HOST, "smtp.mailtrap.io");
properties.setProperty(MysqlExportService.EMAIL_PORT, "25");
properties.setProperty(MysqlExportService.EMAIL_USERNAME, "mailtrap-username");
properties.setProperty(MysqlExportService.EMAIL_PASSWORD, "mailtrap-password");
properties.setProperty(MysqlExportService.EMAIL_FROM, "[email protected]");
properties.setProperty(MysqlExportService.EMAIL_TO, "[email protected]");

//set the outputs temp dir
properties.setProperty(MysqlExportService.TEMP_DIR, new File("external").getPath());

MysqlExportService mysqlExportService = new MysqlExportService(properties);
mysqlExportService.export();

But, B4J won't accept a Map as a suitable object to pass the config in

Can't Pass a Map to Initialize...:
    '===========INITILIZE BACKUP OBJECT====================
    Private DBackup As JavaObject
    Dim Prpt As Map
    Prpt.Initialize
    Prpt.Put("DB_NAME", DBName)                  ' defined elsewhwre
    Prpt.Put("DB_USERNAME", DBUsername)
    Prpt.Put("DB_PASSWORD", DBPassword)
    Prpt.Put("EMAIL_HOST", "smtp.server.com")
    Prpt.Put("EMAIL_PORT", "465")
    Prpt.Put("EMAIL_USERNAME", "emailuser")
    Prpt.Put("EMAIL_PASSWORD", "emailpass")
    Prpt.Put("EMAIL_FROM", "[email protected]")
    Prpt.Put("EMAIL_TO", "[email protected]")
    Prpt.Put("TEMP_DIR", "C:\Users\Public\Documents")
    
    DBackup.InitializeNewInstance("com.smattme.mysql-backup4j", Prpt)
    
    DBackup.RunMethod("export", Null)

If anyone has any pointers or ideas, I'd be really grateful...
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
If anyone has any pointers or ideas
You can not use a B4A Map to replace a java Properties.
Use inlinejava to create a valid Properties or iterate through the map and fill the Properties (in your wrapper).
 
Upvote 0

teddybear

Well-Known Member
Licensed User
UPDATE:

I managed to compile the mysql-backup4j into a jar file and now I'm working on instantiating it as an #AdditionalJar

From what I can make out from the java examples on Seun Matt's website, (https://smattme.com/blog/technology...atabase-programmatically-using-mysql-backup4j), I need to set up some properties as configuration,

They are these:
Configuration as defined in Java:
//required properties for exporting of db
Properties properties = new Properties();
properties.setProperty(MysqlExportService.DB_NAME, "database-name");
properties.setProperty(MysqlExportService.DB_USERNAME, "root");
properties.setProperty(MysqlExportService.DB_PASSWORD, "root");
       
//properties relating to email config
properties.setProperty(MysqlExportService.EMAIL_HOST, "smtp.mailtrap.io");
properties.setProperty(MysqlExportService.EMAIL_PORT, "25");
properties.setProperty(MysqlExportService.EMAIL_USERNAME, "mailtrap-username");
properties.setProperty(MysqlExportService.EMAIL_PASSWORD, "mailtrap-password");
properties.setProperty(MysqlExportService.EMAIL_FROM, "[email protected]");
properties.setProperty(MysqlExportService.EMAIL_TO, "[email protected]");

//set the outputs temp dir
properties.setProperty(MysqlExportService.TEMP_DIR, new File("external").getPath());

MysqlExportService mysqlExportService = new MysqlExportService(properties);
mysqlExportService.export();

But, B4J won't accept a Map as a suitable object to pass the config in

Can't Pass a Map to Initialize...'t Pass a Map to Initialize...:
    '===========INITILIZE BACKUP OBJECT====================
    Private DBackup As JavaObject
    Dim Prpt As Map
    Prpt.Initialize
    Prpt.Put("DB_NAME", DBName)                  ' defined elsewhwre
    Prpt.Put("DB_USERNAME", DBUsername)
    Prpt.Put("DB_PASSWORD", DBPassword)
    Prpt.Put("EMAIL_HOST", "smtp.server.com")
    Prpt.Put("EMAIL_PORT", "465")
    Prpt.Put("EMAIL_USERNAME", "emailuser")
    Prpt.Put("EMAIL_PASSWORD", "emailpass")
    Prpt.Put("EMAIL_FROM", "[email protected]")
    Prpt.Put("EMAIL_TO", "[email protected]")
    Prpt.Put("TEMP_DIR", "C:\Users\Public\Documents")
   
    DBackup.InitializeNewInstance("com.smattme.mysql-backup4j", Prpt)
   
    DBackup.RunMethod("export", Null)

If anyone has any pointers or ideas, I'd be really grateful...
A simple way is that write the properties file and pass filename to inline java. then load it

 
Upvote 0

teddybear

Well-Known Member
Licensed User
Sounds great, but I haven't spotted how to make that happen yet...
The properties file is like this:

B4X:
DB_NAME=database-name
DB_USERNAME=root
...
You can put it to "/yourpath/properties.cfg"

In java, you just need to do loading the properties file, like below:
Java:
//required properties for exporting of db
Properties properties = new Properties();
/* Comment set properties
properties.setProperty(MysqlExportService.DB_NAME, "database-name");
properties.setProperty(MysqlExportService.DB_USERNAME, "root");
...
*/

// Added read properties from config file
FileInputStream fis = new FileInputStream("/yourpath/properties.cfg");
properties.load(fis);
//-
MysqlExportService mysqlExportService = new MysqlExportService(properties);
mysqlExportService.export();

In b4j, you just write the properties to a folder you specified if you need to do that, and then run export method .

B4X:
   'Write properties to /yourpath/properties.cfg'

    DBackup.InitializeNewInstance("com.smattme.mysql-backup4j", Null)
 
    DBackup.RunMethod("export", Null)
 
Upvote 0
Top