Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-mysqlbackend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-mysqlbackend
Commits
fc7e5ff7
Commit
fc7e5ff7
authored
5 years ago
by
Daniel
Browse files
Options
Downloads
Patches
Plain Diff
FIX ENH: Works again, cleaned up code.
parent
ddc45772
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
utils/backup.sh
+27
-20
27 additions, 20 deletions
utils/backup.sh
with
27 additions
and
20 deletions
utils/backup.sh
+
27
−
20
View file @
fc7e5ff7
...
@@ -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
}
}
# Print
s
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment