Add migration services
This commit is contained in:
47
infrastructure/scripts/notification_restore.sh
Executable file
47
infrastructure/scripts/notification_restore.sh
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Restore script for notification database
|
||||
set -e
|
||||
|
||||
SERVICE_NAME="notification"
|
||||
BACKUP_FILE="$1"
|
||||
|
||||
if [ -z "$BACKUP_FILE" ]; then
|
||||
echo "Usage: $0 <backup_file>"
|
||||
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$BACKUP_FILE" ]; then
|
||||
echo "Error: Backup file not found: $BACKUP_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
|
||||
|
||||
# Get database credentials from Kubernetes secrets
|
||||
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.NOTIFICATION_DB_USER}' | base64 -d)
|
||||
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.NOTIFICATION_DB_NAME}')
|
||||
|
||||
# Get the pod name
|
||||
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=notification-db -o jsonpath='{.items[0].metadata.name}')
|
||||
|
||||
if [ -z "$POD_NAME" ]; then
|
||||
echo "Error: Could not find notification database pod"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if file is compressed
|
||||
if [[ "$BACKUP_FILE" == *.gz ]]; then
|
||||
echo "Decompressing backup file..."
|
||||
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
|
||||
else
|
||||
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Restore completed successfully"
|
||||
else
|
||||
echo "Restore failed"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user