python-dbsync 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_dbsync-0.3.0/LICENSE +48 -0
- python_dbsync-0.3.0/PKG-INFO +336 -0
- python_dbsync-0.3.0/README.md +299 -0
- python_dbsync-0.3.0/pyproject.toml +57 -0
- python_dbsync-0.3.0/setup.cfg +4 -0
- python_dbsync-0.3.0/src/dbsync/__init__.py +0 -0
- python_dbsync-0.3.0/src/dbsync/__main__.py +5 -0
- python_dbsync-0.3.0/src/dbsync/alerts.py +57 -0
- python_dbsync-0.3.0/src/dbsync/api.py +254 -0
- python_dbsync-0.3.0/src/dbsync/assets/dbsync-conflict.svg +1 -0
- python_dbsync-0.3.0/src/dbsync/assets/dbsync-error.svg +1 -0
- python_dbsync-0.3.0/src/dbsync/assets/dbsync-offline.svg +1 -0
- python_dbsync-0.3.0/src/dbsync/assets/dbsync-paused.svg +1 -0
- python_dbsync-0.3.0/src/dbsync/assets/dbsync-synced.svg +1 -0
- python_dbsync-0.3.0/src/dbsync/assets/dbsync-syncing.svg +1 -0
- python_dbsync-0.3.0/src/dbsync/auth.py +75 -0
- python_dbsync-0.3.0/src/dbsync/cli.py +264 -0
- python_dbsync-0.3.0/src/dbsync/config.py +135 -0
- python_dbsync-0.3.0/src/dbsync/daemon.py +260 -0
- python_dbsync-0.3.0/src/dbsync/gitops.py +170 -0
- python_dbsync-0.3.0/src/dbsync/hashing.py +22 -0
- python_dbsync-0.3.0/src/dbsync/ignore.py +50 -0
- python_dbsync-0.3.0/src/dbsync/plat/__init__.py +41 -0
- python_dbsync-0.3.0/src/dbsync/plat/linux_tray.py +123 -0
- python_dbsync-0.3.0/src/dbsync/plat/posix.py +160 -0
- python_dbsync-0.3.0/src/dbsync/plat/windows.py +254 -0
- python_dbsync-0.3.0/src/dbsync/plat/windows_tray.py +143 -0
- python_dbsync-0.3.0/src/dbsync/state.py +64 -0
- python_dbsync-0.3.0/src/dbsync/status.py +42 -0
- python_dbsync-0.3.0/src/dbsync/sync.py +627 -0
- python_dbsync-0.3.0/src/python_dbsync.egg-info/PKG-INFO +336 -0
- python_dbsync-0.3.0/src/python_dbsync.egg-info/SOURCES.txt +44 -0
- python_dbsync-0.3.0/src/python_dbsync.egg-info/dependency_links.txt +1 -0
- python_dbsync-0.3.0/src/python_dbsync.egg-info/entry_points.txt +2 -0
- python_dbsync-0.3.0/src/python_dbsync.egg-info/requires.txt +10 -0
- python_dbsync-0.3.0/src/python_dbsync.egg-info/top_level.txt +1 -0
- python_dbsync-0.3.0/tests/test_alerts.py +33 -0
- python_dbsync-0.3.0/tests/test_auth.py +45 -0
- python_dbsync-0.3.0/tests/test_daemon.py +165 -0
- python_dbsync-0.3.0/tests/test_deletes_renames.py +282 -0
- python_dbsync-0.3.0/tests/test_ignore_hash_roots.py +159 -0
- python_dbsync-0.3.0/tests/test_init_config.py +75 -0
- python_dbsync-0.3.0/tests/test_merge_flow.py +137 -0
- python_dbsync-0.3.0/tests/test_protect.py +99 -0
- python_dbsync-0.3.0/tests/test_push_only.py +96 -0
- python_dbsync-0.3.0/tests/test_windows_plat.py +89 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
python-dbsync License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 George Butiri. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to use,
|
|
7
|
+
copy, modify, merge, and distribute the Software, subject to the following
|
|
8
|
+
conditions:
|
|
9
|
+
|
|
10
|
+
1. NON-COMMERCIAL USE ONLY
|
|
11
|
+
|
|
12
|
+
The Software may be used freely for:
|
|
13
|
+
- Personal use and experimentation
|
|
14
|
+
- Academic and research purposes
|
|
15
|
+
- Development, testing, and evaluation
|
|
16
|
+
- Non-commercial projects
|
|
17
|
+
- Internal use by individuals (not organizations)
|
|
18
|
+
|
|
19
|
+
2. COMMERCIAL USE REQUIRES A LICENSE
|
|
20
|
+
|
|
21
|
+
Any use of the Software for commercial purposes requires a separate
|
|
22
|
+
commercial license from the copyright holder. "Commercial purposes"
|
|
23
|
+
includes, but is not limited to:
|
|
24
|
+
|
|
25
|
+
- Offering the Software as a hosted service to third parties
|
|
26
|
+
- Incorporating the Software into a product or service that is sold
|
|
27
|
+
or offered for a fee
|
|
28
|
+
- Using the Software within a business or organization where it
|
|
29
|
+
generates revenue, reduces costs, or provides competitive advantage
|
|
30
|
+
- Distributing the Software as part of a commercial product
|
|
31
|
+
|
|
32
|
+
For commercial licensing inquiries: george@iseestudios.com
|
|
33
|
+
|
|
34
|
+
3. ATTRIBUTION
|
|
35
|
+
|
|
36
|
+
The above copyright notice and this permission notice shall be included
|
|
37
|
+
in all copies or substantial portions of the Software.
|
|
38
|
+
|
|
39
|
+
4. NO WARRANTY
|
|
40
|
+
|
|
41
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
42
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
43
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
44
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
45
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
46
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
47
|
+
DEALINGS IN THE SOFTWARE. SYNCING SOFTWARE CAN CHANGE AND DELETE FILES:
|
|
48
|
+
KEEP BACKUPS.
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python-dbsync
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Selective Dropbox folder sync for Linux and Windows: the folders you choose, one per running copy, with git underneath, rev-checked uploads that never overwrite a newer file, kept conflicts, a mass-delete guard, a daemon and a tray icon
|
|
5
|
+
Author-email: George Butiri <george@iseestudios.com>
|
|
6
|
+
License: Proprietary
|
|
7
|
+
Project-URL: Homepage, https://github.com/gbutiri/python-dbsync
|
|
8
|
+
Project-URL: Repository, https://github.com/gbutiri/python-dbsync
|
|
9
|
+
Project-URL: Issues, https://github.com/gbutiri/python-dbsync/issues
|
|
10
|
+
Keywords: dropbox,sync,selective sync,git,backup,daemon
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: No Input/Output (Daemon)
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
15
|
+
Classifier: License :: Other/Proprietary License
|
|
16
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
17
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: System :: Archiving :: Mirroring
|
|
24
|
+
Classifier: Topic :: System :: Filesystems
|
|
25
|
+
Requires-Python: >=3.11
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: dropbox>=12
|
|
29
|
+
Requires-Dist: python-dotenv>=1.0
|
|
30
|
+
Requires-Dist: requests>=2.28
|
|
31
|
+
Provides-Extra: windows
|
|
32
|
+
Requires-Dist: pystray>=0.19; extra == "windows"
|
|
33
|
+
Requires-Dist: Pillow>=10; extra == "windows"
|
|
34
|
+
Provides-Extra: test
|
|
35
|
+
Requires-Dist: pytest>=7.0; extra == "test"
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# python-dbsync
|
|
39
|
+
|
|
40
|
+
**Selective Dropbox sync for the folders you choose, with git underneath.**
|
|
41
|
+
|
|
42
|
+
dbsync keeps the Dropbox folders you choose in step with local folders, on Linux and on Windows: one folder per running copy, and as many copies as you need. It uses the Dropbox API, not the Dropbox desktop client. It never downloads your whole Dropbox, never touches the official client's folder, and never overwrites a newer file without telling you. Every change on either side becomes a git commit, so nothing is lost and every conflict can be resolved with ordinary git.
|
|
43
|
+
|
|
44
|
+
It was built for machines that need a few folders from Dropbox and not the rest: a laptop with a small disk, a Chromebook, an AI agent's working folder that has to follow it from machine to machine. The official client starts by downloading everything (on the author's machine that was 1.6 TB), and its "selective sync" ignore flag deletes folders from the server when it is set the wrong way. dbsync was written so that neither can happen.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install python-dbsync
|
|
48
|
+
dbsync auth # your own Dropbox app's key, secret and refresh token, saved, never printed
|
|
49
|
+
dbsync init # after writing ~/.config/dbsync/config.toml: makes the folder a repo, first pull
|
|
50
|
+
dbsync daemon # watches both sides and syncs, or run it as a service
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## What It Does
|
|
54
|
+
|
|
55
|
+
- **Folders chosen explicitly.** For each copy you name one Dropbox path (at least two levels deep, such as `/Projects/notes`) and one local folder. `/`, an empty path or a single top-level folder is refused. Every API call is checked to stay inside the configured path.
|
|
56
|
+
- **Both directions, near real time.** Dropbox's longpoll tells dbsync when something changed remotely; a local scan every few seconds finds local changes. A change that has settled is pushed right away.
|
|
57
|
+
- **Never overwrites blind.** Every upload carries the last Dropbox revision dbsync saw. If the file changed on Dropbox since then, Dropbox refuses the upload, dbsync pulls the newer version and merges it instead.
|
|
58
|
+
- **Git underneath.** The local folder is a git repository. Remote changes land on a `dropbox` branch and are merged into `main`. A real conflict stops with both sides kept, the merge left in progress, and the tray showing "conflict", for you to resolve with `git add` and `git commit`.
|
|
59
|
+
- **Safe deletes.** A local delete is sent to Dropbox only with the matching revision, so a file someone changed elsewhere is never deleted. More than 20 deletions in one sync are refused until you say so. Deleted files stay recoverable in Dropbox's own history.
|
|
60
|
+
- **Renames are moves.** A local rename becomes a Dropbox move (not a delete and an upload), and a Dropbox rename becomes a `git mv`, so local edits carry over.
|
|
61
|
+
- **Growing files behave.** A log or a chat transcript that gets a line every second is uploaded at most every 10 minutes, and when it grew while uploading, the local side wins the conflicting lines.
|
|
62
|
+
- **Start-up files can be locked** (`protect`). A change made only in Dropbox to a listed file is kept aside, reported, and not applied. For an AI agent's instructions, a config, anything that should only change on the machine itself.
|
|
63
|
+
- **One-way mode** (`push_only`). Local to Dropbox only, for files that only this machine writes, such as live chat transcripts.
|
|
64
|
+
- **Several folders, one service each**, through one environment variable (see [Several Folders](#several-folders)).
|
|
65
|
+
- **A daemon, a tray icon and phone alerts.** A systemd user service (Linux) or a Task Scheduler task (Windows), a tray icon with the state and a menu, and an optional push to your phone on conflict or error.
|
|
66
|
+
- **No secrets in the code or the output.** Credentials live in a `.env` file you name. `dbsync auth` writes them without ever printing them.
|
|
67
|
+
|
|
68
|
+
## Install
|
|
69
|
+
|
|
70
|
+
Python 3.11 or newer and `git` on the PATH.
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install python-dbsync
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
On Windows, with the tray icon:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pip install "python-dbsync[windows]"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The Linux tray uses the system's GTK bindings, not a pip package:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
sudo apt install python3-gi gir1.2-ayatanaappindicator3-0.1 libnotify-bin
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
If dbsync is installed in a virtual environment that has no PyGObject, `dbsync tray` starts itself again with `/usr/bin/python3`: the tray needs only the standard library and `gi`.
|
|
89
|
+
|
|
90
|
+
## Quick Start
|
|
91
|
+
|
|
92
|
+
### 1. Make a Dropbox app
|
|
93
|
+
|
|
94
|
+
dbsync talks to Dropbox as an app that you own, so no one else's servers are involved.
|
|
95
|
+
|
|
96
|
+
1. Open the [Dropbox App Console](https://www.dropbox.com/developers/apps) and click **Create app**.
|
|
97
|
+
2. Choose **Scoped access** and **Full Dropbox** (dbsync limits itself to your folder; "App folder" would only let it see `/Apps/<name>`).
|
|
98
|
+
3. On the **Permissions** tab, tick `files.metadata.read`, `files.content.read` and `files.content.write`, then **Submit**.
|
|
99
|
+
4. On the **Settings** tab, note the **App key** and **App secret**.
|
|
100
|
+
|
|
101
|
+
### 2. Save the keys
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
dbsync auth
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
It asks for the app key, then the secret (hidden), opens Dropbox's **Allow** page, and asks for the code Dropbox shows (hidden). It saves `DROPBOX_APP_KEY`, `DROPBOX_APP_SECRET` and `DROPBOX_REFRESH_TOKEN` in `~/.config/secrets/api.env` with mode 600, keeps a copy of any earlier file, and tells you which permissions were granted. Nothing secret is printed. Use `--secrets <file>` for another file. Run it again whenever you change the app's permissions.
|
|
108
|
+
|
|
109
|
+
### 3. Write the config
|
|
110
|
+
|
|
111
|
+
Linux: `~/.config/dbsync/config.toml`. Windows: `%APPDATA%\dbsync\config.toml`.
|
|
112
|
+
|
|
113
|
+
```toml
|
|
114
|
+
[settings]
|
|
115
|
+
secrets_file = "~/.config/secrets/api.env"
|
|
116
|
+
|
|
117
|
+
[[folder]]
|
|
118
|
+
id = "notes" # short name for the state file, lock and log
|
|
119
|
+
remote = "/Projects/notes" # must already exist in Dropbox
|
|
120
|
+
local = "~/notes" # NOT inside the official Dropbox client's folder
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The full example with every setting is in [`config/example.toml`](config/example.toml). With no config, `dbsync init` refuses, writes nothing, and prints the block to write. A config that still has the example's `CHANGE-ME` is refused by every command.
|
|
124
|
+
|
|
125
|
+
### 4. First sync
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
dbsync init # makes ~/notes a git repo (if it is not one) and pulls the Dropbox folder
|
|
129
|
+
dbsync status # what would happen next
|
|
130
|
+
dbsync push # sends local changes (pulls first)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### 5. Keep it running
|
|
134
|
+
|
|
135
|
+
**Linux**, as a user service:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
mkdir -p ~/.config/systemd/user ~/.config/autostart
|
|
139
|
+
cp config/systemd/dbsync.service ~/.config/systemd/user/ # edit ExecStart if `which dbsync` differs
|
|
140
|
+
cp config/autostart/dbsync-tray.desktop ~/.config/autostart/ # tray at login (optional)
|
|
141
|
+
systemctl --user daemon-reload
|
|
142
|
+
systemctl --user enable --now dbsync
|
|
143
|
+
loginctl enable-linger $USER # keep syncing while logged out (optional)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The unit files are in this repository's `config/` folder (they are not inside the pip package).
|
|
147
|
+
|
|
148
|
+
**Windows**: run `dbsync daemon` and `dbsync tray` at logon through Task Scheduler, with `pythonw.exe` so no console window stays open, and "restart on failure" ticked. No administrator rights are needed.
|
|
149
|
+
|
|
150
|
+
## Commands
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
dbsync auth [--secrets FILE] get a Dropbox refresh token into the secrets file
|
|
154
|
+
dbsync init set up the repo and do the first pull
|
|
155
|
+
dbsync status pending local and remote changes
|
|
156
|
+
dbsync pull [--dry-run] bring Dropbox changes down and merge them
|
|
157
|
+
dbsync push [--dry-run] [--allow-mass-delete]
|
|
158
|
+
pull, then upload, move and delete
|
|
159
|
+
dbsync watch foreground longpoll loop, pull only
|
|
160
|
+
dbsync daemon what the service runs: watch + auto-push + status + control
|
|
161
|
+
dbsync tray tray icon for the running daemon
|
|
162
|
+
dbsync ctl status|sync-now|pause|resume|stop talk to the running daemon
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Every command takes `--config FILE`. Exit codes: 0 ok, 1 error, 2 conflict. `dbsync ctl stop` makes the daemon write "stopped" and exit 0, so systemd's `Restart=on-failure` leaves it stopped.
|
|
166
|
+
|
|
167
|
+
## Settings
|
|
168
|
+
|
|
169
|
+
All under `[settings]` unless marked.
|
|
170
|
+
|
|
171
|
+
| Setting | Default | What it does |
|
|
172
|
+
|---|---|---|
|
|
173
|
+
| `secrets_file` | `~/.config/secrets/api.env` | The `.env` with the three Dropbox keys. |
|
|
174
|
+
| `longpoll_timeout` | 240 | Seconds per Dropbox longpoll (30 to 480). |
|
|
175
|
+
| `fallback_poll` | 30 | Retry interval when offline or in error, and the longest backoff. |
|
|
176
|
+
| `local_scan` | 10 | Seconds between local scans. |
|
|
177
|
+
| `auto_push` | true | Push settled local changes by itself. Off: the daemon only pulls; **Sync now** still pushes. |
|
|
178
|
+
| `settle_seconds` | 30 | A file changed more recently than this is "hot". |
|
|
179
|
+
| `hot_upload_interval` | 600 | A hot file goes up at most this often. |
|
|
180
|
+
| `local_wins` | `["logs/**"]` | After a push, conflicting lines in these paths keep the local side. |
|
|
181
|
+
| `propagate_local_deletes` | true | Send local deletes and renames to Dropbox. Off: they are only reported. |
|
|
182
|
+
| `max_deletes` | 20 | More deletions than this in one push are refused without `--allow-mass-delete`. |
|
|
183
|
+
| `extra_ignore` | `[]` | More paths to leave out, gitignore style (`"build/"`, `"tools/cache/"`). |
|
|
184
|
+
| `push_only` | false | One way, local to Dropbox. See below. |
|
|
185
|
+
| `ntfy_alerts` | true | Run `ntfy_script` on conflict or error. |
|
|
186
|
+
| `ntfy_script` | `""` | A script called as `script "<message>" "<title>" <priority> <tag>`. |
|
|
187
|
+
| `protect` (in `[[folder]]`) | `[]` | Files a Dropbox-only change may not replace. See below. |
|
|
188
|
+
|
|
189
|
+
Always left out: `.git/`, `.venv/`, `venv/`, `env_*/`, `node_modules/`, `__pycache__/`, `*.pyc`, `.dbsync/`. `.env` files **are** synced: Dropbox is meant to be the backup.
|
|
190
|
+
|
|
191
|
+
## How a Sync Works
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
Dropbox /Projects/notes
|
|
195
|
+
| ^
|
|
196
|
+
longpoll, | | rev-checked upload, move_v2, delete_v2 (parent_rev)
|
|
197
|
+
download v |
|
|
198
|
+
branch `dropbox` (a git worktree in the data folder: the last known state of Dropbox)
|
|
199
|
+
| ^
|
|
200
|
+
merge v | the uploaded files are committed here too
|
|
201
|
+
branch `main` = your folder ~/notes
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
- **Pull**: download what changed into the `dropbox` branch, commit any local changes on `main`, merge `dropbox` into `main`.
|
|
205
|
+
- **Push**: pull first. Then upload each changed file with the revision last seen (`update(rev)`), or as a new file (`add`, never renamed by Dropbox). A refused upload is a conflict: the newer remote version is pulled and merged, and you push again.
|
|
206
|
+
- **Conflicts**: a git conflict leaves the merge in progress on `main`. Resolve it in the folder (`git status`, edit, `git add`, `git commit`); the daemon notices and carries on.
|
|
207
|
+
|
|
208
|
+
### Deletes and renames
|
|
209
|
+
|
|
210
|
+
- **Local delete to Dropbox**: only for files dbsync has synced, with `parent_rev` set to the revision it last saw. If the file changed on Dropbox, the delete is refused, nothing is deleted, and the newer version comes back as a conflict.
|
|
211
|
+
- **Mass-delete guard**: more than `max_deletes` in one push are refused. A missing local folder or repository is refused outright, so an unplugged drive does not look like "everything was deleted".
|
|
212
|
+
- **Dropbox delete to local**: the local file is removed only if it is unchanged since the last sync. If you changed it, it is kept and reported.
|
|
213
|
+
- **Local rename** (a file gone and a new one with the same content): sent as a Dropbox move after checking the revision. If that fails, the new name is uploaded and the old one goes through the checked delete.
|
|
214
|
+
- **Dropbox rename**: a `git mv` on the `dropbox` branch, merged rename-aware, so your edits to the old name land in the new one.
|
|
215
|
+
- Empty folders are not synced.
|
|
216
|
+
|
|
217
|
+
### Growing files
|
|
218
|
+
|
|
219
|
+
A file modified less than `settle_seconds` ago is "hot" and is uploaded at most once per `hot_upload_interval`. A log written every two seconds goes up about every ten minutes; files that have settled go up at once. If a hot file grew while its snapshot was uploading, the paths in `local_wins` keep the local lines instead of stopping on a conflict. The repository packs its history automatically (`gc.auto = 100`), so a file that grows all day does not leave hundreds of full copies.
|
|
220
|
+
|
|
221
|
+
## Protecting Start-up Files
|
|
222
|
+
|
|
223
|
+
Without protection, a change made only in Dropbox reaches the machine quietly, which is what a sync is for. For some files that is the wrong thing: an AI agent's instruction files (`CLAUDE.md`, `NOTES.md`), a config, a script that runs at login. Anything that can write to that Dropbox folder could change what runs on the machine.
|
|
224
|
+
|
|
225
|
+
```toml
|
|
226
|
+
[[folder]]
|
|
227
|
+
id = "agent"
|
|
228
|
+
remote = "/Agents/agent"
|
|
229
|
+
local = "~/agent"
|
|
230
|
+
protect = ["CLAUDE.md", "PRINCIPLES.md", "NOTES.md", "config/*.toml"]
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
For a listed file:
|
|
234
|
+
|
|
235
|
+
- A change or a delete made **only in Dropbox** is not applied. The Dropbox version is kept beside the file as `<name>.remote-<YYYYmmdd-HHMMSS>`, and the local file goes back up on the next push.
|
|
236
|
+
- It is reported in `dbsync status` and push/pull output (`PROTECTED ...`), the log, the status file (`kept_remote`), and the tray's detail line.
|
|
237
|
+
- Local edits sync as usual. When both sides changed, the local side wins.
|
|
238
|
+
- Off by default (`protect = []`). Patterns are globs relative to the folder; a pattern without `/` also matches the file name in any folder.
|
|
239
|
+
|
|
240
|
+
## One-way Mode
|
|
241
|
+
|
|
242
|
+
```toml
|
|
243
|
+
[settings]
|
|
244
|
+
push_only = true
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
The whole folder goes one way, local to Dropbox, for files only this machine writes: live chat transcripts, logs, exported data.
|
|
248
|
+
|
|
249
|
+
- Dropbox-side edits and deletes never reach the local folder. Remote changes are still fetched into the `dropbox` branch, which keeps them, but they are never merged into `main`; the local copy is then uploaded over them.
|
|
250
|
+
- A file that exists only in Dropbox (added there by another machine) is left alone in Dropbox and not downloaded.
|
|
251
|
+
- A first sync against a Dropbox folder that already has older copies pulls nothing over a newer local file.
|
|
252
|
+
|
|
253
|
+
## Several Folders
|
|
254
|
+
|
|
255
|
+
Each running copy syncs one folder. For more folders, run one copy per folder, each with its own config and its own data folder:
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
cp config/systemd/dbsync@.service ~/.config/systemd/user/
|
|
259
|
+
# ~/.config/dbsync/photos.toml with its own [[folder]]
|
|
260
|
+
systemctl --user daemon-reload
|
|
261
|
+
systemctl --user enable --now dbsync@photos
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
`dbsync@photos` reads `~/.config/dbsync/photos.toml` and sets `DBSYNC_DATA_DIR=~/.local/share/dbsync-photos`, so its state, log, status file and control socket never meet another copy's. With `DBSYNC_DATA_DIR` unset, dbsync uses the single default data folder. From a shell: `DBSYNC_DATA_DIR=~/.local/share/dbsync-photos dbsync --config ~/.config/dbsync/photos.toml status`.
|
|
265
|
+
|
|
266
|
+
## The Daemon, the Tray and Alerts
|
|
267
|
+
|
|
268
|
+
- **States**: `synced`, `syncing`, `paused`, `conflict` (a git conflict, or Dropbox refused a write or a delete), `error` (rechecked every `fallback_poll` seconds), `offline` (retried), `stopped` (no daemon running).
|
|
269
|
+
- **Status file**: `status.json` in the data folder, with the state, message, last sync, conflicts, files kept by `protect`, the last result and a short history.
|
|
270
|
+
- **Control**: on Linux a unix socket (mode 600) at `$XDG_RUNTIME_DIR/dbsync.sock`; on Windows 127.0.0.1 on a random port with a token in the data folder. `dbsync ctl ...` uses it.
|
|
271
|
+
- **Tray**: the icon follows the state. Its menu has the status line, Sync now, Pause/Resume, Open folder, Open log and Quit tray. Desktop notifications only on conflict and error.
|
|
272
|
+
- **Phone alerts**: with `ntfy_alerts = true` and an `ntfy_script`, one push per change into conflict or error, and at most one error push per 15 minutes. The message holds the state, paths and the error type, never a secret.
|
|
273
|
+
- **Noisy accounts**: longpoll sometimes reports changes elsewhere in the account. Those wake-ups only move the cursor, with a growing backoff, so a busy Dropbox does not keep dbsync busy.
|
|
274
|
+
|
|
275
|
+
## Files
|
|
276
|
+
|
|
277
|
+
| | Linux | Windows |
|
|
278
|
+
|---|---|---|
|
|
279
|
+
| Config | `~/.config/dbsync/config.toml` | `%APPDATA%\dbsync\config.toml` |
|
|
280
|
+
| State, log, status, worktree | `~/.local/share/dbsync/` | `%LOCALAPPDATA%\dbsync\` |
|
|
281
|
+
| Credentials | the `secrets_file` you name | the same |
|
|
282
|
+
|
|
283
|
+
In the data folder: `<id>.db` (SQLite: each file's revision, hash, size and time, and the Dropbox cursor), `<id>.dropbox-worktree/` (the `dropbox` branch), `<id>.lock`, `dbsync.log`, `status.json`.
|
|
284
|
+
|
|
285
|
+
## Never Point It At
|
|
286
|
+
|
|
287
|
+
- the whole Dropbox (`/`) or a single top-level folder;
|
|
288
|
+
- a folder inside the official Dropbox client's folder (two programs syncing the same files);
|
|
289
|
+
- a folder another sync tool is also syncing.
|
|
290
|
+
|
|
291
|
+
## How It Is Built
|
|
292
|
+
|
|
293
|
+
```
|
|
294
|
+
src/dbsync/
|
|
295
|
+
cli.py commands
|
|
296
|
+
auth.py dbsync auth: OAuth code flow, writes the .env, prints no secret
|
|
297
|
+
config.py TOML config, folders, defaults, paths
|
|
298
|
+
api.py Dropbox API wrapper: every path checked against the configured roots
|
|
299
|
+
sync.py pull, push, merge, deletes and renames, protect, push_only
|
|
300
|
+
gitops.py git plumbing: repo and worktree setup, commits, merges
|
|
301
|
+
state.py SQLite state: revisions, hashes, cursor
|
|
302
|
+
hashing.py Dropbox content hash
|
|
303
|
+
ignore.py ignore rules (built-in + extra_ignore, gitignore style)
|
|
304
|
+
daemon.py longpoll thread, local scan, status file, control channel
|
|
305
|
+
status.py status.json read and write
|
|
306
|
+
alerts.py phone alerts, rate-limited
|
|
307
|
+
plat/ the only platform-specific code: posix.py + linux_tray.py, windows.py + windows_tray.py
|
|
308
|
+
assets/ tray icons
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## Tests
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
pip install "python-dbsync[test]"
|
|
315
|
+
pytest tests
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
The suite uses a fake Dropbox API (`tests/fake_api.py`) and real git, with no network: 117 tests on Linux, 7 of them Windows-only and skipped there. It covers rev conflicts, merges, deletes, renames, the mass-delete guard, ignore rules, the daemon, `protect`, `push_only`, `auth` and the Windows platform code. The Windows build is tested on Windows 11 with Python 3.12.
|
|
319
|
+
|
|
320
|
+
## Status
|
|
321
|
+
|
|
322
|
+
v0.3.0: first public release. `protect` for start-up files; `push_only`; several copies per user (`DBSYNC_DATA_DIR`, `dbsync@.service`); automatic packing for growing files; `dbsync auth`; the tray finds its icons in an installed package. Fixed: in `push_only`, a file added only in Dropbox was deleted from Dropbox on the next push.
|
|
323
|
+
|
|
324
|
+
Earlier, unpublished: the Windows version (Task Scheduler, pystray tray, toasts, a token-checked local control port); anchored ignore paths such as `data/cache/`; `init` refusing to run without your own config; the daemon surviving `pythonw` with no console; the first versions with the daemon, tray, safe deletes and renames, rev-checked uploads and the git merge flow.
|
|
325
|
+
|
|
326
|
+
## License
|
|
327
|
+
|
|
328
|
+
[Proprietary](LICENSE). Source-available, not open source.
|
|
329
|
+
|
|
330
|
+
**Free for:** personal use, development, testing, research, academic work, non-commercial projects. Study it, fork it, learn from it.
|
|
331
|
+
|
|
332
|
+
**Requires a commercial license for:** hosted services, revenue-generating products, organizational or business use. Contact george@iseestudios.com.
|
|
333
|
+
|
|
334
|
+
## Author
|
|
335
|
+
|
|
336
|
+
George Butiri, [george@iseestudios.com](mailto:george@iseestudios.com)
|