Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save wowaTYPO3/9fe0342bc401dd54c846a79f103cf405 to your computer and use it in GitHub Desktop.

Select an option

Save wowaTYPO3/9fe0342bc401dd54c846a79f103cf405 to your computer and use it in GitHub Desktop.
Live DB to Staging
#!/bin/bash
# Setze die Server- und Datenbank-Details
REMOTE_HOST="remote_server"
LIVE_DB_HOST="localhost"
LIVE_DB_USER="live_user"
LIVE_DB_PASS="live_password"
LIVE_DB_NAME="live_database"
STAGING_DB_HOST="localhost"
STAGING_DB_USER="staging_user"
STAGING_DB_PASS="staging_password"
STAGING_DB_NAME="staging_database"
echo "Kopiere Datenbank vom Live-System ins Staging-System..."
# SSH in den Remote-Server und führe dort die Befehle aus
ssh -T $REMOTE_HOST << ENDSSH
# Erstelle einen Dump der Live-Datenbank
mysqldump --opt --no-tablespaces -h $LIVE_DB_HOST -u $LIVE_DB_USER -p'$LIVE_DB_PASS' $LIVE_DB_NAME > ~/www/live_db_dump.sql
# Prüfe, ob der Dump erfolgreich war
if [ $? -ne 0 ]; then
echo "Fehler beim Erstellen des Live-DB-Dumps"
exit 1
fi
# Importiere den Dump in die Staging-Datenbank
mysql -h $STAGING_DB_HOST -u $STAGING_DB_USER -p'$STAGING_DB_PASS' $STAGING_DB_NAME < ~/www/live_db_dump.sql
# Prüfe, ob der Import erfolgreich war
if [ $? -ne 0 ]; then
echo "Fehler beim Importieren in die Staging-DB"
exit 1
fi
# Lösche den Dump, um Speicherplatz freizugeben
rm -f ~/www/live_db_dump.sql
ENDSSH
if [ $? -ne 0 ]; then
echo "Fehler beim Ausführen der Operationen auf dem Remote-Server"
exit 1
fi
echo "Datenbank erfolgreich von Live auf Staging kopiert."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment