# Backups

## What is backed up, and when

| When (Sri Lanka time) | What | Kept on the server |
|---|---|---|
| Every night, 2:00 AM | **Database** (all customers, jobs, invoices, payments, stock, settings, users) | The newest 14, plus one per week for the last 8 weeks |
| Every Sunday, 2:30 AM | **Files**: device photos, job card / invoice / quotation PDFs, signatures, logo, part photos, supplier bills | The newest 8 |
| Every Sunday, 7:00 AM | **Email to admins**: the newest database backup attached if under 10 MB, otherwise a reminder to download it | — |

All run from the one cPanel cron line (`php artisan schedule:run` every minute).

- The zips are in `storage/app/private/backups/` on the server. That folder is **not** reachable from the web (only `public/` is).
- Admins download them from **Admin → Backups**. Every download is written in the Activity Log.
- **Backup database now** makes one straight away. **Backup files now** starts in the background and appears within a few minutes.
- **System health** shows the time of the last database backup.

### How the database is copied

1. **mysqldump**, if the hosting lets PHP run it (fastest, the standard tool).
2. If mysqldump is missing, blocked, or fails: a **PHP dump** (no programs needed). Both make a normal `database.sql` that phpMyAdmin can import.

The Backups page shows which one your server uses. If mysqldump is installed in an unusual place, put its folder in `.env`:

```
BACKUP_MYSQLDUMP_PATH=/usr/bin
```

## Copy the backups to Google Drive every week (about 5 minutes)

A backup that lives only on the server is lost if the server is lost. Keep a copy in Google Drive.

**Once:**

1. Open <https://drive.google.com> with the shop's Google account.
2. **New → New folder**, name it `AppleTek Backups`.
3. Do **not** share this folder. The zips contain customer names, phone numbers and invoices.

**Every Sunday (after the 7:00 AM backup email):**

1. On a computer, log in to the repair system as admin → **Admin → Backups**.
2. Click **Download** on the newest **Database** backup, then on the newest **Files** backup.
   (If the weekly email had the database backup attached, you can save that attachment to Drive instead: open the email → hover over the attachment → **Add to Drive** → move it into `AppleTek Backups`.)
3. Open the `AppleTek Backups` folder in Google Drive and **drag the two .zip files into it**. Wait until it says *Upload complete*.
4. Delete the downloaded zips from the computer's Downloads folder.
5. Once a month: delete zips older than about 2 months from the Drive folder, to save space.

**Tip:** with *Google Drive for desktop* installed on the shop PC, you can download straight into the synced `AppleTek Backups` folder and it uploads by itself.

If the backup email does not arrive on Sunday, or the Backups page shows a red box, open **Admin → System health**: the cron job may have stopped.

## Restore (only if data is lost)

Restoring **replaces** the live data. Make a fresh "Backup database now" first if the system still works, and ask your developer if you are unsure.

**Database**

1. Unzip the database backup. Inside is `database.sql`.
2. cPanel → **phpMyAdmin** → click the shop's database on the left.
3. **Import** → choose `database.sql` → **Go**.
   For a very big file, ask LankaHost to import it, or use SSH: `mysql -u USER -p DATABASE < database.sql`.

**Files**

1. Unzip the files backup on your PC. Inside is a folder `files`.
2. Zip the **contents** of `files` (the folders `jobs`, `branding`, …) again, upload that zip with cPanel → **File Manager** into `/home/mytechno/appletek-app/storage/app/private/`, and **Extract** it there.
