# CouchDB Sync Daemon Setup ## The Problem Files in CouchDB can be "read" by Obsidian's self-hosted sync plugin, but they don't automatically sync to the filesystem. The daemon only monitors changes but doesn't write files. ## The Solution The `sync_daemon.py` script watches CouchDB for changes and **writes files to disk in real-time**. ## Setup ### 1. Configure Your Vault Path Edit `sync_daemon.py` and set your Obsidian vault path: ```python TARGET_FOLDER = os.path.expanduser("~/ObsidianVault") # Change this! ``` Or use the current directory structure (seems like you have notes here): ```python TARGET_FOLDER = "/home/diego/Scratchpad/obsidian-magic/obsidian_automator" ``` ### 2. Run the Daemon ```bash cd obsidian_automator source .venv/bin/activate # or use your virtual environment python3 sync_daemon.py ``` ### 3. What It Does 1. **Initial Sync**: Downloads all notes from CouchDB to filesystem 2. **Real-time Watch**: Monitors CouchDB changes and updates files immediately 3. **Handles Chunks**: Reconstructs files from LiveSync's chunked storage format 4. **Skips Encryption**: Ignores encrypted files automatically ## Running as a Service (Optional) ### Using systemd (Linux) Create `/etc/systemd/system/obsidian-sync.service`: ```ini [Unit] Description=Obsidian CouchDB Sync Daemon After=network.target [Service] Type=simple User=diego WorkingDirectory=/home/diego/Scratchpad/obsidian-magic/obsidian_automator ExecStart=/home/diego/Scratchpad/obsidian-magic/obsidian_automator/.venv/bin/python3 sync_daemon.py Restart=always RestartSec=10 [Install] WantedBy=multi-user.target ``` Then: ```bash sudo systemctl daemon-reload sudo systemctl enable obsidian-sync sudo systemctl start obsidian-sync sudo systemctl status obsidian-sync ``` ### Using screen/tmux (Quick method) ```bash screen -S obsidian-sync cd obsidian_automator python3 sync_daemon.py # Press Ctrl+A, then D to detach ``` To reattach: `screen -r obsidian-sync` ## Troubleshooting ### Files Not Appearing - Check that `TARGET_FOLDER` path is correct - Ensure CouchDB credentials are correct - Check file permissions on target folder ### Connection Issues - Verify CouchDB is accessible: `curl http://100.100.112.48:5984/` - Check firewall rules - Verify database name is correct ### Encrypted Files The daemon automatically skips encrypted files. If you need to sync encrypted files, you'll need to configure the passphrase in the code. ## Architecture ``` CouchDB (LiveSync Format) ↓ sync_daemon.py (watches _changes feed) ↓ Filesystem (Obsidian Vault) ↓ Obsidian App (reads local files) ``` ## Key Files - `sync_daemon.py` - Main sync daemon (NEW) - `couch_sync.py` - CouchDBSync class (used by web UI) - `couch_manager.py` - CouchDB operations (move, flag, etc.) - `watch_changes.py` - Simple change monitor (doesn't write files)