Skip to content
Snippets Groups Projects
Commit fc7e5ff7 authored by Daniel's avatar Daniel
Browse files

FIX ENH: Works again, cleaned up code.

parent ddc45772
Branches
Tags
No related merge requests found
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
# The directory which the dump is to be stored to. Do not change it here. Use # The directory which the dump is to be stored to. Do not change it here. Use
# the --backupdir=./my/dir/ option or an environment variable instead. # the --backupdir=./my/dir/ option or an environment variable instead.
BACKUPDIR="${BACKUPDIR:-../backup}" BACKUPDIR="${BACKUPDIR:-../backup}"
# Iff this (environment) variable is "true" as lower-case, then this script also # Iff this (environment) variable is "true" as lower-case, then this script also
# outputs a machine readable status report. The variable can also be set by # outputs a machine readable status report. The variable can also be set by
# giving the `--yaml` command line option. # giving the `--yaml` command line option.
...@@ -36,7 +37,7 @@ PRINT_HELP="--backupdir=BACKUPDIR\n\tThe directory which the dump is to be store ...@@ -36,7 +37,7 @@ PRINT_HELP="--backupdir=BACKUPDIR\n\tThe directory which the dump is to be store
# YAML string templates ####################################################### # YAML string templates #######################################################
YAMLFAIL=$(cat << "EOF" YAML_FAIL=$(cat << "EOF"
#### YAML #### #### YAML ####
error: error:
code: $error_code code: $error_code
...@@ -45,7 +46,7 @@ error: ...@@ -45,7 +46,7 @@ error:
EOF EOF
) )
YAMLSUCCESS=$(cat << "EOF" YAML_SUCCESS=$(cat << "EOF"
#### YAML #### #### YAML ####
error: error:
code: 0 code: 0
...@@ -64,25 +65,26 @@ EOF ...@@ -64,25 +65,26 @@ EOF
# load useful stuff - parses the commandline parameters and so on... # load useful stuff - parses the commandline parameters and so on...
. ../patches/utils/patch_header.sh . ../patches/utils/patch_header.sh
echo "BACKUPDIR: $BACKUPDIR"
echo "YAML: $YAML"
function backup() { function backup() {
NARG_NAME="$1" NARG_NAME="$1"
NARG_FILE="$2" NARG_FILE="$2"
shift 2 shift 2
echo $MYSQLDUMP_CMD
# parameters: connection, database, outfile # parameters: connection, database, outfile
if [ -e "$NARG_FILE" ]; then if [ -e "$NARG_FILE" ]; then
failure "dumpfile already exists." failure "dumpfile already exists."
fi fi
echo "Dumping database $NARG_NAME to $NARG_FILE ... " echo "Dumping database $NARG_NAME to $NARG_FILE ... "
$CMD_MYSQL_DUMP $MYSQL_CONNECTION_NO_DB $* --opt --default-character-set=utf8 --routines \ $CMD_MYSQL_DUMP $MYSQL_CONNECTION_NO_DB $* --opt --default-character-set=utf8 --routines \
$NARG_NAME > $NARG_FILE "$NARG_NAME" > "$NARG_FILE"
if [[ "$YAML" == "true" ]] ; then
yaml_success "$NARG_FILE" "$DATE"
fi
success success
} }
# Prints a YAML failure message, if YAML is true. # Print a YAML failure message, if YAML is true.
# #
# Arguments: # Arguments:
# - $1 Error code, integer > 0 # - $1 Error code, integer > 0
...@@ -95,24 +97,35 @@ function yaml_fail() { ...@@ -95,24 +97,35 @@ function yaml_fail() {
echo "$yaml" echo "$yaml"
} }
# Prints a YAML success message, if YAML is true. # Print a YAML success message, if YAML is true.
#
# Arguments:
# - $1 The file location of the backup file.
# - $2 The current date & time
function yaml_success() { function yaml_success() {
file_location="$1"
date="$2"
local yaml="${YAML_SUCCESS/\$file_location/$file_location}"
yaml="${yaml/\$date/$date}"
echo "$yaml"
} }
##test dump file exists ## test if dump file exists
#touch dumpfile.tmp #touch dumpfile.tmp
#backup 0 1 2 "dumpfile.tmp" #backup 0 1 2 "dumpfile.tmp"
#rm dumpfile.tmp #rm dumpfile.tmp
# create backup dir if not exists # Assert backup dir
mkdir -p "$BACKUPDIR" mkdir -p "$BACKUPDIR"
DATE=$(date -u --rfc-3339=ns | sed 's/ /T/g') DATE=$(date -u --rfc-3339=ns | sed 's/ /T/g')
BACKUPFILE=${BACKUPDIR}/${DATABASE_NAME}.${DATE}.dump.sql BACKUPFILE=${BACKUPDIR}/${DATABASE_NAME}.${DATE}.dump.sql
#YAMLSUCCESS=$(cat <<"EOF" # echo "date: $date" >&2
read -r -d '' YAMLSUCCESS <<"EOF" || true # echo "file_location: $file_location" >&2
#YAML_SUCCESS=$(cat <<"EOF"
read -r -d '' YAML_SUCCESS <<"EOF" || true
#### YAML #### #### YAML ####
error: error:
code: 0 code: 0
...@@ -123,10 +136,4 @@ backup: ...@@ -123,10 +136,4 @@ backup:
#### YAML END #### #### YAML END ####
EOF EOF
echo "YAMLSUCCESS:"
echo "$YAMLSUCCESS"
backup $DATABASE_NAME $BACKUPFILE backup $DATABASE_NAME $BACKUPFILE
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment