Automating Backups for AppGini Applications Using Task Scheduler and Mysqldump (Windows)
If you’re using AppGini to build and deploy PHP applications backed by MySQL or MariaDB, automating database backups is crucial to protect your data from accidental loss or corruption. This tutorial will walk you through automating backups on Windows using Task Scheduler and mysqldump, with steps tailored specifically for AppGini apps.
Why Automate Backups?
Your AppGini app’s database holds essential data — such as user records, custom tables, and application settings. Automating backups ensures you can quickly recover your app’s functionality in case of:
- Hardware failures
- Software bugs
- Human errors
- Security breaches
On Windows, mysqldump combined with Task Scheduler provides a reliable way to automate these backups.
Step 1: Locate Your Database Credentials
AppGini stores database connection details in the config.php
file, typically located in your app’s root directory. Open the file in a text editor and locate the following variables:
|
|
Take note of:
- Database server:
$dbServer
- Database username:
$dbUsername
- Database password:
$dbPassword
- Database name:
$dbDatabase
- Database port:
$dbPort
These credentials will be used in the backup script.
Step 2: Locate and Test the mysqldump
Command
Before automating backups, we need to identify where mysqldump.exe
is located on your machine. Follow these steps:
Locate mysqldump
-
Open PowerShell.
-
Run the following command to search for
mysqldump.exe
:1
Get-ChildItem -Path "C:\Program Files", "C:\Program Files (x86)" -Recurse -Filter "mysqldump.exe" -ErrorAction SilentlyContinue
This will search common installation directories for MySQL and output the full path to
mysqldump.exe
. -
Note the full path of the executable (e.g.,
C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqldump.exe
).If no results are found, ensure you have MySQL or MariaDB installed, and
mysqldump
is included in your installation.
Test the mysqldump
Command
Once you’ve located mysqldump.exe
, test it to ensure it works correctly with your database. Run the following PowerShell command:
|
|
Replace:
C:\Path\To\mysqldump.exe
with the path tomysqldump
you found earlier.northwind
with the value of$dbDatabase
.Password123$
with the value of$dbPassword
.localhost
with the value of$dbServer
.3306
with the value of$dbPort
.C:\backups\northwind_backup.sql
with your desired backup file path.
If the command runs successfully, a .sql
file will appear at the specified location. This file contains the database dump.
Step 3: Create a Backup Script
Now, let’s create a PowerShell script that automates the backup process. This script will:
- Use the credentials from
config.php
- Save backups with timestamps
- Optionally, delete old backups to save disk space
Example PowerShell Backup Script
- Open Notepad (or your favorite text editor) and paste the following script:
|
|
- Save the file as
appgini_backup.ps1
in a secure location, such asC:\scripts
.
Step 4: Automate with Task Scheduler
To schedule the backup script to run automatically, use Task Scheduler:
- Open Task Scheduler (
Win + R
, typetaskschd.msc
, and press Enter). - Click Create Task from the right-hand menu.
- In the General tab:
- Name the task (e.g.,
AppGini Database Backup
). - Select Run whether user is logged on or not.
- Check Run with highest privileges.
- Name the task (e.g.,
- In the Triggers tab:
- Click New to add a trigger.
- Set the backup schedule (e.g., Daily at 2:00 AM).
- In the Actions tab:
- Click New.
- Set Action to Start a Program.
- For Program/script, enter:
1
powershell.exe
- For Add arguments, enter:
1
-File "C:\scripts\appgini_backup.ps1"
- In the Conditions and Settings tabs, adjust options as needed (e.g., stop the task if it runs longer than 1 hour).
- Click OK and enter your username/password when prompted.
Step 5: Verify the Backup
-
Wait for the task to run at its scheduled time (or execute it manually by right-clicking the task and selecting Run).
-
Check the backup directory (e.g.,
C:\backups
) for new.sql
files. -
Test restoring a backup to confirm it works:
1
& "C:\Path\To\mysql.exe" -u northwind -pPassword123$ -h localhost -P 3306 northwind < C:\backups\northwind_backup.sql
By ensuring mysqldump
is correctly located and tested, as shown above, you can create a reliable backup process for your AppGini application!