Have you also noticed that the database backup feature built into AppGini web applications does not work on Windows? The solution is quite simple, as I found out today. Read this post to see how we can solve this problem.
Database Backup
Maybe you have already seen the database backup function in the admin area of your AppGini application:
Click the Create Backup File
button, confirm the prompt and check if it works for you:
Problem
I don't get any backup but I get the following error message:
(mysqldump --no-tablespaces -u"root" -p**** -h"localhost" "..." -r "C:/xampp/htdocs/...../admin"/backups/....sql) 2>&1
Der Befehl "mysqldump" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
This is not only the case on your Windows development computer, but also when your application is installed on a Windows server at the customer's site. Database backup is even more important in customer's productive environment.
Reason
The Apache webserver tries to execute a program called mysqldump
on the server, but this program is not found.
Solution
The solution to this is actually quite simple. The easiest way is: we have to tell our Webserver (Apache) where to look for this program. For this we can use the environment variable Path
of the Windows system environment.
tl;dr
- Add the following directory name to your Windows Systemenvironment
PATH
variable (XAMPP):C:\xampp\mysql\bin
- Restart your webserver
Step by step
Locate the local mysql/bin
directory (on your machine or on the server) and copy the full directory name to the clipboard.
Note: The screenshot above shows the installation directory of my XAMPP environment. This directory will be different when using a different webserver like WAMP.
Open System environment editor
Click button for Environment Variables
At the bottom part, find Path
variable and edit the row
Create new entry...
...paste directory name and close all open dialogs using OK button.
Although you have added the mysql/bin
directory, your Apache process does not know about this, yet. By default it "reads" environment variables on process start. So we have to restart our webserver. This will force Apache to read the (modified) environment variables including Path
variable.
Please note that your web-applications running on that webserver will not be available for a few seconds. If this is critical for your users, you should postpone restart to maintenance times.
Restart Apache webserver
by using services management console
Restart your (Apache) webserver in service management console (services.msc).
or
by using XAMPP Control Panel
You can also use XAMPP-Control Panel for this, if you are more familiar with that.
Then you have to stop Apache first, confirm Admin-prompt, then start Apache and confirm Admin prompt again.
Test backup function
Test backup function again:
That's it. Apache was able to find mysqldump
program and created a backup file of our database. Restore works as well, now.
Summary
Finding the reason and solution was much easier than expected. I hope this blog post will help you in the future!