Update documentation

This commit is contained in:
2026-10-23 16:58:30 +03:00
parent 38bf4b36f9
commit d52db8cf52
2 changed files with 133 additions and 43 deletions
+42 -10
View File
@@ -1,16 +1,23 @@
# Quick Start: TrueNAS Piwigo → Docker # Quick Start: TrueNAS Piwigo → Docker (TrueNAS 27+)
## One-Line Commands ## One-Line Commands
### On TrueNAS (Backup) ### On TrueNAS (Backup)
```bash ```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) ### On Docker Host (Restore + Start)
```bash ```bash
# 1. Copy backup from TrueNAS to Docker host # 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) # 2. Run restore (set your passwords)
cd /opt/piwigo cd /opt/piwigo
@@ -26,12 +33,17 @@ docker-compose up -d
## Minimum Required Commands ## Minimum Required Commands
```bash ```bash
# TRUENAS: Run backup # TRUENAS: Run backup (with your actual paths)
ssh root@truenas 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 # 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 DB_ROOT_PASS=xxx DB_PASS=yyy ./restore-piwigo-docker.sh piwigo_backup_*.tar.gz
cp .env.example .env cp .env.example .env
# Edit .env with: DB_ROOT_PASS=xxx DB_PASS=yyy # Edit .env with: DB_ROOT_PASS=xxx DB_PASS=yyy
@@ -56,12 +68,26 @@ curl -I http://localhost:8080
| Need | Command | | Need | Command |
|------|---------| |------|---------|
| Custom backup location | `BACKUP_DEST=/mnt/pool/backups ./backup-piwigo-truenas.sh` | | 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 files | `SKIP_DB=true ./restore-piwigo-docker.sh backup.tar.gz` |
| Only restore database | `SKIP_FILES=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` | | 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` | | 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 ## File Locations After Migration
``` ```
@@ -77,8 +103,6 @@ curl -I http://localhost:8080
## Rollback Plan ## Rollback Plan
If something goes wrong:
```bash ```bash
# Stop Docker Piwigo # Stop Docker Piwigo
docker-compose down docker-compose down
@@ -86,5 +110,13 @@ docker-compose down
# TrueNAS app is untouched - just restart it in TrueNAS UI # TrueNAS app is untouched - just restart it in TrueNAS UI
# Or if you modified TrueNAS data, restore from backup: # Or if you modified TrueNAS data, restore from backup:
# (backup script keeps last 7 by default) # (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
``` ```
+91 -33
View File
@@ -1,6 +1,8 @@
# TrueNAS Piwigo App → Docker Migration # 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 ## Scripts
@@ -13,12 +15,13 @@ This repository contains scripts to backup a Piwigo instance running as a TrueNA
## Prerequisites ## Prerequisites
### On TrueNAS Host ### On TrueNAS Host (27+)
- TrueNAS with Piwigo app installed - TrueNAS 27+ with Piwigo app installed
- SSH access to TrueNAS (or use TrueNAS Shell) - SSH access to TrueNAS (or TrueNAS Shell)
- `k3s kubectl` available (usually at `/usr/local/bin/k3s kubectl`) - `docker` available (for database dump via container)
- `mariadb-dump` or `mysqldump` installed - **OR** `mariadb-dump`/`mysqldump` installed on host
- Write access to backup destination dataset - Write access to backup destination dataset
- Read access to Piwigo app datasets (configured in app settings)
### On Docker Host ### On Docker Host
- Docker Engine installed - Docker Engine installed
@@ -38,26 +41,30 @@ ssh root@truenas.local
# Copy the backup script to TrueNAS # Copy the backup script to TrueNAS
scp backup-piwigo-truenas.sh root@truenas.local:/tmp/ scp backup-piwigo-truenas.sh root@truenas.local:/tmp/
# Run the backup script # Run the backup script with your dataset paths
# You can set environment variables to customize behavior
APP_NAMESPACE=piwigo \ APP_NAMESPACE=piwigo \
BACKUP_DEST=/mnt/tank/backups/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 /tmp/backup-piwigo-truenas.sh
``` ```
**Environment Variables for Backup:** **Environment Variables for Backup:**
| Variable | Default | Description | | Variable | Default | Description |
|----------|---------|-------------| |----------|---------|-------------|
| `APP_NAMESPACE` | `piwigo` | Kubernetes namespace of Piwigo app |
| `BACKUP_DEST` | `/mnt/tank/backups/piwigo` | Destination dataset path | | `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_PORT` | `3306` | Database port |
| `DB_NAME` | `piwigo` | Database name | | `DB_NAME` | `piwigo` | Database name |
| `DB_USER` | `piwigo` | Database user | | `DB_USER` | `piwigo` | Database user |
| `DB_PASS` | auto-detect | Database password | | `DB_PASS` | **required** | Database password (or auto-detected) |
| `PVC_UPLOADS` | auto-detect | Uploads PVC name | | `DB_CONTAINER` | auto-detect | Database container name (e.g., `ep-piwigo-docker-piwigo-db-1`) |
| `PVC_CONFIG` | auto-detect | Config PVC name | | `DB_PASSWORD_ENV` | auto-detect | Password env var in container (`MYSQL_PASSWORD`, `MYSQL_ROOT_PASSWORD`, `MARIADB_PASSWORD`, etc.) |
| `PVC_GALLERIES` | auto-detect | Galleries PVC name | | `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 | | `RETENTION_COUNT` | `7` | Number of backups to keep |
| `COMPRESSION_LEVEL` | `6` | gzip compression (1-9) | | `COMPRESSION_LEVEL` | `6` | gzip compression (1-9) |
@@ -128,18 +135,20 @@ Open your browser to `http://<docker-host>:8080`
## Detailed Workflow ## Detailed Workflow
### Backup Process (TrueNAS) ### Backup Process (TrueNAS 27+)
The backup script performs these steps: The backup script performs these steps:
1. **Detection**: Finds Kubernetes namespace, database credentials, and PVCs 1. **Validate Paths**: Checks provided dataset paths or auto-detects common locations
2. **Manifests**: Exports all K8s resources (deployments, services, PVCs, secrets, etc.) 2. **Validate Database**: Tests connection via host tools OR docker exec
3. **Database**: Dumps MariaDB/MySQL database with `mariadb-dump`/`mysqldump` 3. **Database**: Dumps MariaDB/MySQL database using:
4. **Files**: Creates temporary pods to copy data from PVCs: - 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 - `uploads/` → Piwigo upload directory
- `config/` → Piwigo local/config directory - `config/` → Piwigo local/config directory
- `galleries/` → Piwigo galleries (if separate PVC) - `galleries/` → Piwigo galleries (if separate path)
5. **Archive**: Creates compressed `.tar.gz` with checksum 5. **Archive**: Creates compressed `.tar.gz` with SHA256 checksum
6. **Cleanup**: Removes old backups per retention policy 6. **Cleanup**: Removes old backups per retention policy
7. **Info**: Generates `RESTORE_INFO_<timestamp>.txt` with restore instructions 7. **Info**: Generates `RESTORE_INFO_<timestamp>.txt` with restore instructions
@@ -178,10 +187,8 @@ piwigo/
### Migration with Same Database Credentials ### Migration with Same Database Credentials
If you want to keep the same database passwords:
```bash ```bash
# On TrueNAS, note the DB_PASS from backup output or secret # On TrueNAS, set DB_PASS
# On Docker host, use same passwords: # On Docker host, use same passwords:
DB_ROOT_PASS=same_as_truenas \ DB_ROOT_PASS=same_as_truenas \
DB_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 ## Troubleshooting
### Backup Fails: "Database dump failed" ### Backup Fails: "Database dump failed"
1. Check database credentials are correct 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: 3. Verify database is accessible from TrueNAS host:
```bash ```bash
mariadb -h <DB_HOST> -u <DB_USER> -p<DB_PASS> <DB_NAME> -e "SELECT 1" # If host tools available
mariadb -h localhost -u piwigo -p<DB_PASS> piwigo -e "SELECT 1"
# If using docker
docker exec ep-piwigo-docker-piwigo-db-1 mariadb -u piwigo -p<DB_PASS> -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` 1. Verify dataset paths in TrueNAS app configuration
2. Set `PVC_UPLOADS`, `PVC_CONFIG`, `PVC_GALLERIES` explicitly 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 <container> | grep -i password`
3. Try setting `DB_PASSWORD_ENV=MYSQL_ROOT_PASSWORD` (common for root password)
### Restore Fails: "Database not ready" ### Restore Fails: "Database not ready"
1. Check database container logs: `docker-compose logs db` 1. Check database container logs: `docker-compose logs db`
2. Ensure `DB_ROOT_PASS` in `.env` matches what you passed to restore script 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" ### Piwigo Shows "Database Connection Failed"
@@ -242,14 +302,12 @@ PIWIGO_DATA_DIR=/data/piwigo \
### Permission Errors on Files ### Permission Errors on Files
```bash ```bash
# Fix permissions manually
docker run --rm -v /opt/piwigo/piwigo-data:/data alpine:latest \ docker run --rm -v /opt/piwigo/piwigo-data:/data alpine:latest \
sh -c "chown -R 33:33 /data && chmod -R 755 /data" sh -c "chown -R 33:33 /data && chmod -R 755 /data"
``` ```
### Large Backup Times Out ### Large Backup Times Out
For very large galleries, increase Docker Compose healthcheck timeouts or run restore in steps:
```bash ```bash
# Restore DB first # Restore DB first
SKIP_FILES=true ./restore-piwigo-docker.sh backup.tar.gz 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 1. Check the log output from both scripts
2. Verify all prerequisites are met 2. Verify all prerequisites are met
3. Ensure network connectivity between containers 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` 5. Check Docker logs: `docker-compose logs piwigo`
--- ---