Skip to content

Instantly share code, notes, and snippets.

@Rene-Roscher
Created June 28, 2023 12:35
Show Gist options
  • Select an option

  • Save Rene-Roscher/9ca100ab9c3742a14ed7f910e05aa7b5 to your computer and use it in GitHub Desktop.

Select an option

Save Rene-Roscher/9ca100ab9c3742a14ed7f910e05aa7b5 to your computer and use it in GitHub Desktop.
bash livck-db-dump.sh
#!/bin/bash
# Name of the database service defined in the docker-compose.yml
DB_SERVICE="database"
# Destination directory for the MySQL dump file
EXPORT_DIR="/opt/livck"
# Name of the database to export
DATABASE_NAME="livck-cp"
# Path to the .env file
ENV_FILE="/opt/livck/.env"
# Load the environment variables from the .env file
export $(grep -v '^#' "$ENV_FILE" | xargs -d '\n')
docker-compose exec "$DB_SERVICE" sh -c "apt-get update && apt-get install -y mysql-client"
# Dump the MySQL database from the container
docker-compose exec -T "$DB_SERVICE" sh -c "mysqldump --single-transaction -u\"$DB_USERNAME\" -p\"$DB_PASSWORD\" --databases \"$DATABASE_NAME\" --no-tablespaces --skip-column-statistics" > "$EXPORT_DIR/db_dump.sql"
echo "MySQL database dumped successfully: $EXPORT_DIR/db_dump.sql"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment