Add migration services
This commit is contained in:
39
infrastructure/scripts/recipes_backup.sh
Executable file
39
infrastructure/scripts/recipes_backup.sh
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Backup script for recipes database
|
||||
set -e
|
||||
|
||||
SERVICE_NAME="recipes"
|
||||
BACKUP_DIR="${BACKUP_DIR:-./backups}"
|
||||
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
||||
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
|
||||
|
||||
# Create backup directory if it doesn't exist
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
|
||||
echo "Starting backup for $SERVICE_NAME database..."
|
||||
|
||||
# Get database credentials from Kubernetes secrets
|
||||
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.RECIPES_DB_USER}' | base64 -d)
|
||||
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.RECIPES_DB_NAME}')
|
||||
|
||||
# Get the pod name
|
||||
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=recipes-db -o jsonpath='{.items[0].metadata.name}')
|
||||
|
||||
if [ -z "$POD_NAME" ]; then
|
||||
echo "Error: Could not find recipes database pod"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Backing up to: $BACKUP_FILE"
|
||||
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Backup completed successfully: $BACKUP_FILE"
|
||||
# Compress the backup
|
||||
gzip "$BACKUP_FILE"
|
||||
echo "Backup compressed: ${BACKUP_FILE}.gz"
|
||||
else
|
||||
echo "Backup failed"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user