131 lines
3.6 KiB
Markdown
131 lines
3.6 KiB
Markdown
|
|
# Obsidian CouchDB Sync - Problem & Solution
|
||
|
|
|
||
|
|
## What Was Wrong
|
||
|
|
|
||
|
|
Your setup had **three separate pieces** that don't work together:
|
||
|
|
|
||
|
|
1. ✅ **CouchDB** - Storing files (WORKING)
|
||
|
|
2. ✅ **Obsidian Self-Hosted Sync Plugin** - Reading from CouchDB (WORKING)
|
||
|
|
3. ❌ **Filesystem Sync** - Writing files to disk (MISSING!)
|
||
|
|
|
||
|
|
### Why Files Weren't Showing
|
||
|
|
|
||
|
|
The Obsidian plugin can READ files from CouchDB through its API, but:
|
||
|
|
- Files weren't being **written to the filesystem**
|
||
|
|
- Your `watch_changes.py` only **printed** changes, didn't save files
|
||
|
|
- Your `couch_sync.py` CAN sync, but it's not running continuously
|
||
|
|
|
||
|
|
## The Fix
|
||
|
|
|
||
|
|
I created `sync_daemon.py` which:
|
||
|
|
|
||
|
|
1. ✅ Connects to CouchDB
|
||
|
|
2. ✅ Does initial full sync (downloads all files)
|
||
|
|
3. ✅ Watches for changes in real-time
|
||
|
|
4. ✅ Writes updated files to disk immediately
|
||
|
|
5. ✅ Reconstructs files from LiveSync's chunk format
|
||
|
|
6. ✅ Skips encrypted files automatically
|
||
|
|
|
||
|
|
## Quick Start
|
||
|
|
|
||
|
|
### Step 1: Test Connection
|
||
|
|
```bash
|
||
|
|
cd obsidian_automator
|
||
|
|
python3 test_connection.py
|
||
|
|
```
|
||
|
|
|
||
|
|
This verifies CouchDB is accessible and shows your files.
|
||
|
|
|
||
|
|
### Step 2: Configure Target Folder
|
||
|
|
|
||
|
|
Edit `sync_daemon.py`, line 16:
|
||
|
|
```python
|
||
|
|
TARGET_FOLDER = "/path/to/your/obsidian/vault"
|
||
|
|
```
|
||
|
|
|
||
|
|
Or keep it syncing to current directory:
|
||
|
|
```python
|
||
|
|
TARGET_FOLDER = "/home/diego/Scratchpad/obsidian-magic/obsidian_automator"
|
||
|
|
```
|
||
|
|
|
||
|
|
### Step 3: Run Sync Daemon
|
||
|
|
```bash
|
||
|
|
python3 sync_daemon.py
|
||
|
|
```
|
||
|
|
|
||
|
|
You should see:
|
||
|
|
- Initial sync downloading all files
|
||
|
|
- Real-time updates as you edit in Obsidian
|
||
|
|
|
||
|
|
### Step 4 (Optional): Run as Background Service
|
||
|
|
|
||
|
|
See `SYNC_SETUP.md` for systemd service setup.
|
||
|
|
|
||
|
|
## How It Works
|
||
|
|
|
||
|
|
```
|
||
|
|
┌─────────────┐
|
||
|
|
│ Obsidian │ ← Edit files
|
||
|
|
└──────┬──────┘
|
||
|
|
│
|
||
|
|
↓
|
||
|
|
┌─────────────────┐
|
||
|
|
│ Self-Hosted │ ← Uploads to CouchDB
|
||
|
|
│ Sync Plugin │
|
||
|
|
└──────┬──────────┘
|
||
|
|
│
|
||
|
|
↓
|
||
|
|
┌──────────────┐
|
||
|
|
│ CouchDB │ ← Stores in chunks
|
||
|
|
└──────┬───────┘
|
||
|
|
│
|
||
|
|
↓ _changes feed
|
||
|
|
┌──────────────┐
|
||
|
|
│ sync_daemon │ ← NEW! Watches & writes files
|
||
|
|
└──────┬───────┘
|
||
|
|
│
|
||
|
|
↓
|
||
|
|
┌──────────────┐
|
||
|
|
│ Filesystem │ ← Files appear here!
|
||
|
|
└──────────────┘
|
||
|
|
```
|
||
|
|
|
||
|
|
## Files Changed/Created
|
||
|
|
|
||
|
|
- ✨ **sync_daemon.py** (NEW) - Main sync daemon
|
||
|
|
- ✨ **test_connection.py** (NEW) - Connection tester
|
||
|
|
- ✨ **SYNC_SETUP.md** (NEW) - Detailed setup guide
|
||
|
|
- ✨ **FIX_SUMMARY.md** (NEW) - This file
|
||
|
|
|
||
|
|
Existing files (not modified):
|
||
|
|
- `couch_sync.py` - Still used by web UI
|
||
|
|
- `couch_manager.py` - Still used for operations
|
||
|
|
- `watch_changes.py` - Keep for debugging
|
||
|
|
|
||
|
|
## Next Steps
|
||
|
|
|
||
|
|
1. Run `test_connection.py` to verify setup
|
||
|
|
2. Edit `TARGET_FOLDER` in `sync_daemon.py`
|
||
|
|
3. Run `sync_daemon.py`
|
||
|
|
4. Check that files appear in target folder
|
||
|
|
5. Make changes in Obsidian and watch them sync
|
||
|
|
6. (Optional) Set up as systemd service for auto-start
|
||
|
|
|
||
|
|
## Troubleshooting
|
||
|
|
|
||
|
|
**No files appearing?**
|
||
|
|
- Check `TARGET_FOLDER` path is correct and writable
|
||
|
|
- Verify CouchDB connection with `test_connection.py`
|
||
|
|
- Check daemon output for errors
|
||
|
|
|
||
|
|
**Connection refused?**
|
||
|
|
- Verify CouchDB is running: `curl http://100.100.112.48:5984/`
|
||
|
|
- Check credentials in `sync_daemon.py`
|
||
|
|
- Check firewall/network settings
|
||
|
|
|
||
|
|
**Files are encrypted?**
|
||
|
|
- Daemon skips encrypted files by default
|
||
|
|
- To sync encrypted files, need to add passphrase decryption
|
||
|
|
|
||
|
|
Need help? Check `SYNC_SETUP.md` for more details!
|