Files
picpeak/scripts/backup.sh
T
paul 1773ed5f95
Mirror to GitHub / mirror (push) Successful in 26s
Test and Lint / backend-test (push) Successful in 1m11s
continuous-integration/drone/push Build is passing
Test and Lint / frontend-test (push) Successful in 2m28s
Version and Release / version-bump (push) Successful in 32s
Version and Release / trigger-drone (push) Has been skipped
Initial commit - Project start (July 17, 2025)
Original: feat: enhance security logging and ensure rate limit blocks are properly tracked

- Add comprehensive logging for rate limit blocks with full request details
  - IP address (with proper proxy detection), user agent, headers, timestamps
  - Rate limit info (current count, limit, remaining, reset time)
  - Separate tracking for auth vs general endpoints

- Enhance authentication failure logging
  - JWT validation failures with detailed error info
  - Admin auth attempts without token
  - Failed token validation with user context
  - All events include IP, path, method, user agent

- Improve Winston logger configuration for production
  - Add automatic log rotation (10MB errors, 50MB combined)
  - Create separate security.log for auth/rate limit events
  - Ensure logs directory exists automatically
  - Add structured JSON format for log aggregation
  - Support container logging with LOG_TO_CONSOLE env var

- Create comprehensive documentation
  - Security logging guide with examples
  - Monitoring recommendations
  - Configuration reference

- Add test script to verify logging functionality

All rate limit settings remain configurable via admin panel:
- Window duration, max requests, auth limits
- Skip authenticated requests option
- Public endpoints only option

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-24 16:57:07 +02:00

69 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# PicPeak Backup Script
# Creates backups of database and storage
set -e
# Configuration
BACKUP_DIR="./backups"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_NAME="picpeak_backup_${TIMESTAMP}"
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
echo "🔄 Starting PicPeak backup..."
# Create backup directory
mkdir -p "${BACKUP_DIR}/${BACKUP_NAME}"
# Backup database
echo "📊 Backing up database..."
if [ -f "./data/photo_sharing.db" ]; then
cp ./data/photo_sharing.db "${BACKUP_DIR}/${BACKUP_NAME}/"
echo -e "${GREEN}✓ SQLite database backed up${NC}"
else
# PostgreSQL backup
docker exec picpeak-postgres pg_dump -U picpeak picpeak > "${BACKUP_DIR}/${BACKUP_NAME}/database.sql" 2>/dev/null || {
echo -e "${RED}⚠ Database backup failed - is PostgreSQL running?${NC}"
}
fi
# Backup storage
echo "📸 Backing up photos..."
if [ -d "./storage" ]; then
tar -czf "${BACKUP_DIR}/${BACKUP_NAME}/storage.tar.gz" ./storage 2>/dev/null || {
echo -e "${RED}⚠ Storage backup failed${NC}"
exit 1
}
echo -e "${GREEN}✓ Storage backed up${NC}"
fi
# Backup environment files
echo "⚙️ Backing up configuration..."
cp .env "${BACKUP_DIR}/${BACKUP_NAME}/.env.backup" 2>/dev/null || true
# Create backup info
echo "📝 Creating backup info..."
cat > "${BACKUP_DIR}/${BACKUP_NAME}/backup_info.txt" << EOF
PicPeak Backup
Created: $(date)
Version: $(grep version backend/package.json | head -1 | awk -F'"' '{print $4}')
Storage Size: $(du -sh ./storage 2>/dev/null | cut -f1 || echo "N/A")
EOF
# Compress entire backup
echo "📦 Compressing backup..."
cd "${BACKUP_DIR}"
tar -czf "${BACKUP_NAME}.tar.gz" "${BACKUP_NAME}"
rm -rf "${BACKUP_NAME}"
# Cleanup old backups (keep last 7)
echo "🧹 Cleaning up old backups..."
ls -t *.tar.gz | tail -n +8 | xargs -r rm
echo -e "${GREEN}✅ Backup completed: ${BACKUP_DIR}/${BACKUP_NAME}.tar.gz${NC}"
echo "💡 To restore: tar -xzf ${BACKUP_NAME}.tar.gz && follow restore instructions"