Something went wrong. Try again.
atproto pds pds.zat.dev
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374#!/bin/sh# The container's command. With no Litestream setting it is zds and nothing# else. With ZDS_LITESTREAM_URL, ZDS_LITESTREAM_BUCKET or# ZDS_LITESTREAM_CONFIG, Litestream runs zds as its child and streams the# database to the replica until zds exits; see docs/backups.md.set -eu
if [ -z "${ZDS_LITESTREAM_URL:-}${ZDS_LITESTREAM_BUCKET:-}${ZDS_LITESTREAM_CONFIG:-}" ]; then exec zds "$@"fi
export ZDS_DB="${ZDS_DB:-/data/zds.sqlite3}"export ZDS_LITESTREAM_PATH="${ZDS_LITESTREAM_PATH:-zds.sqlite3}"export ZDS_LITESTREAM_SYNC_INTERVAL="${ZDS_LITESTREAM_SYNC_INTERVAL:-10s}"export ZDS_LITESTREAM_RETENTION="${ZDS_LITESTREAM_RETENTION:-168h}"
if [ -z "${ZDS_LITESTREAM_CONFIG:-}" ] && [ -n "${ZDS_LITESTREAM_URL:-}" ]; then if [ -n "${ZDS_LITESTREAM_BUCKET:-}" ]; then echo "zds: set ZDS_LITESTREAM_URL or ZDS_LITESTREAM_BUCKET, not both; see docs/backups.md." >&2 exit 1 fi # Litestream expands the variables when it reads the file, so a password in # the URL is never written to disk. AWS_REGION stays as it is: the "auto" # default below would stop Litestream looking up an AWS bucket's region. config="${TMPDIR:-/tmp}/zds-litestream.yml" cat >"$config" <<'EOF'dbs: - path: ${ZDS_DB} replica: url: ${ZDS_LITESTREAM_URL} sync-interval: ${ZDS_LITESTREAM_SYNC_INTERVAL}
snapshot: interval: 24h retention: ${ZDS_LITESTREAM_RETENTION}EOF replica="ZDS_LITESTREAM_URL"else export AWS_ENDPOINT_URL_S3="${AWS_ENDPOINT_URL_S3:-}" export AWS_REGION="${AWS_REGION:-auto}" config="${ZDS_LITESTREAM_CONFIG:-/etc/zds/litestream.yml}" replica="${ZDS_LITESTREAM_CONFIG:-$ZDS_LITESTREAM_BUCKET/$ZDS_LITESTREAM_PATH}"fi
# A machine that comes up without its database must not replicate an empty# one over the backup: Litestream would take the new database as the# replica's latest state. With ZDS_LITESTREAM_RESTORE_IF_MISSING=true the# replica is restored first; otherwise zds starts empty only when the replica# is empty too (a new install), and refuses to start when it is not.restore=""if [ ! -e "$ZDS_DB" ]; then if [ "${ZDS_LITESTREAM_RESTORE_IF_MISSING:-false}" = true ]; then restore="-restore-if-db-not-exists" elif plan=$(litestream restore -config "$config" -dry-run -o /dev/null "$ZDS_DB" 2>&1); then echo "zds: $ZDS_DB is missing but the replica at $replica has a backup." >&2 echo "zds: refusing to replicate an empty database over it. Restore it (ZDS_LITESTREAM_RESTORE_IF_MISSING=true)" >&2 echo "zds: or point zds at a new, empty replica; see docs/backups.md." >&2 exit 1 else case "$plan" in *"no matching backup files"*) ;; *) echo "zds: $ZDS_DB is missing and the replica could not be checked:" >&2 echo "$plan" >&2 exit 1 ;; esac fifi
# Litestream's -exec takes one string that it splits on spaces, so arguments# containing spaces are not supported here.exec litestream replicate -config "$config" $restore -exec "zds${*:+ $*}"