Skip to content
Snippets Groups Projects
Unverified Commit c0542b35 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

FIX backup script

parent 5cbd671b
Branches
Tags
No related merge requests found
...@@ -25,8 +25,9 @@ ...@@ -25,8 +25,9 @@
#dump a database with all procedures, permissions, structure and data #dump a database with all procedures, permissions, structure and data
BACKUPDIR=./backup #The directory which the dump is to be stored to. Do not change it here. Use the --backupdir=./my/dir/ option! BACKUPDIR=./backup #The directory which the dump is to be stored to. Do not change it here. Use the --backupdir=./my/dir/ option!
PRINT_HELP="--backupdir=BACKUPDIR\n\tThe directory which the dump is to be stored to. (Defaults to ./backup)" PRINT_HELP="--backupdir=BACKUPDIR\n\tThe directory which the dump is to be stored to. (Defaults to ./backup)\n"
. .config
# load useful stuff - scans the parameters and so on... # load useful stuff - scans the parameters and so on...
. patches/utils/patch_header.sh . patches/utils/patch_header.sh
...@@ -36,12 +37,12 @@ PRINT_HELP="--backupdir=BACKUPDIR\n\tThe directory which the dump is to be store ...@@ -36,12 +37,12 @@ PRINT_HELP="--backupdir=BACKUPDIR\n\tThe directory which the dump is to be store
function backup { function backup {
# parameters: login-path, database, outfile # parameters: connection, database, outfile
if [ -e "$3" ]; then if [ -e "$3" ]; then
failure "dumpfile already exists." failure "dumpfile already exists."
fi fi
echo -n "Dumping database $3 to $4 ... " echo "Dumping database $2 to $3 ... "
$CMD_MYSQL_DUMP --opt --default-character-set=utf8 --routines --login-path=$1 $2 > ${3} $CMD_MYSQL_DUMP $1 --opt --default-character-set=utf8 --routines $2 > ${3}
success success
} }
...@@ -56,7 +57,7 @@ function backup { ...@@ -56,7 +57,7 @@ function backup {
DATE=$(date -u --rfc-3339=ns | sed 's/ /T/g') DATE=$(date -u --rfc-3339=ns | sed 's/ /T/g')
BACKUPFILE=${BACKUPDIR}/${DATABASE}.${DATE}.dump.sql BACKUPFILE=${BACKUPDIR}/${DATABASE_NAME}.${DATE}.dump.sql
backup $LOGIN_PATH $DATABASE $BACKUPFILE backup $MYSQL_CONNECTION $DATABASE_NAME $BACKUPFILE
...@@ -28,13 +28,13 @@ CMD_OPTIONS="options:\n\n-h, --help\n\tShow brief help.\n-l LOGIN_PATH, --login- ...@@ -28,13 +28,13 @@ CMD_OPTIONS="options:\n\n-h, --help\n\tShow brief help.\n-l LOGIN_PATH, --login-
set -e set -e
function _print_help() { function _print_help() {
printf $USAGE printf "$USAGE"
printf $CMD_OPTIONS printf "$CMD_OPTIONS"
if [ -n "$PRINT_HELP" ]; then if [ -n "$PRINT_HELP" ]; then
printf $PRINT_HELP printf -- "$PRINT_HELP"
fi fi
if [ -n "$1" ]; then if [ -n "$1" ]; then
printf $1 printf "$1"
fi fi
} }
while test $# -gt 0; do while test $# -gt 0; do
...@@ -60,7 +60,7 @@ while test $# -gt 0; do ...@@ -60,7 +60,7 @@ while test $# -gt 0; do
-u) -u)
shift shift
if test $# -gt 0; then if test $# -gt 0; then
DBUSER=$1 DATABASE_USER=$1
else else
echo "no database specified" echo "no database specified"
exit 1 exit 1
...@@ -68,7 +68,7 @@ while test $# -gt 0; do ...@@ -68,7 +68,7 @@ while test $# -gt 0; do
shift shift
;; ;;
--user*) --user*)
DBUSER=`echo $1 | sed -e 's/^[^=]*=//g'` DATABASE_USER=`echo $1 | sed -e 's/^[^=]*=//g'`
shift shift
;; ;;
-l) -l)
...@@ -88,7 +88,7 @@ while test $# -gt 0; do ...@@ -88,7 +88,7 @@ while test $# -gt 0; do
-d) -d)
shift shift
if test $# -gt 0; then if test $# -gt 0; then
DATABASE=$1 DATABASE_NAME=$1
else else
echo "no database specified" echo "no database specified"
exit 1 exit 1
...@@ -96,7 +96,7 @@ while test $# -gt 0; do ...@@ -96,7 +96,7 @@ while test $# -gt 0; do
shift shift
;; ;;
--database*) --database*)
DATABASE=`echo $1 | sed -e 's/^[^=]*=//g'` DATABASE_NAME=`echo $1 | sed -e 's/^[^=]*=//g'`
shift shift
;; ;;
--patch*) --patch*)
...@@ -113,9 +113,9 @@ while test $# -gt 0; do ...@@ -113,9 +113,9 @@ while test $# -gt 0; do
esac esac
done done
if [ -z "$DATABASE" ] if [ -z "$DATABASE_NAME" ]
then then
print_help "Please specify the database." _print_help "Please specify the database."
exit 1 exit 1
fi fi
...@@ -124,7 +124,7 @@ then ...@@ -124,7 +124,7 @@ then
MYSQL_CONNECTION="--login-path=$LOGIN_PATH" MYSQL_CONNECTION="--login-path=$LOGIN_PATH"
else else
MYSQL_CONNECTION="" MYSQL_CONNECTION=""
if [ "$DBUSER" ] if [ "$DATABASE_USER" ]
then then
MYSQL_CONNECTION="--user=$DBUSER" MYSQL_CONNECTION="--user=$DBUSER"
fi fi
...@@ -135,7 +135,7 @@ else ...@@ -135,7 +135,7 @@ else
fi fi
if [ -n "$PATCH" ]; then if [ -n "$PATCH" ]; then
echo -ne "applying patch $PATCH to $DATABASE ... " echo -ne "applying patch $PATCH to $DATABASE_NAME ... "
fi fi
function success { function success {
...@@ -155,7 +155,7 @@ function uptodate { ...@@ -155,7 +155,7 @@ function uptodate {
# @param $1: db version string, e.g. v2.0.0 # @param $1: db version string, e.g. v2.0.0
# @return: 0 on success, 1 on failure # @return: 0 on success, 1 on failure
function check_version { function check_version {
local version=$($CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -B -e "Select CaosDBVersion();") local version=$($CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE_NAME -B -e "Select CaosDBVersion();")
if [[ "$(echo $version | sed 's/^CaosDBVersion()\s//')" = "$1" ]]; then if [[ "$(echo $version | sed 's/^CaosDBVersion()\s//')" = "$1" ]]; then
return 0 return 0
fi fi
...@@ -168,13 +168,13 @@ function update_version { ...@@ -168,13 +168,13 @@ function update_version {
} }
function dump_table { function dump_table {
$CMD_MYSQL_DUMP $MYSQL_CONNECTION $DATABASE $1 > ${DATABASE}.${1}.${OLD_VERSION}.dump.sql $CMD_MYSQL_DUMP $MYSQL_CONNECTION $DATABASE_NAME $1 > ${DATABASE_NAME}.${1}.${OLD_VERSION}.dump.sql
} }
function mysql_execute { function mysql_execute {
set +e set +e
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e "$1" $CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE_NAME -e "$1"
ret=${PIPESTATUS[0]} ret=${PIPESTATUS[0]}
if [ "$ret" -ne 0 ]; then if [ "$ret" -ne 0 ]; then
failure "MYSQL ERROR" failure "MYSQL ERROR"
...@@ -183,5 +183,5 @@ function mysql_execute { ...@@ -183,5 +183,5 @@ function mysql_execute {
} }
function redo_table { function redo_table {
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE < ${DATABASE}.${1}.${OLD_VERSION}.dump.sql $CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE_NAME < ${DATABASE_NAME}.${1}.${OLD_VERSION}.dump.sql
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment