26 Commits
Author SHA1 Message Date
Donkie 016ca6791e Back up to the target without taking file locks on it
Backup folders on network shares often refuse SQLite's file locks (CIFS
without nobrl, NFS without lockd). SQLite reports a refused lock as
SQLITE_BUSY, so every backup to such a folder retried until the 60 second
give-up and blamed a locked database, while the live database was not
locked at all (#1246).

The target is a scratch .pending file that nothing else opens, so open it
with nolock=1. The give-up message now names the live database, since that
is the only file a backup can still wait on.
2026-10-10 14:36:01 +02:00
Donkie bcc1ba1ace Stop a locked database from hanging the server during backup
sqlite3's Connection.backup() retries forever while the source is busy,
calling progress with 0 of 0 pages each time. The backup ran synchronously
on the event loop, so a lock that did not clear froze every request and
spammed "Copied 0 of 0 pages." into the log (#1191).

Run backups in a worker thread, give up after the source has been locked
for 60 seconds, and serialize backups now that they can overlap. Per-page
progress drops to debug.
2026-10-10 14:32:21 +02:00
Donkie 27ea256e2d Merge pull request #1078 from romasku/fix/sqlite-unicode-search
fix: make SQLite searches Unicode case-insensitive
2026-09-25 15:33:02 +02:00
Jeff PapiezandCopilot App 21c7b98844 Close the sqlite connections used to write a backup
A sqlite3.Connection used as a context manager is a transaction manager: it
commits or rolls back on exit, it does not close the connection. Both handles
stayed open past the `with` block in Database.backup().

backup_and_rotate() then unlinks and moves the .pending file it just wrote.
POSIX allows unlinking a file with open handles, so this was invisible on
Linux, but on Windows it raises WinError 32 and breaks both the scheduled
midnight backup and the manual backup endpoint. It also leaked a pair of
connections per backup on every platform.

Wrap both connections in contextlib.closing instead. Connection.backup()
commits on the destination internally, so nothing is lost by dropping the
transaction-managing context manager.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-08-19 21:50:54 -07:00
Roman Skurikhin 1507f9b3b8 fix: make SQLite searches Unicode case-insensitive 2026-08-14 20:48:28 +03:00
Donkie 72daa29cd2 security: finish the audit's low-severity items
Task 10: config.js JSON-encodes the base path, so a backslash cannot
escape the string literal the way the old " check allowed; search.py
escapes LIKE wildcards at both its call sites, using a helper moved into
database/utils.py so it and extra_field_query share one implementation.

Task 9 was a pair of decisions rather than fixes. /info keeps its paths:
both clients render them and removing response fields breaks API v1, while
the disclosure buys nothing against an API that is unauthenticated anyway.
/metrics keeps its shape but now says what it publishes when switched on.

Also pins the unit tests to a throwaway data directory -- importing
spoolman.main creates one as a side effect, and it was the real one.
2026-07-31 09:42:32 +02:00
Donkie 404b03173b security: stop backup rotation from churning away the restore history
Rotating deletes the oldest restore point and shifts the rest down, so enough
calls in quick succession leave nothing but snapshots of whatever state the
database is in now. POST /backup takes no parameters, so a bodyless cross-origin
form post reached it; the audit destroyed a full six-deep history that way
(todo.md task 2).

The origin guard from the previous commit already refuses that request, but the
rotation itself should not be this easy to abuse, so two further changes:

Rotation is skipped when the database has not actually changed. Not by comparing
the live database file, which the audit suggested: under WAL the live file does
not yet contain recent commits, so comparing it would skip backups that were
genuinely needed. Instead the snapshot is written to a pending file first and
compared against the newest backup -- sqlite's backup API reads through the
connection, so it sees WAL content. Identical means the pending file is
discarded and the history is left alone. This is fail-safe: if the comparison
ever came out unequal for an unchanged database, the result is the old behaviour
of rotating, never a missed backup.

Rotation is also rate-limited to one per five minutes, returning the newest
existing backup instead. Never applied when there is no backup to fall back on.

BackupResponse gained a `created` field so a client can tell the difference.
Additive, so v1-compatible, but load-bearing: telling a user they have a fresh
restore point when they do not is exactly the wrong failure mode here.

Verified against a real server -- six rapid calls now leave exactly one backup
and never rotate.
2026-07-27 19:33:07 +02:00
Donkie b942d1f8a1 Replaced pdm with uv, updated backend deps, python 3.10 minimum, simplified install script 2026-01-07 22:01:02 +01:00
Paul Sinclair ea36a94327 🔨 Add pool_recycle for MySQL 2025-04-05 09:58:34 -04:00
Donkie 70ea7ad414 Update python dependencies and ruff/black versions 2025-03-16 21:34:02 +01:00
Donkie 535fa40ad2 Updated most python dependencies
Primarily FastAPI and Pydantic to v2. Also ruff to latest.

Updated some code to support Pydantic v2
2024-05-23 19:42:27 +02:00
Donkie 21d541a680 Added script to download files from external db 2024-05-12 10:48:33 +02:00
Dmitry Belousov 91d922d0b8 fixed version prometheus-client
added env variable SPOOLMAN_METRICS_ENABLED for enabled database collector

set metrics path as /metrics

checked Null values at vendors, init weight and price
removed some logs
2024-04-15 00:17:36 +03:00
Dmitry Belousov 2aa0a4f1b0 WA for FastApi session manager 2024-04-12 01:20:35 +03:00
Dmitry Belousov 28b2bfec50 Added prometheus client
Added scheduler for compute current spool metrics and info
2024-04-09 15:25:09 +03:00
Donkie 796523a860 Fixed db backups not using the fancy get_backups_dir function 2023-11-25 21:58:20 +01:00
Donkie d3a4dcfcf8 Added logging for when scheduled backup runs 2023-07-07 17:37:17 +02:00
Donkie f24b9610e8 Added automatic nightly SQLite backups
Resolves #22
2023-07-04 14:59:05 +02:00
Donkie d201f17e5e Improved manually specifying sqlite db 2023-07-04 12:10:14 +02:00
Donkie 94d8cbf227 SQLite dbs now handle concurrent reqs better
Closes #7
2023-06-30 22:28:01 +02:00
Donkie de1bf05922 Added Alembic for migrations 2023-05-27 23:14:06 +02:00
Donkie ba6fb62c7b Enabled pool_pre_ping to mitigate postgres drop 2023-05-21 23:38:21 +02:00
Donkie 1c59e0efd5 Added logging level env var 2023-05-09 21:44:25 +02:00
Donkie ed3e30ea75 Improved compatibility with postgres 2023-05-09 20:03:19 +02:00
Donkie 1a148c0991 Added proper support for all databases 2023-04-06 16:19:33 +02:00
Donkie 6fd9662c42 Renamed to Spoolman
Spoolson just didn't sound that good after all
2023-04-02 19:19:15 +02:00