small fix, don't worry about it

This commit is contained in:
Tomas Dvorak
2026-04-10 12:06:24 +02:00
commit 5c500a72b0
243 changed files with 44176 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
#!/bin/sh
# Database Backup Script for SEEN
# Runs daily automated backups with retention policy
set -e
# Configuration
BACKUP_DIR="/backups"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/seen_backup_${TIMESTAMP}.sql.gz"
RETENTION_DAYS=${BACKUP_RETENTION_DAYS:-7}
# Create backup directory if it doesn't exist
mkdir -p "${BACKUP_DIR}"
echo "[$(date)] Starting database backup..."
# Perform backup
PGPASSWORD="${POSTGRES_PASSWORD}" pg_dump \
-h "${POSTGRES_HOST}" \
-U "${POSTGRES_USER}" \
-d "${POSTGRES_DB}" \
--format=plain \
--no-owner \
--no-acl \
| gzip > "${BACKUP_FILE}"
# Check if backup was successful
if [ $? -eq 0 ]; then
BACKUP_SIZE=$(du -h "${BACKUP_FILE}" | cut -f1)
echo "[$(date)] Backup completed successfully: ${BACKUP_FILE} (${BACKUP_SIZE})"
else
echo "[$(date)] ERROR: Backup failed!"
exit 1
fi
# Clean up old backups
echo "[$(date)] Cleaning up backups older than ${RETENTION_DAYS} days..."
find "${BACKUP_DIR}" -name "seen_backup_*.sql.gz" -type f -mtime +${RETENTION_DAYS} -delete
# List current backups
echo "[$(date)] Current backups:"
ls -lh "${BACKUP_DIR}"/seen_backup_*.sql.gz 2>/dev/null || echo "No backups found"
echo "[$(date)] Backup process completed"
+67
View File
@@ -0,0 +1,67 @@
#!/bin/bash
# Generate Strong Secrets for SEEN Production Deployment
#
# This script generates cryptographically secure random secrets
# for use in production environment configuration.
set -e
echo "==================================="
echo "SEEN - Secret Generation Tool"
echo "==================================="
echo ""
# Check if openssl is available
if ! command -v openssl &> /dev/null; then
echo "ERROR: openssl is required but not installed."
echo "Please install openssl and try again."
exit 1
fi
echo "Generating secure secrets..."
echo ""
# Generate JWT secret (32 bytes = 256 bits)
JWT_SECRET=$(openssl rand -base64 32)
echo "JWT Secret (SEEN_AUTH_JWT_SECRET):"
echo "${JWT_SECRET}"
echo ""
# Generate database password (24 bytes)
DB_PASSWORD=$(openssl rand -base64 24 | tr -d "=+/" | cut -c1-32)
echo "Database Password (POSTGRES_PASSWORD):"
echo "${DB_PASSWORD}"
echo ""
# Generate cache password (optional, 24 bytes)
CACHE_PASSWORD=$(openssl rand -base64 24 | tr -d "=+/" | cut -c1-32)
echo "Cache Password (SEEN_CACHE_PASSWORD - optional):"
echo "${CACHE_PASSWORD}"
echo ""
# Generate session secret (32 bytes)
SESSION_SECRET=$(openssl rand -base64 32)
echo "Session Secret (for future use):"
echo "${SESSION_SECRET}"
echo ""
echo "==================================="
echo "IMPORTANT SECURITY NOTES:"
echo "==================================="
echo ""
echo "1. Store these secrets securely (password manager, secrets vault)"
echo "2. Never commit these secrets to version control"
echo "3. Use different secrets for each environment (dev/staging/prod)"
echo "4. Rotate secrets periodically (every 90 days recommended)"
echo "5. Update backend/.env.production with these values"
echo ""
echo "Quick setup command:"
echo "-----------------------------------"
echo "# Copy to production env file"
echo "cp backend/.env.production backend/.env.production.local"
echo ""
echo "# Then manually edit backend/.env.production.local and replace:"
echo "# - SEEN_AUTH_JWT_SECRET with the JWT Secret above"
echo "# - POSTGRES_PASSWORD with the Database Password above"
echo ""
echo "==================================="
+67
View File
@@ -0,0 +1,67 @@
#!/bin/sh
# Database Restore Script for SEEN
# Restores database from a backup file
set -e
# Check if backup file is provided
if [ -z "$1" ]; then
echo "Usage: $0 <backup_file.sql.gz>"
echo ""
echo "Available backups:"
ls -lh /backups/seen_backup_*.sql.gz 2>/dev/null || echo "No backups found"
exit 1
fi
BACKUP_FILE="$1"
# Check if backup file exists
if [ ! -f "${BACKUP_FILE}" ]; then
echo "ERROR: Backup file not found: ${BACKUP_FILE}"
exit 1
fi
echo "[$(date)] Starting database restore from: ${BACKUP_FILE}"
echo "WARNING: This will overwrite the current database!"
read -p "Are you sure you want to continue? (yes/no): " CONFIRM
if [ "${CONFIRM}" != "yes" ]; then
echo "Restore cancelled"
exit 0
fi
# Drop existing connections
echo "[$(date)] Terminating existing connections..."
PGPASSWORD="${POSTGRES_PASSWORD}" psql \
-h "${POSTGRES_HOST}" \
-U "${POSTGRES_USER}" \
-d postgres \
-c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '${POSTGRES_DB}' AND pid <> pg_backend_pid();"
# Drop and recreate database
echo "[$(date)] Recreating database..."
PGPASSWORD="${POSTGRES_PASSWORD}" psql \
-h "${POSTGRES_HOST}" \
-U "${POSTGRES_USER}" \
-d postgres \
-c "DROP DATABASE IF EXISTS ${POSTGRES_DB};"
PGPASSWORD="${POSTGRES_PASSWORD}" psql \
-h "${POSTGRES_HOST}" \
-U "${POSTGRES_USER}" \
-d postgres \
-c "CREATE DATABASE ${POSTGRES_DB};"
# Restore backup
echo "[$(date)] Restoring backup..."
gunzip -c "${BACKUP_FILE}" | PGPASSWORD="${POSTGRES_PASSWORD}" psql \
-h "${POSTGRES_HOST}" \
-U "${POSTGRES_USER}" \
-d "${POSTGRES_DB}"
if [ $? -eq 0 ]; then
echo "[$(date)] Restore completed successfully!"
else
echo "[$(date)] ERROR: Restore failed!"
exit 1
fi