diff --git a/QUICKSTART.md b/QUICKSTART.md index 7999d4d..4e554bf 100644 --- a/QUICKSTART.md +++ b/QUICKSTART.md @@ -1,16 +1,23 @@ -# Quick Start: TrueNAS Piwigo → Docker +# Quick Start: TrueNAS Piwigo → Docker (TrueNAS 27+) ## One-Line Commands ### On TrueNAS (Backup) ```bash -ssh root@truenas "APP_NAMESPACE=piwigo BACKUP_DEST=/mnt/tank/backups/piwigo bash -s" < backup-piwigo-truenas.sh +# Set your dataset paths and DB password +ssh root@truenas " \ + BACKUP_DEST=/mnt/stor0/backups/piwigo \ + PIWIGO_UPLOADS_PATH=/mnt/.ix-apps/app_mounts/piwigo/config/upload \ + PIWIGO_CONFIG_PATH=/mnt/.ix-apps/app_configs/piwigo/versions/1.4.17 \ + PIWIGO_GALLERIES_PATH=/mnt/.ix-apps/app_mounts/piwigo/config/galleries \ + DB_PASS=your_db_password \ + bash -s" < backup-piwigo-truenas.sh ``` ### On Docker Host (Restore + Start) ```bash # 1. Copy backup from TrueNAS to Docker host -scp root@truenas:/mnt/tank/backups/piwigo/piwigo_backup_*.tar.gz* /opt/piwigo/ +scp root@truenas:/mnt/stor0/backups/piwigo/piwigo_backup_*.tar.gz* /opt/piwigo/ # 2. Run restore (set your passwords) cd /opt/piwigo @@ -26,12 +33,17 @@ docker-compose up -d ## Minimum Required Commands ```bash -# TRUENAS: Run backup +# TRUENAS: Run backup (with your actual paths) ssh root@truenas -/tmp/backup-piwigo-truenas.sh +BACKUP_DEST=/mnt/stor0/backups/piwigo \ +PIWIGO_UPLOADS_PATH=/mnt/.ix-apps/app_mounts/piwigo/config/upload \ +PIWIGO_CONFIG_PATH=/mnt/.ix-apps/app_configs/piwigo/versions/1.4.17 \ +PIWIGO_GALLERIES_PATH=/mnt/.ix-apps/app_mounts/piwigo/config/galleries \ +DB_PASS=your_db_password \ +./backup-piwigo-truenas.sh # DOCKER HOST: Restore and start -scp root@truenas:/mnt/tank/backups/piwigo/piwigo_backup_*.tar.gz* . +scp root@truenas:/mnt/stor0/backups/piwigo/piwigo_backup_*.tar.gz* . DB_ROOT_PASS=xxx DB_PASS=yyy ./restore-piwigo-docker.sh piwigo_backup_*.tar.gz cp .env.example .env # Edit .env with: DB_ROOT_PASS=xxx DB_PASS=yyy @@ -56,12 +68,26 @@ curl -I http://localhost:8080 | Need | Command | |------|---------| | Custom backup location | `BACKUP_DEST=/mnt/pool/backups ./backup-piwigo-truenas.sh` | -| Different namespace | `APP_NAMESPACE=my-piwigo ./backup-piwigo-truenas.sh` | +| Specify DB container | `DB_CONTAINER=ep-piwigo-docker-piwigo-db-1 ./backup-piwigo-truenas.sh` | +| Specify password env var | `DB_PASSWORD_ENV=MYSQL_ROOT_PASSWORD ./backup-piwigo-truenas.sh` | | Only restore files | `SKIP_DB=true ./restore-piwigo-docker.sh backup.tar.gz` | | Only restore database | `SKIP_FILES=true ./restore-piwigo-docker.sh backup.tar.gz` | | Custom data dir | `PIWIGO_DATA_DIR=/data/piwigo ./restore-piwigo-docker.sh backup.tar.gz` | | Non-interactive | `FORCE=true ./restore-piwigo-docker.sh backup.tar.gz` | +## Finding Your Dataset Paths (TrueNAS 27+) + +```bash +# Find Piwigo mount paths +ls /mnt/.ix-apps/app_mounts/piwigo/ +ls /mnt/.ix-apps/app_configs/piwigo/ + +# Typical paths: +# /mnt/.ix-apps/app_mounts/piwigo/config/upload +# /mnt/.ix-apps/app_configs/piwigo/versions/X.X.X +# /mnt/.ix-apps/app_mounts/piwigo/config/galleries +``` + ## File Locations After Migration ``` @@ -77,8 +103,6 @@ curl -I http://localhost:8080 ## Rollback Plan -If something goes wrong: - ```bash # Stop Docker Piwigo docker-compose down @@ -86,5 +110,13 @@ docker-compose down # TrueNAS app is untouched - just restart it in TrueNAS UI # Or if you modified TrueNAS data, restore from backup: # (backup script keeps last 7 by default) -ls /mnt/tank/backups/piwigo/piwigo_backup_*.tar.gz +ls /mnt/stor0/backups/piwigo/piwigo_backup_*.tar.gz +``` + +## Critical .env Settings + +```bash +# REQUIRED - Database passwords +DB_ROOT_PASS=strong_random_password_here +DB_PASS=strong_random_password_here ``` \ No newline at end of file diff --git a/README.md b/README.md index 1fafca0..7b469b9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # TrueNAS Piwigo App → Docker Migration -This repository contains scripts to backup a Piwigo instance running as a TrueNAS App (Kubernetes/k3s) and restore it to a Docker container. +This repository contains scripts to backup a Piwigo instance running as a TrueNAS App and restore it to a Docker container. + +**Updated for TrueNAS 27+ (Electric Eel)** - No kubectl/k3s required. Works with direct dataset access. ## Scripts @@ -13,12 +15,13 @@ This repository contains scripts to backup a Piwigo instance running as a TrueNA ## Prerequisites -### On TrueNAS Host -- TrueNAS with Piwigo app installed -- SSH access to TrueNAS (or use TrueNAS Shell) -- `k3s kubectl` available (usually at `/usr/local/bin/k3s kubectl`) -- `mariadb-dump` or `mysqldump` installed +### On TrueNAS Host (27+) +- TrueNAS 27+ with Piwigo app installed +- SSH access to TrueNAS (or TrueNAS Shell) +- `docker` available (for database dump via container) +- **OR** `mariadb-dump`/`mysqldump` installed on host - Write access to backup destination dataset +- Read access to Piwigo app datasets (configured in app settings) ### On Docker Host - Docker Engine installed @@ -38,26 +41,30 @@ ssh root@truenas.local # Copy the backup script to TrueNAS scp backup-piwigo-truenas.sh root@truenas.local:/tmp/ -# Run the backup script -# You can set environment variables to customize behavior +# Run the backup script with your dataset paths APP_NAMESPACE=piwigo \ BACKUP_DEST=/mnt/tank/backups/piwigo \ +PIWIGO_UPLOADS_PATH=/mnt/.ix-apps/app_mounts/piwigo/config/upload \ +PIWIGO_CONFIG_PATH=/mnt/.ix-apps/app_configs/piwigo/versions/1.4.17 \ +PIWIGO_GALLERIES_PATH=/mnt/.ix-apps/app_mounts/piwigo/config/galleries \ +DB_PASS=your_database_password \ /tmp/backup-piwigo-truenas.sh ``` **Environment Variables for Backup:** | Variable | Default | Description | |----------|---------|-------------| -| `APP_NAMESPACE` | `piwigo` | Kubernetes namespace of Piwigo app | | `BACKUP_DEST` | `/mnt/tank/backups/piwigo` | Destination dataset path | -| `DB_HOST` | auto-detect | Database host | +| `DB_HOST` | `localhost` | Database host (if using host tools) | | `DB_PORT` | `3306` | Database port | | `DB_NAME` | `piwigo` | Database name | | `DB_USER` | `piwigo` | Database user | -| `DB_PASS` | auto-detect | Database password | -| `PVC_UPLOADS` | auto-detect | Uploads PVC name | -| `PVC_CONFIG` | auto-detect | Config PVC name | -| `PVC_GALLERIES` | auto-detect | Galleries PVC name | +| `DB_PASS` | **required** | Database password (or auto-detected) | +| `DB_CONTAINER` | auto-detect | Database container name (e.g., `ep-piwigo-docker-piwigo-db-1`) | +| `DB_PASSWORD_ENV` | auto-detect | Password env var in container (`MYSQL_PASSWORD`, `MYSQL_ROOT_PASSWORD`, `MARIADB_PASSWORD`, etc.) | +| `PIWIGO_UPLOADS_PATH` | **required** | Host path to uploads dataset | +| `PIWIGO_CONFIG_PATH` | **required** | Host path to config dataset | +| `PIWIGO_GALLERIES_PATH` | optional | Host path to galleries dataset | | `RETENTION_COUNT` | `7` | Number of backups to keep | | `COMPRESSION_LEVEL` | `6` | gzip compression (1-9) | @@ -128,18 +135,20 @@ Open your browser to `http://:8080` ## Detailed Workflow -### Backup Process (TrueNAS) +### Backup Process (TrueNAS 27+) The backup script performs these steps: -1. **Detection**: Finds Kubernetes namespace, database credentials, and PVCs -2. **Manifests**: Exports all K8s resources (deployments, services, PVCs, secrets, etc.) -3. **Database**: Dumps MariaDB/MySQL database with `mariadb-dump`/`mysqldump` -4. **Files**: Creates temporary pods to copy data from PVCs: +1. **Validate Paths**: Checks provided dataset paths or auto-detects common locations +2. **Validate Database**: Tests connection via host tools OR docker exec +3. **Database**: Dumps MariaDB/MySQL database using: + - Host tools (`mariadb-dump`/`mysqldump`) if available + - `docker exec` into database container if host tools not available +4. **Files**: Copies data directly from host filesystem paths using `rsync`: - `uploads/` → Piwigo upload directory - `config/` → Piwigo local/config directory - - `galleries/` → Piwigo galleries (if separate PVC) -5. **Archive**: Creates compressed `.tar.gz` with checksum + - `galleries/` → Piwigo galleries (if separate path) +5. **Archive**: Creates compressed `.tar.gz` with SHA256 checksum 6. **Cleanup**: Removes old backups per retention policy 7. **Info**: Generates `RESTORE_INFO_.txt` with restore instructions @@ -178,10 +187,8 @@ piwigo/ ### Migration with Same Database Credentials -If you want to keep the same database passwords: - ```bash -# On TrueNAS, note the DB_PASS from backup output or secret +# On TrueNAS, set DB_PASS # On Docker host, use same passwords: DB_ROOT_PASS=same_as_truenas \ DB_PASS=same_as_truenas \ @@ -211,27 +218,80 @@ PIWIGO_DATA_DIR=/data/piwigo \ --- +## Finding TrueNAS 27+ Dataset Paths + +In TrueNAS 27+, app data is stored in `.ix-apps` datasets. Find your paths: + +```bash +# List app mounts +ls /mnt/.ix-apps/app_mounts/ + +# List app configs +ls /mnt/.ix-apps/app_configs/ + +# For Piwigo, typical paths are: +# /mnt/.ix-apps/app_mounts/piwigo/config/upload +# /mnt/.ix-apps/app_configs/piwigo/versions/X.X.X +# /mnt/.ix-apps/app_mounts/piwigo/config/galleries +``` + +--- + +## Database Credentials + +### Option 1: Set DB_PASS directly (recommended) +```bash +DB_PASS=your_password ./backup-piwigo-truenas.sh +``` + +### Option 2: Auto-detect from container +The script checks these env vars in the database container: +- `MYSQL_PASSWORD` +- `MYSQL_ROOT_PASSWORD` +- `MARIADB_PASSWORD` +- `MARIADB_ROOT_PASSWORD` +- Docker secret files (`*_FILE` variants) + +### Option 3: Specify container and env var +```bash +DB_CONTAINER=ep-piwigo-docker-piwigo-db-1 \ +DB_PASSWORD_ENV=MYSQL_ROOT_PASSWORD \ +./backup-piwigo-truenas.sh +``` + +--- + ## Troubleshooting ### Backup Fails: "Database dump failed" 1. Check database credentials are correct -2. Ensure `mariadb-dump` or `mysqldump` is installed on TrueNAS +2. Ensure `mariadb-dump`/`mysqldump` is installed on TrueNAS **OR** docker is available 3. Verify database is accessible from TrueNAS host: ```bash - mariadb -h -u -p -e "SELECT 1" + # If host tools available + mariadb -h localhost -u piwigo -p piwigo -e "SELECT 1" + + # If using docker + docker exec ep-piwigo-docker-piwigo-db-1 mariadb -u piwigo -p -e "SELECT 1" ``` -### Backup Fails: "PVC not found" +### Backup Fails: "Path does not exist" -1. Check PVC names in TrueNAS: `k3s kubectl get pvc -n piwigo` -2. Set `PVC_UPLOADS`, `PVC_CONFIG`, `PVC_GALLERIES` explicitly +1. Verify dataset paths in TrueNAS app configuration +2. Check `/mnt/.ix-apps/app_mounts/` and `/mnt/.ix-apps/app_configs/` +3. Set `PIWIGO_UPLOADS_PATH`, `PIWIGO_CONFIG_PATH`, `PIWIGO_GALLERIES_PATH` explicitly + +### Backup Fails: "Cannot connect to database in container" + +1. Check container name: `docker ps | grep -i mariadb` +2. Verify password env var name: `docker inspect | grep -i password` +3. Try setting `DB_PASSWORD_ENV=MYSQL_ROOT_PASSWORD` (common for root password) ### Restore Fails: "Database not ready" 1. Check database container logs: `docker-compose logs db` 2. Ensure `DB_ROOT_PASS` in `.env` matches what you passed to restore script -3. Increase startup wait time in script if needed ### Piwigo Shows "Database Connection Failed" @@ -242,14 +302,12 @@ PIWIGO_DATA_DIR=/data/piwigo \ ### Permission Errors on Files ```bash -# Fix permissions manually docker run --rm -v /opt/piwigo/piwigo-data:/data alpine:latest \ sh -c "chown -R 33:33 /data && chmod -R 755 /data" ``` ### Large Backup Times Out -For very large galleries, increase Docker Compose healthcheck timeouts or run restore in steps: ```bash # Restore DB first SKIP_FILES=true ./restore-piwigo-docker.sh backup.tar.gz @@ -322,7 +380,7 @@ If you encounter issues: 1. Check the log output from both scripts 2. Verify all prerequisites are met 3. Ensure network connectivity between containers -4. Check TrueNAS app logs: `k3s kubectl logs -n piwigo -l app=piwigo` +4. Check TrueNAS app logs in TrueNAS UI 5. Check Docker logs: `docker-compose logs piwigo` ---