File size: 1,181 Bytes
af1bee9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/sh
# Back up everything the application stores: database, secrets vault, encrypted evidence, reports, script library.
#   ./backup.sh [target-directory]        (default: ./backups)
# The archive contains the secrets vault, so store it encrypted and restrict who can read it.
# Restore: stop the stack, then
#   docker run --rm -v patch-coworker_fpt-data:/data -v "$PWD/backups":/b alpine sh -c "rm -rf /data/* && tar -xzf /b/<file>.tar.gz -C /data"
set -eu
TARGET="${1:-./backups}"
STAMP="$(date -u +%Y%m%dT%H%M%SZ)"
mkdir -p "$TARGET"

# A consistent copy of the SQLite database while the application keeps running.
docker compose exec -T app python - <<'PY'
import os, sqlite3
home = os.environ["FPT_HOME"]
for name in ("fpt.sqlite", "checkpoints.sqlite"):
    src = os.path.join(home, name)
    if os.path.exists(src):
        with sqlite3.connect(src) as s, sqlite3.connect(src + ".backup") as d:
            s.backup(d)
print("database snapshot written")
PY

docker run --rm -v patch-coworker_fpt-data:/data:ro -v "$(cd "$TARGET" && pwd)":/backup alpine \
  tar -czf "/backup/patch-coworker-$STAMP.tar.gz" -C /data .
echo "backup: $TARGET/patch-coworker-$STAMP.tar.gz"