Skip to content

Commit 9842a18

Browse files
committed
Point tests at teal_test database, add backup script
phpunit.xml was pointing at the production teal database, meaning RefreshDatabase would wipe real data. Now uses teal_test. Added scripts/backup-db.sh for timestamped pg_dump backups with auto-rotation (keeps last 20).
1 parent b537b94 commit 9842a18

4 files changed

Lines changed: 32 additions & 1 deletion

File tree

backups/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.sql
2+
!.gitignore
3+
!.gitkeep

backups/.gitkeep

Whitespace-only changes.

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<env name="DB_CONNECTION" value="pgsql"/>
2727
<env name="DB_HOST" value="127.0.0.1"/>
2828
<env name="DB_PORT" value="5432"/>
29-
<env name="DB_DATABASE" value="teal"/>
29+
<env name="DB_DATABASE" value="teal_test"/>
3030
<env name="DB_USERNAME" value="teal"/>
3131
<env name="DB_PASSWORD" value="secret"/>
3232
<env name="MAIL_MAILER" value="array"/>

scripts/backup-db.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
# Backup TEAL PostgreSQL database with timestamp
3+
# Usage: ./scripts/backup-db.sh [label]
4+
# Example: ./scripts/backup-db.sh pre-test
5+
6+
set -euo pipefail
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
10+
BACKUP_DIR="$PROJECT_DIR/backups"
11+
LABEL="${1:-manual}"
12+
TIMESTAMP="$(date +%Y%m%d_%H%M%S)"
13+
FILENAME="teal_${TIMESTAMP}_${LABEL}.sql"
14+
15+
mkdir -p "$BACKUP_DIR"
16+
17+
# Dump from the containerized PostgreSQL
18+
if podman exec teal-db pg_dump -U teal -d teal --no-owner --no-acl > "$BACKUP_DIR/$FILENAME" 2>/dev/null; then
19+
SIZE=$(du -h "$BACKUP_DIR/$FILENAME" | cut -f1)
20+
echo "Backup saved: backups/$FILENAME ($SIZE)"
21+
else
22+
echo "ERROR: Failed to backup database. Is teal-db container running?" >&2
23+
exit 1
24+
fi
25+
26+
# Keep only the 20 most recent backups
27+
cd "$BACKUP_DIR"
28+
ls -t teal_*.sql 2>/dev/null | tail -n +21 | xargs -r rm --

0 commit comments

Comments
 (0)