Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iml-backup
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
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
IML Open Source
iml-backup
Commits
c4868db7
Commit
c4868db7
authored
3 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
couchdb: fixes with shellcheck
parent
dedc6dc0
No related branches found
No related tags found
1 merge request
!26
Eliminate scheduler
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
plugins/localdump/couchdb.sh
+42
-46
42 additions, 46 deletions
plugins/localdump/couchdb.sh
with
42 additions
and
46 deletions
plugins/localdump/couchdb.sh
+
42
−
46
View file @
c4868db7
...
...
@@ -10,10 +10,11 @@
#
# 2017-03-24 ah,ds v0.9 backup
# 2017-03-27 ..... v1.0 restore
# 2022-01-20 v1.1 fixes with shellcheck
# ================================================================================
if
[
-z
$BACKUP_TARGETDIR
]
;
then
echo
ERROR: you cannot start
`
basename
$0
`
directly
if
[
-z
"
$BACKUP_TARGETDIR
"
]
;
then
echo
ERROR: you cannot start
$(
basename
$0
)
directly
rc
=
$rc
+1
exit
1
fi
...
...
@@ -41,10 +42,10 @@ function _couchapi(){
# sParams="$sParams -u ${couchdbuser}:${couchdbpw}"
sParams
=
"
$sParams
-X
${
method
}
"
sParams
=
"
$sParams
${
COUCHDB_URL
}${
apiurl
}
"
if
[
!
-z
$outfile
]
;
then
if
[
!
-z
"
$outfile
"
]
;
then
sParams
=
"
$sParams
-o
${
outfile
}
"
fi
curl
$sParams
2>/dev/null
curl
"
$sParams
"
2>/dev/null
}
function
_couchGet
(){
...
...
@@ -52,7 +53,7 @@ function _couchGet(){
}
function
_getDblist
(){
_couchGet _all_dbs |
sed
's#\"#\n#g'
|
e
grep
-v
"^(
\[
|
\,
|
\]
)$"
_couchGet _all_dbs |
sed
's#\"#\n#g'
|
grep
-
E
v
"^(
\[
|
\,
|
\]
)$"
}
...
...
@@ -60,11 +61,10 @@ function _getDblist(){
# get valid configured instances
function
getInstances
(){
for
mycfg
in
`
ls
-1
~/.iml_backup/couchdb/
*
.config
`
for
mycfg
in
$(
ls
-1
"
~/.iml_backup/couchdb/*.config
"
)
do
.
$mycfg
if
[
$?
-eq
0
]
;
then
echo
`
basename
"
${
mycfg
}
"
|
cut
-f
1
-d
"."
`
if
.
"
$mycfg
"
;
then
echo
$(
basename
"
${
mycfg
}
"
|
cut
-f
1
-d
"."
)
fi
done
}
...
...
@@ -75,25 +75,24 @@ function getInstances(){
# param string name of the instance to load
function
loadInstance
(){
COUCHDB_URL
=
.
~/.iml_backup/couchdb/
${
1
}
.config
if
[
$?
-ne
0
]
;
then
if
!
.
"~/.iml_backup/couchdb/
${
1
}
.config"
;
then
color error
echo
ERROR: invalid instance:
$1
- the config file cannot be sourced
color reset
exit
1
fi
if
[
-z
${
COUCHDB_URL
}
]
;
then
if
[
-z
"
${
COUCHDB_URL
}
"
]
;
then
color error
echo
ERROR: invalid instance:
$1
- the config file has no COUCHDB_URL
echo
"
ERROR: invalid instance:
$1
- the config file has no COUCHDB_URL
"
color reset
exit
1
fi
# parse ${COUCHDB_URL} ...
couchdbhost
=
`
echo
${
COUCHDB_URL
}
|
cut
-f
3
-d
"/"
|
cut
-f
2
-d
"@"
|
cut
-f
1
-d
":"
`
couchdbport
=
`
echo
${
COUCHDB_URL
}
|
cut
-f
3
-d
"/"
|
cut
-f
2
-d
"@"
|
cut
-f
2
-d
":"
`
couchdbuser
=
`
echo
${
COUCHDB_URL
}
|
cut
-f
3
-d
"/"
|
cut
-f
1
-d
"@"
|
cut
-f
1
-d
":"
`
couchdbpw
=
`
echo
${
COUCHDB_URL
}
|
cut
-f
3
-d
"/"
|
cut
-f
1
-d
"@"
|
cut
-f
2
-d
":"
`
couchdbhost
=
$(
echo
"
${
COUCHDB_URL
}
"
|
cut
-f
3
-d
"/"
|
cut
-f
2
-d
"@"
|
cut
-f
1
-d
":"
)
couchdbport
=
$(
echo
"
${
COUCHDB_URL
}
"
|
cut
-f
3
-d
"/"
|
cut
-f
2
-d
"@"
|
cut
-f
2
-d
":"
)
couchdbuser
=
$(
echo
"
${
COUCHDB_URL
}
"
|
cut
-f
3
-d
"/"
|
cut
-f
1
-d
"@"
|
cut
-f
1
-d
":"
)
couchdbpw
=
$(
echo
"
${
COUCHDB_URL
}
"
|
cut
-f
3
-d
"/"
|
cut
-f
1
-d
"@"
|
cut
-f
2
-d
":"
)
}
...
...
@@ -103,14 +102,12 @@ function loadInstance(){
# backup with loop over instances
function
doBackup
(){
# for mycfg in `ls -1 ~/.iml_backup/couchdb/*.config`
for
COUCHDB_INSTANCE
in
`
getInstances
`
for
COUCHDB_INSTANCE
in
$(
getInstances
)
do
loadInstance
$COUCHDB_INSTANCE
loadInstance
"
$COUCHDB_INSTANCE
"
echo
---
instance:
$COUCHDB_INSTANCE
curl
--head
-X
GET
$COUCHDB_URL
2>/dev/null |
grep
"^HTTP.*
\
200
\
"
if
[
$?
-eq
0
]
;
then
echo
"--- instance:
$COUCHDB_INSTANCE
"
if
curl
--head
-X
GET
"
$COUCHDB_URL
"
2>/dev/null |
grep
"^HTTP.*
\
200
\
"
;
then
_doBackupOfSingleInstance
...
...
@@ -119,12 +116,12 @@ function doBackup(){
color error
echo
ERROR: couch DB instance is not available or canot be accessed with these credentials
in
config file
# repeat curl to show the error message
curl
-X
GET
$COUCHDB_URL
curl
-X
GET
"
$COUCHDB_URL
"
color reset
fi
echo
echo
---
`
date
`
done
.
echo
"
---
$(
date
)
done.
"
echo
done
}
...
...
@@ -135,29 +132,29 @@ function doBackup(){
function
_doBackupOfSingleInstance
(){
create_targetdir
mkdir
-p
${
BACKUP_TARGETDIR
}
/
${
COUCHDB_INSTANCE
}
2>/dev/null
mkdir
-p
"
${
BACKUP_TARGETDIR
}
/
${
COUCHDB_INSTANCE
}
"
2>/dev/null
echo
echo
" DUMP databases of instance
${
COUCHDB_INSTANCE
}
"
echo
" couchdbhost
$couchdbhost
on port
$couchdbport
with user
$couchdbuser
"
echo
for
dbname
in
`
_getDblist
`
for
dbname
in
$(
_getDblist
)
do
echo
-----
`
date
`
${
COUCHDB_INSTANCE
}
--
${
dbname
}
OUTFILE
=
${
BACKUP_TARGETDIR
}
/
${
COUCHDB_INSTANCE
}
/
`
get_outfile
${
dbname
}
`
.couchdbdump
python
${
dirPythonPackages
}
/couchdb/tools/dump.py
${
COUCHDB_URL
}
/
${
dbname
}
>
${
OUTFILE
}
echo
"
-----
$(
date
)
${
COUCHDB_INSTANCE
}
--
${
dbname
}
"
OUTFILE
=
${
BACKUP_TARGETDIR
}
/
${
COUCHDB_INSTANCE
}
/
$(
get_outfile
"
${
dbname
}
"
)
.couchdbdump
python
${
dirPythonPackages
}
/couchdb/tools/dump.py
"
${
COUCHDB_URL
}
/
${
dbname
}
"
>
"
${
OUTFILE
}
"
fetchrc
# $myrc is last returncode - set in fetchrc
if
[
$myrc
-eq
0
]
;
then
echo
-n
"gzip ... "
compress_file
$OUTFILE
compress_file
"
$OUTFILE
"
else
echo
"ERROR occured - no gzip"
fi
ls
-l
$OUTFILE
*
ls
-l
"
$OUTFILE
"
*
echo
done
...
...
@@ -173,10 +170,10 @@ function restoreByFile(){
echo
h2
"analyze dump
$sMyfile
"
COUCHDB_INSTANCE
=
`
echo
$sMyfile
|
sed
"s#
${
BACKUP_TARGETDIR
}
##g"
|
sed
"s#
\.
/##g"
|
sed
"s#^/##g"
|
cut
-f
1
-d
"/"
`
COUCHDB_INSTANCE
=
$(
echo
"
$sMyfile
"
|
sed
"s#
${
BACKUP_TARGETDIR
}
##g"
|
sed
"s#
\.
/##g"
|
sed
"s#^/##g"
|
cut
-f
1
-d
"/"
)
echo
"detected COUCHDB_INSTANCE : [
${
COUCHDB_INSTANCE
}
]"
if
[
-z
$sMyDb
]
;
then
sMyDb
=
`
guessDB
$sMyfile
`
if
[
-z
"
$sMyDb
"
]
;
then
sMyDb
=
$(
guessDB
"
$sMyfile
"
)
echo
"detected db schema from file: [
${
sMyDb
}
]"
else
echo
"db schema from param 2: [
${
sMyDb
}
]"
...
...
@@ -184,14 +181,13 @@ function restoreByFile(){
echo
loadInstance
$COUCHDB_INSTANCE
loadInstance
"
$COUCHDB_INSTANCE
"
echo
connect
$couchdbhost
on port
$couchdbport
with user
$couchdbuser
curl
--head
-X
GET
$COUCHDB_URL
2>/dev/null |
grep
"^HTTP.*
\
200
\
"
>
/dev/null
if
[
$?
-ne
0
]
;
then
echo
"connect
$couchdbhost
on port
$couchdbport
with user
$couchdbuser
"
if
!
curl
--head
-X
GET
"
$COUCHDB_URL
"
2>/dev/null |
grep
"^HTTP.*
\
200
\
"
>
/dev/null
;
then
color error
echo
ERROR: couch DB instance is not available
curl
-X
GET
$COUCHDB_URL
curl
-X
GET
"
$COUCHDB_URL
"
color reset
exit
1
fi
...
...
@@ -207,21 +203,21 @@ function restoreByFile(){
# echo DB exists ... need to drop it first
# fi
h2 deleting database
[
$sMyDb
]
...
h2
"
deleting database [
$sMyDb
] ...
"
color cmd
_couchapi DELETE
$sMyDb
_couchapi DELETE
"
$sMyDb
"
fetchrc
color reset
h2 creating database
[
$sMyDb
]
...
h2
"
creating database [
$sMyDb
] ...
"
color cmd
_couchapi PUT
$sMyDb
_couchapi PUT
"
$sMyDb
"
fetchrc
color reset
h2 import file ...
color cmd
zcat
${
sMyfile
}
| python
${
dirPythonPackages
}
/couchdb/tools/load.py
$COUCHDB_URL
/
$sMyDb
zcat
"
${
sMyfile
}
"
| python
${
dirPythonPackages
}
/couchdb/tools/load.py
"
$COUCHDB_URL
/
$sMyDb
"
fetchrc
color reset
echo
...
...
@@ -276,6 +272,6 @@ else
fi
echo
$0
$*
[
couchdb] final returncode
rc
=
$rc
echo
"
$0
$*
[couchdb] final returncode rc=
$rc
"
# --------------------------------------------------------------------------------
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