# SyncTide — Backup Recovery Guide

## Prerequisites

- Windows 10/11 (64-bit)
- Python 3.14+ installed and available in PATH
- Visual Studio Build Tools (for Cython compilation)
- Internet connection (to download embedded Python, NSSM, Inno Setup, and pip packages)

## Step-by-Step Recovery

### Step 1: Extract the Backup

Extract the backup zip to the desired location. If restoring over an existing folder, delete it first or use `-Force`.

```powershell
Expand-Archive "SyncTide_source_backup_XXXXXXXX_XXXXXX.zip" -DestinationPath "C:\Users\<you>\Desktop\CSV_Folders\SyncTide" -Force
```

### Step 2: Open a Terminal

```powershell
cd "C:\Users\<you>\Desktop\CSV_Folders\SyncTide"
```

### Step 3: Create the Virtual Environment

```powershell
python -m venv .venv
.venv\Scripts\activate
```

### Step 4: Install Python Dependencies

```powershell
pip install -r requirements.txt
```

If you also need the supervisor/tray dependencies:

```powershell
pip install -r requirements_supervisor.txt
```

### Step 5: Verify the Setup

```powershell
python -c "import settings; print('DB URL:', settings.DB_URL[:30] + '...')"
```

If this fails, ensure you have a `.env` file configured (copy from `.env.example` and fill in your database credentials).

### Step 6: Rebuild the Release (Cython + Distribution + Installer)

```powershell
python build_release.py
```

This will:
1. Compile all `.py` modules to `.pyd` (Cython)
2. Create `dist/SyncTide-X.X.X/` with compiled modules + page stubs + assets
3. Download bundled installers (PostgreSQL, VC++, pgAdmin, embedded Python, NSSM)
4. Download Inno Setup (if not already present)
5. Build `SyncTideSetup-X.X.X.exe`

### Step 7: Verify the Build

After `build_release.py` completes, you should see:

```
dist/
  SyncTide-X.X.X/          <- Distribution folder (deployable as-is)
  SyncTideSetup-X.X.X.exe  <- Installer for client machines
```

## Quick Reference

| Task                        | Command                          |
|-----------------------------|----------------------------------|
| Run backend locally         | `start_backend.bat`              |
| Run UI locally              | `start_ui.bat`                   |
| Run ingestion worker        | `start_ingestion_worker.bat`     |
| Build release + installer   | `python build_release.py`        |
| Build installer only        | `python installer/build_installer.py` |
| Backup runtime (config+DB)  | `powershell backup_platform.ps1` |

## Notes

- The backup does NOT include: `.venv/`, `dist/`, `build/`, compiled `.pyd` files, or downloaded installers. All of these are regenerated by the steps above.
- The backup DOES include: all source code, installer scripts (`.pas`, `.iss`), migrations, setup scripts, assets, and configuration templates.
- If you need to restore the database as well, use a separate `pg_dump`/`pg_restore` workflow or the runtime backup from `backup_platform.ps1`.
