Refresh deploy/ and bin/ from the boilerplate at 09e144d (the release split between the distro and Windows, wsl-setup, the server config, USER 1000, python:3.15-slim) with roledesk's facts put back: no frontend stage, desk, plugins and seed copied, the extras passkeys, embeddings and llm, roles as the table the backup and the importer require, bin/pull.sh and bin/worker.sh with their profile commands, and Install Server.md and Install WSL.md as copies in place of the five old deployment docs
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
83e965dfeb
commit
a1f281a23a
40 files changed
+2226
-1287
No files matched your search
+43
-10
@@ -13,9 +13,26 @@
|
||||
# self-contained and compacted file, and never blocks a writer for long enough
|
||||
# to matter on a database of this size.
|
||||
#
|
||||
# Rename `app` and `APP_DATA` to your service's name.
|
||||
# The database is the one the app's own config names, asked of the app inside
|
||||
# the container, and it is opened read-only, so a path that names no file is
|
||||
# an error rather than a new empty database and a snapshot of nothing.
|
||||
#
|
||||
# SERVICE is the compose service (deploy.sh says why it is here); APP_DATA is
|
||||
# renamed with the other APP_ variables, and `from app.config` with the package.
|
||||
|
||||
SERVICE=app
|
||||
# Tables every database this app writes has: the same set as REQUIRED_TABLES in
|
||||
# import_database.py, which a test holds this line to. A snapshot without one
|
||||
# of them is deleted and the run fails.
|
||||
# Ours: `roles` is app/storage/schema.py's first table, where the boilerplate has `ticks`.
|
||||
TABLES="jobs roles"
|
||||
|
||||
set -euo pipefail
|
||||
# A snapshot is the whole database, so it is owner only whatever the caller's
|
||||
# umask is. This covers the folder made below; the umask inside the container
|
||||
# (set in the snippet) covers the .db, and gzip gives the .gz the mode of the
|
||||
# file it compresses.
|
||||
umask 077
|
||||
cd "${1:-$(dirname "$(readlink -f "$0")")}"
|
||||
|
||||
# Same source of truth as the compose file and deploy.sh.
|
||||
@@ -27,18 +44,34 @@ stamp=$(date +%Y%m%d-%H%M%S)
|
||||
|
||||
mkdir -p "$DATA/backups"
|
||||
|
||||
docker compose exec -T app python -c "
|
||||
import sqlite3
|
||||
db = sqlite3.connect('/data/app.db')
|
||||
db.execute('VACUUM INTO ?', ('/data/backups/app-$stamp.db',))
|
||||
db.close()
|
||||
"
|
||||
gzip -f "$DATA/backups/app-$stamp.db"
|
||||
echo "$DATA/backups/app-$stamp.db.gz $(du -h "$DATA/backups/app-$stamp.db.gz" | cut -f1)"
|
||||
# shellcheck disable=SC2086 # TABLES is a list of words on purpose
|
||||
docker compose exec -T "$SERVICE" python - "$SERVICE-$stamp" $TABLES <<'PY'
|
||||
import os, sqlite3, sys
|
||||
from contextlib import closing
|
||||
from pathlib import Path
|
||||
|
||||
from app.config import load
|
||||
|
||||
os.umask(0o077)
|
||||
name, required = sys.argv[1], set(sys.argv[2:])
|
||||
database = load().database.absolute()
|
||||
snapshot = Path("/data/backups") / f"{name}.db"
|
||||
with closing(sqlite3.connect(f"{database.as_uri()}?mode=ro", uri=True)) as db:
|
||||
db.execute("VACUUM INTO ?", (str(snapshot),))
|
||||
with closing(sqlite3.connect(f"{snapshot.as_uri()}?mode=ro", uri=True)) as db:
|
||||
tables = {row[0] for row in db.execute("SELECT name FROM sqlite_master WHERE type='table'")}
|
||||
missing = sorted(required - tables)
|
||||
if missing:
|
||||
snapshot.unlink()
|
||||
sys.exit(f"{database} has no table {', '.join(missing)}: not this app's database")
|
||||
print(f"snapshot of {database}")
|
||||
PY
|
||||
gzip -f "$DATA/backups/$SERVICE-$stamp.db"
|
||||
echo "$DATA/backups/$SERVICE-$stamp.db.gz $(du -h "$DATA/backups/$SERVICE-$stamp.db.gz" | cut -f1)"
|
||||
|
||||
# Oldest first, everything past KEEP goes. Named by timestamp, so sorting the
|
||||
# names sorts them by age.
|
||||
ls -1 "$DATA"/backups/app-*.db.gz 2>/dev/null \
|
||||
ls -1 "$DATA"/backups/"$SERVICE"-*.db.gz 2>/dev/null \
|
||||
| sort \
|
||||
| head -n -"$KEEP" \
|
||||
| while read -r old; do rm -f "$old"; echo "removed $old"; done
|
||||
Reference in new issue
Block a user