Greetings everyone!

I have some codes in my application which makes a backup of mysql database and save the backup .sql file to a location on the hard disk. I made the code in like 2013/early 2014, I think I was then using a now older version of mysql, it worked perfectly.

But now, when I use this, it takes the backup as usual, no problem with the backup itself, the problem, when that code runs, it brings up a black command promp window which shows the used mysql user-name and the password used PLAINLY. After all the hard work I have done to ecrypt the password, this code simple prints out the real password and username just PLAINLY.

I am asking if anyone can suggest to me a better way of taking my backup and restoring them from VB.NET

I'm pasting the backup code here below, but please note that ALL the variables that you see have been well declared before being used and there is no problem with them at all. I decided to leave the declarations code away so as not to post a lengthy unneccessary code here. I'm posting the actual line where backup takes place, thanks.

Code:

Process.Start("" & dumpPath & "", " -u " & dbuser & " -p" & dbpassword & " " & dbname & " -r " & locationOfBackup & "")
**This uses the mysqldump to create backups/dumps, the variable "dumpPath" above is the location of the dump file in the host computer.

Thanks for any inputs.

Recommended Answers

All 4 Replies

You can just hide the console instead. Use something like

 Proc.StartInfo.CreateNoWindow = True

Or but I'm not sure if it will apply, just before your essential information try hiding it using the bat code within your code you will do something like:

 Proc.Send {"The code to turn on the char hide here", "Enter"}

NOTE: not sure of the format but it must have or start with "Send" but the rest is like the above, and also note that at least for me when I used this method I had to close any on top app running like Task manager because these make the command prompt loose focus and the typing will be done on an on top app or app with focus.

This sends one commands to command at a time so you will have more commands.

Thanks Mr.MM, I have one additional question, when taking a backup, instead of specifying a filename as something.sql, can I trick into giving it an extension that is unreadable by sql/text editor (say .gov), then when restoring the backup, rip off the .gov extension and put .sql and then restore the backup??

Yes that's achievable, you will have to make sure you have used an extension that is not used by any file, since the sample I did bellow only checks and get a list of files but an extension. Also since you will be working with two extension you will have to code them separately one for extracting which will search for ".gov" and change it to ".sql".

Suppose your path is "D:\Test\" and you have more then one file inside. So you can do it like this:

 Dim D As DirectoryInfo = New DirectoryInfo("D:\Test\")
 For Each File As FileInfo In D.GetFiles("*.sql")
 Dim OriginalFileName As String
 OriginalFileName  = File        
 Dim result As String
 result = Path.ChangeExtension(OriginalFileName, ".gov")
 File.Move(OriginalFileName ,result)
 Next

Now you can use the very same code above for searching for ".gov" files to change them back to ".sql". Also note that you will have to swap around the extension to set it back to the original.

You can place the above code under a button to change extension, then copy it again and past it on the button to set to original and on the code just change the extensions.

HTH.

Thank you Mr.M! I will definitely try this & your code and come back here for feedback.
Thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.