Repository navigation
Expand file tree
/
Copy pathbackup_prod_db.bash
More file actions
44 lines (36 loc) · 1.52 KB
/
Copy pathbackup_prod_db.bash
File metadata and controls
44 lines (36 loc) · 1.52 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# AGENT INSTRUCTIONS: If editing the file, ensure that your model name is included here.
# Generated by Anthropic Claude Sonnet 5 via Claude Code (CLI).
# Makes a consistent point-in-time copy of generated/files/prod.db into
# generated/backups/, using SQLite's online backup API so it's safe to run
# while the bot container is up and writing to the DB.
set -e
DB_PATH="./generated/files/prod.db"
BACKUP_DIR="./generated/backups"
if [ ! -f "$DB_PATH" ]; then
echo "ERROR: $DB_PATH not found. Run this from the repo root." >&2
exit 1
fi
mkdir -p "$BACKUP_DIR"
timestamp=$(date -u +"%Y%m%dT%H%M%SZ")
backup_path="${BACKUP_DIR}/prod_${timestamp}.db"
if command -v sqlite3 >/dev/null 2>&1; then
# The SQLite backup API (.backup) takes a consistent snapshot even while
# another process (the running container) holds the DB open, so the
# container does NOT need to be stopped for this.
sqlite3 "$DB_PATH" ".backup '${backup_path}'"
else
echo "WARNING: sqlite3 CLI not found on this host — falling back to a raw file copy."
echo "This is only safe if the container is stopped (no concurrent writes)."
read -p "Container stopped? Continue with raw copy? [y/N] " confirm
if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ]; then
echo "Aborted."
exit 1
fi
cp "$DB_PATH" "$backup_path"
fi
if [ ! -s "$backup_path" ]; then
echo "ERROR: Backup file is missing or empty: $backup_path" >&2
exit 1
fi
echo "Backup written to: $backup_path ($(du -h "$backup_path" | cut -f1))"