# LendCore Database Backups

`backup_lendcore.php` creates the latest SQL dump as `sqlbackup/lendcore_latest.sql`. Each successful run replaces the previous backup and removes older `.sql` files from `sqlbackup/`. It runs once per invocation, so the hosting account's cron service controls the schedule. The recommended production schedule is hourly.

## cPanel setup

1. Upload `backup_lendcore.php` and the `sqlbackup/` directory into the LendCore application directory.
2. Ensure the directory is writable by the cPanel account. A typical permission is `750`; do not make it world-writable.
3. In cPanel, open **Cron Jobs** and create a job with this schedule:

```text
Minute: 0
Hour: *
Day: *
Month: *
Weekday: *
```

Use the command below, replacing the paths with the actual cPanel account paths:

```bash
/usr/local/bin/php /home/CPANEL_USER/path/to/LendCore/backup_lendcore.php >> /home/CPANEL_USER/logs/lendcore-backup.log 2>&1
```

This runs at the start of every hour. The cron interval is `0 * * * *`.

## mysqldump path

The script checks `MYSQLDUMP_PATH` in `.env`, followed by `/usr/bin/mysqldump` and `/usr/local/bin/mysqldump`. If cPanel uses another location, add its absolute path to `.env`:

```dotenv
MYSQLDUMP_PATH=/home/CPANEL_USER/bin/mysqldump
```

The script also supports the local XAMPP path automatically when run on Windows.

## Manual test

Run the same command from SSH or cPanel Terminal before enabling cron:

```bash
/usr/local/bin/php /home/CPANEL_USER/path/to/LendCore/backup_lendcore.php
```

Confirm that `sqlbackup/lendcore_latest.sql` exists and that its size is greater than zero. The script writes to a temporary file first and only replaces the latest `.sql` file after a successful dump.

## Security and retention

The `sqlbackup/.htaccess` file blocks Apache web access to the SQL files. Keep the directory outside `public_html` where possible, and restrict backup file permissions. SQL backups contain credentials and customer data; store and transfer them securely.

The script intentionally keeps only the latest backup. Copy `lendcore_latest.sql` to secure off-site storage if historical recovery points are required.