Skip to content

Instantly share code, notes, and snippets.

@suabo
Created August 18, 2018 13:28
Show Gist options
  • Save suabo/41c5d2e36aa03841120e771429285b85 to your computer and use it in GitHub Desktop.
Save suabo/41c5d2e36aa03841120e771429285b85 to your computer and use it in GitHub Desktop.
MySQL OXID Dump without Views - Bash Script
#!/bin/bash
# $1 = dbname
# $2 = dbusername
# $3 = dumpfile
# $4 = hostname
# $5 = gzip
if [ "$1" == "" ]
then
echo "Syntax!"
echo "cmd dbname dbusername dumpfile [hostname]"
exit 255
fi
if [ "$2" == "" ]
then
echo "Syntax!"
echo "cmd dbname dbusername dumpfile [hostname]"
exit 255
fi
if [ "$3" == "" ]
then
echo "Syntax!"
echo "cmd dbname dbusername dumpfile [hostname]"
exit 255
else
filename="$3.sql"
fi
if [ "$4" == "" ]
then
echo "No Hostname given, using localhost."
hostname="localhost"
else
hostname=$4
fi
if [ "$5" != "" ]
then
gzip="| gzip -9"
filename="$3.gz.sql"
else
gzip=""
fi
echo "Starte MySQL Backup von ohne Views (oxv_ Tabellen)"
echo "Hostname: $hostname"
echo "Datenbank: $1"
echo "Benutzer: $2"
query="'show tables where tables_in_$1 not like \"oxv\_%\"'"
eval "mysql $1 -h $hostname -u $2 -p -e $query | grep -v Tables_in | xargs mysqldump $1 -h $hostname -u $2 -p $gzip > $filename"
if [ -f $3 ]
then
echo "Exportdatei $3 wurde erfolgreich geschrieben."
else
echo "Fehler! Exportdatei $3 wurde nicht erstellt."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment