2026-10-03 16:45:40 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
# Backs up learn.halkyon.eu off-site. Runs every hour from
|
2026-10-13 23:11:40 +02:00
|
|
|
# deploy/backup/halkyon-backup.timer, as deploy on the server; deploy/backups.md says
|
2026-10-03 16:45:40 +02:00
|
|
|
# how it was set up and how to restore.
|
|
|
|
|
#
|
|
|
|
|
# Everything people keep is in the database, their files too (Serverpod's database
|
build(todo): Todo deployable beside Learn's server, and released as an APK, on F-Droid and as a snap (ADR 0033, step 5)
deploy/compose.todo.yaml adds Todo's server at todo.halkyon.eu, a member
of Learn's register, its database halkyon_todo in the instance's
PostgreSQL, its image built as Train's. redeploy.sh and backup.sh go over
every app server .env switches on (train, todo). Each compose file names
its server to the register in a variable of its own
(INSTANCE_MEMBER_TRAIN, INSTANCE_MEMBER_TODO), which halkyon_base adds to
INSTANCE_MEMBERS, each address once, as a second compose file's default
would have replaced Train's.
apps/todo/release.dart configures the release tool for Todo's APK and
snap: a key of its own (pinned once made; until then nothing is
released), the F-Droid listing (Time, NonFreeNet), and the snap from
apps/todo/snap/, which the tool builds in a clone of the repository at the
tag with that folder in place of snap/, as snapcraft builds one recipe a
folder and the root's is Learn's. What's new for 0.1.0 in English and
German, now shown. Android's backup and transfer are off, as Train's
(D53): the reminders scheduled keep their tasks' titles unsealed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-11-02 15:35:40 +01:00
|
|
|
# cloud storage), and in Train's and Todo's where .env switches each on (compose.train.yaml,
|
|
|
|
|
# Halkyon Train's ADR 0030, D46; compose.todo.yaml, Halkyon Todo's ADR 0033), but for the
|
|
|
|
|
# releases of published studysets, which are git
|
feat(publish): releases in git (public tier, stage 2)
A person with an identity and a public profile publishes a studyset with
everything inside it as its next release (ADR 0005, rule 3): the server
reads their synced rows and writes them through the git command as a
commit on main and the annotated tag vN, in a bare repository of the
studyset's own, named by a random public id made at the first publish.
A release is a directory per studyset with a file per card, note, path,
step and PDF (its id, position, tag names and payload as synced, keys
sorted and indented) and the files the content names, without what is
only the author's (a card's report, a PDF's deadline). Publishing is
refused without a licence allowing passing it on in every studyset ("no
derivatives" allowed), with revisions to settle, with files not uploaded
yet, when nothing changed, or for a name that won't do; the name is
fixed from the first release, as is the person's handle.
In the app, Share in a studyset's action row opens the Publish sheet;
publishing syncs first, and settles by itself the revisions that merge
cleanly, listing only real conflicts. The server's image gets git, the
repositories a volume of their own, and the hourly backup a git bundle of
each.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MMm7usAo6q9ZZRoPkWjoxi
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-10-09 22:01:00 +02:00
|
|
|
# repositories in the server's volume: a dump and a bundle of each repository cover
|
|
|
|
|
# the instance; the secrets in deploy/.env are kept in Proton Pass instead. restic stores the dump encrypted in a Hetzner Storage Box
|
2026-10-03 16:45:40 +02:00
|
|
|
# and keeps 24 hourly, 7 daily, 4 weekly and 3 monthly snapshots (decided 2026-10-03).
|
|
|
|
|
# Hourly, because a restore loses what came after the backup, and for someone who
|
|
|
|
|
# started since, that is everything: their app no longer finds its session and starts
|
|
|
|
|
# anew (deploy/backups.md). After 3 months, a deleted account is gone from every
|
|
|
|
|
# backup (the privacy page says so). The box's own automatic snapshots, which only
|
2026-10-13 23:11:40 +02:00
|
|
|
# Hetzner's Console can remove, keep the backups safe from a taken-over server,
|
2026-10-03 16:45:40 +02:00
|
|
|
# which can delete what restic wrote.
|
|
|
|
|
#
|
|
|
|
|
# Failures go to the journal only (decided 2026-10-03):
|
|
|
|
|
#
|
|
|
|
|
# systemctl status halkyon-backup; journalctl -u halkyon-backup
|
|
|
|
|
#
|
|
|
|
|
# restic finds the repository and its password in deploy's files
|
|
|
|
|
# ~/.config/restic/repository and ~/.config/restic/password (both 0600); a run by hand
|
|
|
|
|
# can point elsewhere with RESTIC_REPOSITORY_FILE and RESTIC_PASSWORD_FILE.
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
|
|
export RESTIC_REPOSITORY_FILE="${RESTIC_REPOSITORY_FILE:-$HOME/.config/restic/repository}"
|
|
|
|
|
export RESTIC_PASSWORD_FILE="${RESTIC_PASSWORD_FILE:-$HOME/.config/restic/password}"
|
|
|
|
|
|
|
|
|
|
cd "$(dirname "$0")"
|
|
|
|
|
|
|
|
|
|
# The dump goes to a file first: Ubuntu 24.04's restic (v0.16) would store a dump
|
|
|
|
|
# piped into it even when pg_dump fails halfway, and the file is the newest copy at
|
|
|
|
|
# hand for a quick restore. Uncompressed, so restic finds what hasn't changed since
|
|
|
|
|
# the last hour and stores it only once; restic compresses what it stores.
|
|
|
|
|
mkdir -p -m 700 "$HOME/backups"
|
|
|
|
|
dump="$HOME/backups/latest.dump"
|
build(todo): Todo deployable beside Learn's server, and released as an APK, on F-Droid and as a snap (ADR 0033, step 5)
deploy/compose.todo.yaml adds Todo's server at todo.halkyon.eu, a member
of Learn's register, its database halkyon_todo in the instance's
PostgreSQL, its image built as Train's. redeploy.sh and backup.sh go over
every app server .env switches on (train, todo). Each compose file names
its server to the register in a variable of its own
(INSTANCE_MEMBER_TRAIN, INSTANCE_MEMBER_TODO), which halkyon_base adds to
INSTANCE_MEMBERS, each address once, as a second compose file's default
would have replaced Train's.
apps/todo/release.dart configures the release tool for Todo's APK and
snap: a key of its own (pinned once made; until then nothing is
released), the F-Droid listing (Time, NonFreeNet), and the snap from
apps/todo/snap/, which the tool builds in a clone of the repository at the
tag with that folder in place of snap/, as snapcraft builds one recipe a
folder and the root's is Learn's. What's new for 0.1.0 in English and
German, now shown. Android's backup and transfer are off, as Train's
(D53): the reminders scheduled keep their tasks' titles unsealed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-11-02 15:35:40 +01:00
|
|
|
# The apps' servers .env switches on beside Learn's, each with its database
|
|
|
|
|
# (halkyon_<app>) dumped to latest-<app>.dump.
|
|
|
|
|
services=$(docker compose config --services)
|
|
|
|
|
apps=
|
feat(meditate,deploy): Meditate beside the instance, and every server's public address from .env
Meditate's deploy step (ADR 0038, step 7; ADR 0039, D14), as Todo's: the
server's Dockerfile with the library's check compiled beside it, its
production config on its own database and role, compose.meditate.yaml as a
member of the register, its site sending /library/* to the web server and
the rest to the API server, the operator's library read-only in a compose
file of its own, and redeploy.sh, backup.sh and the image replay taking it
in.
Every server's public address now comes from .env (Serverpod's
SERVERPOD_API_SERVER_PUBLIC_HOST and _WEB_SERVER_, which win over the
config file): Train, Todo and Meditate from their domains, Learn from
LEARN_PUBLIC_HOST, unset learn.halkyon.eu as before. Without it a server on
halkyon.li would name halkyon.eu in its SimpleLogin callback, profile pages
and privacy page.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-11-08 19:12:31 +01:00
|
|
|
for app in train todo meditate; do
|
build(todo): Todo deployable beside Learn's server, and released as an APK, on F-Droid and as a snap (ADR 0033, step 5)
deploy/compose.todo.yaml adds Todo's server at todo.halkyon.eu, a member
of Learn's register, its database halkyon_todo in the instance's
PostgreSQL, its image built as Train's. redeploy.sh and backup.sh go over
every app server .env switches on (train, todo). Each compose file names
its server to the register in a variable of its own
(INSTANCE_MEMBER_TRAIN, INSTANCE_MEMBER_TODO), which halkyon_base adds to
INSTANCE_MEMBERS, each address once, as a second compose file's default
would have replaced Train's.
apps/todo/release.dart configures the release tool for Todo's APK and
snap: a key of its own (pinned once made; until then nothing is
released), the F-Droid listing (Time, NonFreeNet), and the snap from
apps/todo/snap/, which the tool builds in a clone of the repository at the
tag with that folder in place of snap/, as snapcraft builds one recipe a
folder and the root's is Learn's. What's new for 0.1.0 in English and
German, now shown. Android's backup and transfer are off, as Train's
(D53): the reminders scheduled keep their tasks' titles unsealed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-11-02 15:35:40 +01:00
|
|
|
if printf '%s\n' "$services" | grep -qx "$app-server"; then
|
|
|
|
|
apps="$apps $app"
|
|
|
|
|
fi
|
|
|
|
|
done
|
2026-10-03 16:45:40 +02:00
|
|
|
(
|
|
|
|
|
umask 077
|
|
|
|
|
# Never during a deploy (redeploy.sh holds this lock): its migrations would wait
|
|
|
|
|
# for the dump, or the dump for them.
|
|
|
|
|
exec 9>"$HOME/.redeploy.lock"
|
|
|
|
|
flock 9
|
|
|
|
|
docker compose exec -T postgres pg_dump -U halkyon_learn -Fc -Z 0 halkyon_learn >"$dump.partial"
|
build(todo): Todo deployable beside Learn's server, and released as an APK, on F-Droid and as a snap (ADR 0033, step 5)
deploy/compose.todo.yaml adds Todo's server at todo.halkyon.eu, a member
of Learn's register, its database halkyon_todo in the instance's
PostgreSQL, its image built as Train's. redeploy.sh and backup.sh go over
every app server .env switches on (train, todo). Each compose file names
its server to the register in a variable of its own
(INSTANCE_MEMBER_TRAIN, INSTANCE_MEMBER_TODO), which halkyon_base adds to
INSTANCE_MEMBERS, each address once, as a second compose file's default
would have replaced Train's.
apps/todo/release.dart configures the release tool for Todo's APK and
snap: a key of its own (pinned once made; until then nothing is
released), the F-Droid listing (Time, NonFreeNet), and the snap from
apps/todo/snap/, which the tool builds in a clone of the repository at the
tag with that folder in place of snap/, as snapcraft builds one recipe a
folder and the root's is Learn's. What's new for 0.1.0 in English and
German, now shown. Android's backup and transfer are off, as Train's
(D53): the reminders scheduled keep their tasks' titles unsealed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-11-02 15:35:40 +01:00
|
|
|
for app in $apps; do
|
|
|
|
|
docker compose exec -T postgres pg_dump -U halkyon_learn -Fc -Z 0 "halkyon_$app" \
|
|
|
|
|
>"$HOME/backups/latest-$app.dump.partial"
|
|
|
|
|
done
|
2026-10-03 16:45:40 +02:00
|
|
|
)
|
|
|
|
|
mv "$dump.partial" "$dump"
|
build(todo): Todo deployable beside Learn's server, and released as an APK, on F-Droid and as a snap (ADR 0033, step 5)
deploy/compose.todo.yaml adds Todo's server at todo.halkyon.eu, a member
of Learn's register, its database halkyon_todo in the instance's
PostgreSQL, its image built as Train's. redeploy.sh and backup.sh go over
every app server .env switches on (train, todo). Each compose file names
its server to the register in a variable of its own
(INSTANCE_MEMBER_TRAIN, INSTANCE_MEMBER_TODO), which halkyon_base adds to
INSTANCE_MEMBERS, each address once, as a second compose file's default
would have replaced Train's.
apps/todo/release.dart configures the release tool for Todo's APK and
snap: a key of its own (pinned once made; until then nothing is
released), the F-Droid listing (Time, NonFreeNet), and the snap from
apps/todo/snap/, which the tool builds in a clone of the repository at the
tag with that folder in place of snap/, as snapcraft builds one recipe a
folder and the root's is Learn's. What's new for 0.1.0 in English and
German, now shown. Android's backup and transfer are off, as Train's
(D53): the reminders scheduled keep their tasks' titles unsealed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-11-02 15:35:40 +01:00
|
|
|
set -- "$dump"
|
|
|
|
|
for app in $apps; do
|
|
|
|
|
mv "$HOME/backups/latest-$app.dump.partial" "$HOME/backups/latest-$app.dump"
|
|
|
|
|
set -- "$@" "$HOME/backups/latest-$app.dump"
|
|
|
|
|
done
|
2026-10-03 16:45:40 +02:00
|
|
|
|
feat(publish): releases in git (public tier, stage 2)
A person with an identity and a public profile publishes a studyset with
everything inside it as its next release (ADR 0005, rule 3): the server
reads their synced rows and writes them through the git command as a
commit on main and the annotated tag vN, in a bare repository of the
studyset's own, named by a random public id made at the first publish.
A release is a directory per studyset with a file per card, note, path,
step and PDF (its id, position, tag names and payload as synced, keys
sorted and indented) and the files the content names, without what is
only the author's (a card's report, a PDF's deadline). Publishing is
refused without a licence allowing passing it on in every studyset ("no
derivatives" allowed), with revisions to settle, with files not uploaded
yet, when nothing changed, or for a name that won't do; the name is
fixed from the first release, as is the person's handle.
In the app, Share in a studyset's action row opens the Publish sheet;
publishing syncs first, and settles by itself the revisions that merge
cleanly, listing only real conflicts. The server's image gets git, the
repositories a volume of their own, and the hourly backup a git bundle of
each.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MMm7usAo6q9ZZRoPkWjoxi
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-10-09 22:01:00 +02:00
|
|
|
# Each repository as a git bundle, after the dump: a release the dump lacks is never
|
|
|
|
|
# numbered again (the server numbers past the highest tag), while one the bundles
|
|
|
|
|
# lacked would be lost. A bundle is whole whenever it is made: git reads the refs, then
|
|
|
|
|
# packs what they reach. A repository being created this moment has nothing to bundle
|
|
|
|
|
# yet, and comes next hour.
|
|
|
|
|
releases="$HOME/backups/repositories.tar"
|
|
|
|
|
(
|
|
|
|
|
umask 077
|
|
|
|
|
docker compose exec -T server sh -c '
|
|
|
|
|
out=$(mktemp -d)
|
|
|
|
|
for repository in /app/repositories/*.git; do
|
|
|
|
|
[ -d "$repository" ] || continue
|
|
|
|
|
git -C "$repository" bundle create --quiet \
|
|
|
|
|
"$out/$(basename "$repository" .git).bundle" --all ||
|
|
|
|
|
echo "Not bundled: $repository" >&2
|
|
|
|
|
done
|
|
|
|
|
tar -C "$out" -cf - .
|
|
|
|
|
rm -rf "$out"
|
|
|
|
|
' >"$releases.partial"
|
|
|
|
|
)
|
|
|
|
|
mv "$releases.partial" "$releases"
|
|
|
|
|
|
build(todo): Todo deployable beside Learn's server, and released as an APK, on F-Droid and as a snap (ADR 0033, step 5)
deploy/compose.todo.yaml adds Todo's server at todo.halkyon.eu, a member
of Learn's register, its database halkyon_todo in the instance's
PostgreSQL, its image built as Train's. redeploy.sh and backup.sh go over
every app server .env switches on (train, todo). Each compose file names
its server to the register in a variable of its own
(INSTANCE_MEMBER_TRAIN, INSTANCE_MEMBER_TODO), which halkyon_base adds to
INSTANCE_MEMBERS, each address once, as a second compose file's default
would have replaced Train's.
apps/todo/release.dart configures the release tool for Todo's APK and
snap: a key of its own (pinned once made; until then nothing is
released), the F-Droid listing (Time, NonFreeNet), and the snap from
apps/todo/snap/, which the tool builds in a clone of the repository at the
tag with that folder in place of snap/, as snapcraft builds one recipe a
folder and the root's is Learn's. What's new for 0.1.0 in English and
German, now shown. Android's backup and transfer are off, as Train's
(D53): the reminders scheduled keep their tasks' titles unsealed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-11-02 15:35:40 +01:00
|
|
|
restic backup --quiet "$@" "$releases"
|
2026-10-29 00:05:39 +01:00
|
|
|
# By host alone: restic groups by the paths backed up too, so a path added (Train's
|
build(todo): Todo deployable beside Learn's server, and released as an APK, on F-Droid and as a snap (ADR 0033, step 5)
deploy/compose.todo.yaml adds Todo's server at todo.halkyon.eu, a member
of Learn's register, its database halkyon_todo in the instance's
PostgreSQL, its image built as Train's. redeploy.sh and backup.sh go over
every app server .env switches on (train, todo). Each compose file names
its server to the register in a variable of its own
(INSTANCE_MEMBER_TRAIN, INSTANCE_MEMBER_TODO), which halkyon_base adds to
INSTANCE_MEMBERS, each address once, as a second compose file's default
would have replaced Train's.
apps/todo/release.dart configures the release tool for Todo's APK and
snap: a key of its own (pinned once made; until then nothing is
released), the F-Droid listing (Time, NonFreeNet), and the snap from
apps/todo/snap/, which the tool builds in a clone of the repository at the
tag with that folder in place of snap/, as snapcraft builds one recipe a
folder and the root's is Learn's. What's new for 0.1.0 in English and
German, now shown. Android's backup and transfer are off, as Train's
(D53): the reminders scheduled keep their tasks' titles unsealed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-11-02 15:35:40 +01:00
|
|
|
# dump, Todo's) would leave the snapshots before it a group of their own, never forgotten, and
|
2026-10-29 00:05:39 +01:00
|
|
|
# a deleted account in them for good.
|
|
|
|
|
restic forget --quiet --group-by host --keep-hourly 24 --keep-daily 7 --keep-weekly 4 --keep-monthly 3
|
2026-10-03 16:45:40 +02:00
|
|
|
|
|
|
|
|
# Once a day, in the run at 03:00: free the space of forgotten snapshots, and read the
|
|
|
|
|
# repository's structure; on Sundays also a tenth of the stored data, chosen at random,
|
|
|
|
|
# so damage to what was stored long ago shows within weeks.
|
|
|
|
|
if [ "$(date +%H)" = 03 ]; then
|
|
|
|
|
restic prune --quiet
|
|
|
|
|
if [ "$(date +%u)" = 7 ]; then
|
|
|
|
|
restic check --read-data-subset=10%
|
|
|
|
|
else
|
|
|
|
|
restic check
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
restic snapshots --compact --latest 1
|