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
068e354d
Commit
068e354d
authored
3 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
pgsql: fixes with shellcheck
parent
acbce830
Branches
Branches containing commit
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/pgsql.sh
+22
-18
22 additions, 18 deletions
plugins/localdump/pgsql.sh
with
22 additions
and
18 deletions
plugins/localdump/pgsql.sh
+
22
−
18
View file @
068e354d
#!/bin/bash
#!/bin/bash
# ================================================================================ # # LOCALDUMP :: POSTGRES
# ================================================================================
#
# LOCALDUMP :: POSTGRES
# create gzipped plain text backups from each scheme
# create gzipped plain text backups from each scheme
#
#
# --------------------------------------------------------------------------------
# --------------------------------------------------------------------------------
...
@@ -8,12 +10,14 @@
...
@@ -8,12 +10,14 @@
#
#
# 2016-11-10 ah,ds v1.0
# 2016-11-10 ah,ds v1.0
# 2017-03-29 ..... v1.1 added restore
# 2017-03-29 ..... v1.1 added restore
# 2022-01-20 v1.2 fixes with shellcheck
# ================================================================================
# ================================================================================
if
[
-z
$BACKUP_TARGETDIR
]
;
then
if
[
-z
"
$BACKUP_TARGETDIR
"
]
;
then
echo
ERROR: you cannot start
`
basename
$0
`
directly
echo
"ERROR: you cannot start
$(
basename
$0
)
directly"
exit
1
rc
=
$rc
+1
fi
exit
1
fi
# --------------------------------------------------------------------------------
# --------------------------------------------------------------------------------
# CONFIG
# CONFIG
...
@@ -32,29 +36,29 @@ function doPgsqlBackup(){
...
@@ -32,29 +36,29 @@ function doPgsqlBackup(){
create_targetdir
create_targetdir
# ----- change owner of directory because of su command
# ----- change owner of directory because of su command
chown
${
PGUSER
}
.
${
BACKUP_TARGETDIR
}
chown
${
PGUSER
}
.
"
${
BACKUP_TARGETDIR
}
"
# ----- GO
# ----- GO
sSqlGetDblist
=
"select datname from pg_database where not datistemplate and datallowconn order by datname;"
sSqlGetDblist
=
"select datname from pg_database where not datistemplate and datallowconn order by datname;"
for
DATABASE
in
`
su
${
PGUSER
}
-c
"psql -At -c '
$sSqlGetDblist
' postgres"
2>/dev/null
`
for
DATABASE
in
$(
su
${
PGUSER
}
-c
"psql -At -c '
$sSqlGetDblist
' postgres"
2>/dev/null
)
do
do
echo
"-----
$DATABASE
"
echo
"-----
$DATABASE
"
echo
-n
"backup ... "
echo
-n
"backup ... "
OUTFILE
=
${
BACKUP_TARGETDIR
}
/
`
get_outfile
${
DATABASE
}
`
.sql
OUTFILE
=
"
${
BACKUP_TARGETDIR
}
/
$(
get_outfile
${
DATABASE
}
)
.sql
"
su
${
PGUSER
}
-c
"pg_dump -Fp
${
DATABASE
}
>
$OUTFILE
"
su
${
PGUSER
}
-c
"pg_dump -Fp
${
DATABASE
}
>
$OUTFILE
"
fetchrc
fetchrc
if
[
$myrc
-eq
0
]
;
then
if
[
$myrc
-eq
0
]
;
then
echo
-n
"compress ... "
echo
-n
"compress ... "
compress_file
$OUTFILE
compress_file
"
$OUTFILE
"
else
else
color error
color error
echo
"ERROR occured - no gzip"
echo
"ERROR occured - no gzip"
color reset
color reset
# mv $OUTFILE $OUTFILE
# mv $OUTFILE $OUTFILE
fi
fi
ls
-l
$OUTFILE
*
ls
-l
"
$OUTFILE
"
*
echo
echo
done
done
}
}
...
@@ -67,9 +71,9 @@ function restoreByFile(){
...
@@ -67,9 +71,9 @@ function restoreByFile(){
sMyfile
=
$1
sMyfile
=
$1
sMyDb
=
$2
sMyDb
=
$2
if
[
-z
$sMyDb
]
;
then
if
[
-z
"
$sMyDb
"
]
;
then
h2
"analyze dump
$sMyfile
"
h2
"analyze dump
$sMyfile
"
sMyDb
=
`
guessDB
$sMyfile
`
sMyDb
=
"
$(
guessDB
"
$sMyfile
"
)
"
echo
"detected db schema from file: [
${
sMyDb
}
]"
echo
"detected db schema from file: [
${
sMyDb
}
]"
else
else
echo
"db schema from param 2: [
${
sMyDb
}
]"
echo
"db schema from param 2: [
${
sMyDb
}
]"
...
@@ -77,22 +81,22 @@ function restoreByFile(){
...
@@ -77,22 +81,22 @@ function restoreByFile(){
echo
echo
echo
import to
$sMyDb
...
echo
import to
"
$sMyDb
"
...
h2 deleting database
[
$sMyDb
]
...
h2
"
deleting database [
$sMyDb
] ...
"
color cmd
color cmd
su
${
PGUSER
}
-c
"dropdb
${
sMyDb
}
"
su
${
PGUSER
}
-c
"dropdb
${
sMyDb
}
"
color reset
color reset
h2 ensure that database exists ...
h2
"
ensure that database exists ...
"
color cmd
color cmd
su
${
PGUSER
}
-c
"psql -c
\"
CREATE DATABASE
${
sMyDb
}
;
\"
"
su
${
PGUSER
}
-c
"psql -c
\"
CREATE DATABASE
${
sMyDb
}
;
\"
"
fetchrc
fetchrc
color reset
color reset
h2 import ...
h2
"
import ...
"
ls
-l
"
${
sMyfile
}
"
ls
-l
"
${
sMyfile
}
"
echo
import to database
[
${
sMyDb
}
]
echo
"
import to database [
${
sMyDb
}
]
"
color cmd
color cmd
zcat
"
${
sMyfile
}
"
| su
${
PGUSER
}
-c
"psql -d
${
sMyDb
}
"
zcat
"
${
sMyfile
}
"
| su
${
PGUSER
}
-c
"psql -d
${
sMyDb
}
"
fetchrc
fetchrc
...
@@ -123,6 +127,6 @@ function restoreByFile(){
...
@@ -123,6 +127,6 @@ function restoreByFile(){
fi
fi
echo
$0
$*
[
postgres] final returncode
rc
=
$rc
echo
"
$0
$*
[postgres] 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