|
| 1 | +--- |
| 2 | +title: Troubleshooting |
| 3 | +description: Common issues and solutions for Dnote server |
| 4 | +weight: 10 |
| 5 | +--- |
| 6 | + |
| 7 | +## Server Data Management |
| 8 | + |
| 9 | +### Clearing Server Data |
| 10 | + |
| 11 | +If you need to reset your server data (for example, to start fresh or resolve sync issues), you can directly modify the SQLite database. |
| 12 | + |
| 13 | +**Warning:** These operations are destructive and will permanently delete data. Always create a backup first. |
| 14 | + |
| 15 | +#### Backup First |
| 16 | + |
| 17 | +```bash |
| 18 | +# Create a backup |
| 19 | +sqlite3 /var/lib/dnote/server.db ".backup /var/lib/dnote/backups/backup-$(date +%Y%m%d-%H%M%S).db" |
| 20 | +``` |
| 21 | + |
| 22 | +#### Clear All Data for a User |
| 23 | + |
| 24 | +To delete all books and notes for a specific user: |
| 25 | + |
| 26 | +```bash |
| 27 | +# Connect to database |
| 28 | +sqlite3 /var/lib/dnote/server.db |
| 29 | + |
| 30 | +# Find your user ID |
| 31 | +SELECT id, email FROM users; |
| 32 | + |
| 33 | +# Delete all notes and books for user (replace USER_ID with your user ID) |
| 34 | +DELETE FROM notes WHERE user_id = USER_ID; |
| 35 | +DELETE FROM books WHERE user_id = USER_ID; |
| 36 | + |
| 37 | +# Reset user's sync state to empty |
| 38 | +UPDATE users SET max_usn = 0 WHERE id = USER_ID; |
| 39 | + |
| 40 | +# Verify |
| 41 | +SELECT COUNT(*) FROM notes WHERE user_id = USER_ID; |
| 42 | +SELECT COUNT(*) FROM books WHERE user_id = USER_ID; |
| 43 | + |
| 44 | +# Exit |
| 45 | +.quit |
| 46 | +``` |
| 47 | + |
| 48 | +#### Clear All Data (All Users) |
| 49 | + |
| 50 | +To completely reset the server (useful for testing or fresh start): |
| 51 | + |
| 52 | +```bash |
| 53 | +sqlite3 /var/lib/dnote/server.db << EOF |
| 54 | +DELETE FROM notes; |
| 55 | +DELETE FROM books; |
| 56 | +UPDATE users SET max_usn = 0; |
| 57 | +VACUUM; |
| 58 | +EOF |
| 59 | +``` |
| 60 | + |
| 61 | +#### After Clearing Server Data |
| 62 | + |
| 63 | +After clearing server data, clients will need to re-sync. The next time a client syncs: |
| 64 | + |
| 65 | +1. The server is now empty (`max_usn = 0`) |
| 66 | +2. Clients with local data will be prompted to upload their data |
| 67 | +3. Confirm the upload to restore data from that client |
| 68 | + |
| 69 | +**Note:** Only confirm the upload from the client with the data you want to keep. If you have multiple clients, pick one to upload from, then sync the others normally afterward. |
| 70 | + |
| 71 | +## Sync Modes |
| 72 | + |
| 73 | +### Full Sync vs Incremental Sync |
| 74 | + |
| 75 | +Dnote supports two sync modes: |
| 76 | + |
| 77 | +#### Incremental Sync (Default) |
| 78 | + |
| 79 | +The default sync mode. It only syncs changes since your last sync: |
| 80 | + |
| 81 | +```bash |
| 82 | +dnote sync |
| 83 | +``` |
| 84 | + |
| 85 | +**How it works:** |
| 86 | +- Downloads only new/changed items from server (based on USN) |
| 87 | +- Uploads only local changes (dirty items) |
| 88 | +- Fast and efficient for regular use |
| 89 | + |
| 90 | +#### Full Sync |
| 91 | + |
| 92 | +Downloads **all** data from the server and reconciles with local state: |
| 93 | + |
| 94 | +```bash |
| 95 | +dnote sync --full |
| 96 | +``` |
| 97 | + |
| 98 | +**How it works:** |
| 99 | +1. Downloads ALL books and notes from server (not just changes) |
| 100 | +2. **Cleans up orphaned local data** - deletes local items that don't exist on server (unless they're new/dirty) |
| 101 | +3. Merges server data with local data |
| 102 | +4. Uploads local changes |
| 103 | + |
| 104 | +**Warning:** Full sync will delete local items that don't exist on server (unless they're new unsynced items). If you have local data you want to keep: |
| 105 | +1. Make sure it has been uploaded to the server first, OR |
| 106 | + |
| 107 | +## Sync Issues |
| 108 | + |
| 109 | +#### "Server is empty but you have local data" |
| 110 | + |
| 111 | +This warning appears when: |
| 112 | +- Your server's `max_usn` is 0 (empty) |
| 113 | +- Your client has previously synced (`last_max_usn > 0`) |
| 114 | +- You have local books or notes |
| 115 | + |
| 116 | +**Causes:** |
| 117 | +- You switched to a new empty server |
| 118 | +- Server data was accidentally deleted |
| 119 | +- You're setting up a new server after using a different one |
| 120 | + |
| 121 | +**Solutions:** |
| 122 | +- Confirm the upload when prompted to push local data to the empty server |
| 123 | + |
| 124 | +#### Orphaned Notes After Sync |
| 125 | + |
| 126 | +Orphaned notes occur when notes reference non-existent books. This can happen due to sync conflicts or interrupted syncs. |
| 127 | + |
| 128 | +**Check for orphaned notes:** |
| 129 | + |
| 130 | +```bash |
| 131 | +sqlite3 ~/.local/share/dnote/dnote.db << EOF |
| 132 | +SELECT n.uuid, n.body, n.book_uuid |
| 133 | +FROM notes n |
| 134 | +WHERE n.deleted = 0 |
| 135 | +AND n.book_uuid NOT IN (SELECT uuid FROM books WHERE deleted = 0); |
| 136 | +EOF |
| 137 | +``` |
| 138 | + |
| 139 | +**Fix orphaned notes:** |
| 140 | + |
| 141 | +If you find orphaned notes, you can either: |
| 142 | + |
| 143 | +1. Delete them locally and sync: |
| 144 | +```bash |
| 145 | +sqlite3 ~/.local/share/dnote/dnote.db << EOF |
| 146 | +DELETE FROM notes |
| 147 | +WHERE deleted = 0 |
| 148 | +AND book_uuid NOT IN (SELECT uuid FROM books WHERE deleted = 0); |
| 149 | +EOF |
| 150 | +``` |
| 151 | + |
| 152 | +2. Sync again to upload the corrected local state |
0 commit comments