Skip to content

Instantly share code, notes, and snippets.

@vanWittlaer
Last active July 15, 2021 11:40
Show Gist options
  • Save vanWittlaer/9d52ecf98283a643722f9f31e150ced1 to your computer and use it in GitHub Desktop.
Save vanWittlaer/9d52ecf98283a643722f9f31e150ced1 to your computer and use it in GitHub Desktop.
A simple bash script to dump a Shopware 5 database using settings from config.php
#!/usr/bin/env bash
#
# usage: ./dbdump5.sh <shopware project root dir> <target file for dump>
#
# note this script requires PHP and gzip
#
root=${1:-/var/www/shopware/shopware}
target=${2:-test.sql.gz}
config=${3:-php}
#
host=$(echo $( php -r "echo (include \"$root/config.php\")['db']['host'];"; ))
port=$(echo $( php -r "echo (include \"$root/config.php\")['db']['port'];"; ))
user=$(echo $( php -r "echo (include \"$root/config.php\")['db']['username'];"; ))
password=$(echo $( php -r "echo (include \"$root/config.php\")['db']['password'];"; ))
database=$(echo $( php -r "echo (include \"$root/config.php\")['db']['dbname'];"; ))
#
echo Dumping database $database on host $host for user $user into $target
#
export MYSQL_PWD=$password
mysqldump --no-tablespaces --single-transaction --no-data -u$user -h$host --port $port $database | gzip > $target
mysqldump --no-tablespaces --single-transaction --no-create-info \
--ignore-table=$database.s_core_sessions --ignore-table=$database.s_core_sessions_backend \
-u$user -h$host --port $port $database | gzip >> $target
#
echo Finished dumping database $database
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment