diff --git a/BACKUP.md b/BACKUP.md new file mode 100644 index 0000000..57076a4 --- /dev/null +++ b/BACKUP.md @@ -0,0 +1,75 @@ +# Experiments Database — Backup + +## Location +``` +/home/sam/synology/Backups/Experiments-DB-Backup/ +├── daily/ ← up to 5 change-triggered daily backups +├── weekly/ ← up to 2 unconditional weekly backups +├── .last_backup_state ← DB fingerprint from last backup run +└── backup.log ← all run output +``` + +## Scripts +``` +scripts/ +├── backup.sh ← main backup script +└── setup_cron.sh ← installs / updates cron entries (idempotent) +``` + +## Schedule +| Cron | Mode | Behaviour | +|------|------|-----------| +| `0 2 * * *` (daily 02:00) | `daily` | Compares DB fingerprint; skips if nothing changed | +| `0 3 * * 0` (Sunday 03:00) | `weekly` | Always dumps; ignores fingerprint | + +To re-install cron entries after a path change: +```bash +./scripts/setup_cron.sh +``` + +## Backup Format +Files are `pg_dump --format=custom --compress=9` (`.pgdump`). + +**Restore a backup:** +```bash +# Restore into a running container +docker exec -i experiments_postgres pg_restore \ + -U expuser -d experiments_db --clean \ + < /home/sam/synology/Backups/Experiments-DB-Backup/daily/.pgdump + +# Or restore to a fresh database +docker exec -i experiments_postgres createdb -U expuser experiments_db_restore +docker exec -i experiments_postgres pg_restore \ + -U expuser -d experiments_db_restore \ + < /path/to/file.pgdump +``` + +## Change Detection +The daily run fingerprints the database as: +``` +,,, +,, +``` +Any insert, update, or delete on any table shifts this string and triggers a backup. + +## Retention Policy +| Type | Keep | +|------|------| +| Daily | 5 most recent | +| Weekly | 2 most recent | + +Older files are automatically deleted after each successful dump. + +## Manual Run +```bash +# Force a backup right now (ignores change detection) +./scripts/backup.sh weekly + +# Run change-detect check manually +./scripts/backup.sh daily +``` + +## Verify Cron Is Installed +```bash +crontab -l | grep ExpDB +``` diff --git a/N8N_WORKFLOWS.md b/N8N_WORKFLOWS.md new file mode 100644 index 0000000..e192824 --- /dev/null +++ b/N8N_WORKFLOWS.md @@ -0,0 +1,293 @@ +# Experiments Database — n8n Workflows + +n8n is running at **http://localhost:5678** + +The Postgres credential **"Experiments DB (PostgreSQL)"** (id: `9iJuyA9iR5KUzmj5`) connects to `experiments_postgres:5432 / experiments_db` via the shared `llm-net` Docker network. + +--- + +## Workflow Index + +| ID | Workflow | Entity | +|----|----------|--------| +| `jjmtecjuHJPKZ4T7` | ExpDB · Experiments | `experiments` table | +| `HYnlIscuKwMW7blG` | ExpDB · Animals | `animals` table | +| `9emayzMpnhIZQxqd` | ExpDB · Daily Statuses | `daily_statuses` table | +| `hso5z2W1uO44bTP6` | ExpDB · Daily Analyses | `daily_analyses` table | +| `2s02OX1yibfqp6jK` | ExpDB · Session Files | `session_files` table | +| `T76NAYiFcCxHDKQB` | ExpDB · Audit Logs | `audit_logs` table | +| `lq3R3YqeHgxixrbZ` | ExpDB · Reports | cross-table queries | + +--- + +## How to Call a Workflow + +All workflows use an **Execute Workflow Trigger** — call them with an **Execute Workflow** node from any parent workflow. Pass a JSON object with `action` + the required fields. + +``` +Execute Workflow node + → Workflow: