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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
iml-backup
Commits
0cfba9a5
Commit
0cfba9a5
authored
7 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
postgres - detect readonly instance
parent
d6a02e85
No related branches found
No related tags found
1 merge request
!148
postgres - detect readonly instance
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
plugins/localdump/pgsql.sh
+52
-28
52 additions, 28 deletions
plugins/localdump/pgsql.sh
with
52 additions
and
28 deletions
plugins/localdump/pgsql.sh
+
52
−
28
View file @
0cfba9a5
...
@@ -42,6 +42,21 @@ function pgsql.backup(){
...
@@ -42,6 +42,21 @@ function pgsql.backup(){
local
SNAPSHOTDB
local
SNAPSHOTDB
local
OUTFILE
local
OUTFILE
local
snapshotprefix
=
"snapshot_"
local
snapshotprefix
=
"snapshot_"
local
bUseSnapshot
typeset
-i
bUseSnapshot
=
0
# Detect a readonly or writeable postgres host.
TESTDB
=
"imlbackup_createtest"
su
${
PGUSER
}
-c
"dropdb
${
TESTDB
}
"
>
/dev/null 2>&1
if
su
${
PGUSER
}
-c
"psql
${
BACKUP_PARAMS
}
-c
\"
CREATE DATABASE
${
TESTDB
}
;
\"
"
>
/dev/null 2>&1
then
bUseSnapshot
=
1
su
${
PGUSER
}
-c
"dropdb
${
TESTDB
}
"
echo
"INFO: enabling snapshots"
else
echo
"INFO: create database failed for snapshots - dumping databases directly"
fi
create_targetdir
create_targetdir
...
@@ -58,26 +73,35 @@ function pgsql.backup(){
...
@@ -58,26 +73,35 @@ function pgsql.backup(){
for
DATABASE
in
$(
su
${
PGUSER
}
-c
"psql
${
BACKUP_PARAMS
}
-At -c '
$sSqlGetDblist
' postgres"
2>/dev/null |
grep
-v
"^
$snapshotprefix
"
)
for
DATABASE
in
$(
su
${
PGUSER
}
-c
"psql
${
BACKUP_PARAMS
}
-At -c '
$sSqlGetDblist
' postgres"
2>/dev/null |
grep
-v
"^
$snapshotprefix
"
)
do
do
echo
-n
"__DB__
${
SERVICENAME
}
backup
$DATABASE
... "
echo
-n
"__DB__
${
SERVICENAME
}
backup
$DATABASE
... "
SNAPSHOTDB
=
"
${
snapshotprefix
}${
DATABASE
}
"
SNAPSHOTDB
=
"
${
DATABASE
}
"
test
$bUseSnapshot
-eq
1
&&
SNAPSHOTDB
=
"
${
snapshotprefix
}${
DATABASE
}
"
OUTFILE
=
"
${
BACKUP_TARGETDIR
}
/
$(
get_outfile
${
DATABASE
}
)
.sql"
OUTFILE
=
"
${
BACKUP_TARGETDIR
}
/
$(
get_outfile
${
DATABASE
}
)
.sql"
echo
-n
" snapshot ... "
myrc
=
0
# drop snapshot db first - just in case
# drop snapshot db first - just in case
test
$bUseSnapshot
-eq
1
&&
(
echo
-n
" snapshot ... "
su
${
PGUSER
}
-c
"dropdb
${
SNAPSHOTDB
}
"
>
/dev/null 2>&1
su
${
PGUSER
}
-c
"dropdb
${
SNAPSHOTDB
}
"
>
/dev/null 2>&1
su
${
PGUSER
}
-c
"psql
${
BACKUP_PARAMS
}
-c
\"
CREATE DATABASE
${
SNAPSHOTDB
}
WITH TEMPLATE
${
DATABASE
}
;
\"
"
>
/dev/null
su
${
PGUSER
}
-c
"psql
${
BACKUP_PARAMS
}
-c
\"
CREATE DATABASE
${
SNAPSHOTDB
}
WITH TEMPLATE
${
DATABASE
}
;
\"
"
>
/dev/null
fetchrc
>
/dev/null
fetchrc
>
/dev/null
)
if
[
$myrc
-eq
0
]
;
then
if
[
$myrc
-eq
0
]
;
then
echo
-n
"backup ... "
echo
-n
"backup ... "
if
su
${
PGUSER
}
-c
"pg_dump
${
BACKUP_PARAMS
}
-Fp
${
SNAPSHOTDB
}
>
$OUTFILE
"
;
then
if
su
${
PGUSER
}
-c
"pg_dump
${
BACKUP_PARAMS
}
-Fp
${
SNAPSHOTDB
}
>
$OUTFILE
"
;
then
fetchrc
>
/dev/null
fetchrc
>
/dev/null
test
$bUseSnapshot
-eq
1
&&
(
echo
-n
"delete snapshot ... "
echo
-n
"delete snapshot ... "
su
${
PGUSER
}
-c
"dropdb
${
SNAPSHOTDB
}
"
su
${
PGUSER
}
-c
"dropdb
${
SNAPSHOTDB
}
"
)
db._compressDumpfile
"
$OUTFILE
"
db._compressDumpfile
"
$OUTFILE
"
else
else
fetchrc
fetchrc
su
${
PGUSER
}
-c
"dropdb
${
SNAPSHOTDB
}
"
test
$bUseSnapshot
-eq
1
&&
su
${
PGUSER
}
-c
"dropdb
${
SNAPSHOTDB
}
"
fi
fi
else
else
cecho error
"ERROR!"
cecho error
"ERROR!"
...
...
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