forked from Nickel5-Inc/Gaia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean_test_environment.sh
More file actions
executable file
·81 lines (64 loc) · 3.26 KB
/
clean_test_environment.sh
File metadata and controls
executable file
·81 lines (64 loc) · 3.26 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# Comprehensive test environment cleanup script
# Cleans database and pgBackRest backups without deleting stanza configuration
set -e
echo "🧹 Starting comprehensive test environment cleanup..."
echo "=================================================="
# Step 1: Stop validator if running
echo "1️⃣ Stopping validator..."
pm2 stop validator 2>/dev/null || echo " Validator not running or already stopped"
# Step 2: Clear pgBackRest backup data (but keep stanza configuration)
echo "2️⃣ Wiping pgBackRest backup data..."
# Remove any stop files that might be blocking operations
echo " Removing any pgBackRest stop files..."
sudo rm -f /var/lib/pgbackrest/stop/gaia-test.stop 2>/dev/null || true
# Start pgBackRest operations to allow cleanup
echo " Starting pgBackRest operations..."
sudo -u postgres pgbackrest --stanza=gaia-test start || true
# Get current backup info before wiping
echo " Checking current backups..."
sudo -u postgres pgbackrest --stanza=gaia-test info || echo " No backup info available"
# Wipe all backup data from the repository (keeps stanza config)
echo " Wiping all backup data from repository..."
# First get list of existing backups, then expire them individually
sudo -u postgres pgbackrest --stanza=gaia-test info --output=json > /tmp/backup_info.json 2>/dev/null || true
# Remove all backups by setting very short retention and running expire
sudo -u postgres pgbackrest --stanza=gaia-test expire --repo1-retention-full=1 --repo1-retention-diff=1 || true
# Then remove the remaining backup by deleting the backup info files
echo " Cleaning backup repository files..."
sudo rm -f /var/lib/pgbackrest/backup/gaia-test/backup.info* 2>/dev/null || true
sudo rm -f /var/lib/pgbackrest/archive/gaia-test/archive.info* 2>/dev/null || true
echo " pgBackRest data wipe completed (stanza config preserved)"
# Step 3: Drop and recreate database
echo "3️⃣ Recreating database..."
sudo -u postgres psql -c "DROP DATABASE IF EXISTS validator_db;"
sudo -u postgres psql -c "CREATE DATABASE validator_db;"
# Step 4: Run Alembic migrations
echo "4️⃣ Running Alembic migrations..."
cd /root/Gaia
alembic -c alembic_validator.ini upgrade head
# Step 5: Clear any cached data
echo "5️⃣ Clearing cached data..."
rm -rf /root/Gaia/clim_cache/* 2>/dev/null || true
rm -rf /root/Gaia/verification_logs/* 2>/dev/null || true
rm -rf /tmp/weather_* 2>/dev/null || true
# Step 6: Clear Python bytecode caches
echo "6️⃣ Clearing Python bytecode caches (__pycache__, .pyc, .pyo)..."
find /root/Gaia -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find /root/Gaia -type f \( -name "*.pyc" -o -name "*.pyo" -o -name "*.pyd" \) -delete 2>/dev/null || true
# Also clear caches in local Python environment if present
if [ -d "/root/.gaia" ]; then
find /root/.gaia -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find /root/.gaia -type f \( -name "*.pyc" -o -name "*.pyo" -o -name "*.pyd" \) -delete 2>/dev/null || true
fi
echo ""
echo "✅ Test environment cleanup completed!"
echo "=================================================="
echo "🚀 Ready to restart validator with clean state"
echo ""
echo "To restart validator:"
echo " pm2 restart validator"
echo ""
echo "To monitor logs:"
echo " pm2 logs validator"
echo ""