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
468cadb7
Commit
468cadb7
authored
3 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
on snapshot mode it can fallback for single database to normal pg_dump of origin
parent
d22505cd
No related branches found
No related tags found
1 merge request
!149
on snapshot mode it can fallback for single database to normal pg_dump of origin
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
plugins/localdump/pgsql.sh
+26
-34
26 additions, 34 deletions
plugins/localdump/pgsql.sh
with
26 additions
and
34 deletions
plugins/localdump/pgsql.sh
+
26
−
34
View file @
468cadb7
...
...
@@ -15,6 +15,7 @@
# 2023-09-20 v1.4 FIX could not change directory to "/root": Permission denied
# 2024-10-02 ah v1.5 rename backup and restore function
# 2024-12-13 ah v1.6 backup uses a snapshot db
# 2024-12-16 ah v1.7 on snapshot mode it can fallback for single database to normal pg_dump of origin
# ================================================================================
if
[
-z
"
$BACKUP_TARGETDIR
"
]
;
then
...
...
@@ -43,21 +44,10 @@ function pgsql.backup(){
local
OUTFILE
local
snapshotprefix
=
"snapshot_"
local
bUseSnapshot
local
bUseSnapshot4DB
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
# ----- change owner of directory because of su command
...
...
@@ -69,31 +59,48 @@ function pgsql.backup(){
(
cd
/tmp
# 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
sSqlGetDblist
=
"select datname from pg_database where not datistemplate and datallowconn order by datname;"
for
DATABASE
in
$(
su
${
PGUSER
}
-c
"psql
${
BACKUP_PARAMS
}
-At -c '
$sSqlGetDblist
' postgres"
2>/dev/null |
grep
-v
"^
$snapshotprefix
"
)
do
echo
-n
"__DB__
${
SERVICENAME
}
backup
$DATABASE
... "
bUseSnapshot4DB
=
$bUseSnapshot
SNAPSHOTDB
=
"
${
DATABASE
}
"
test
$bUseSnapshot
-eq
1
&&
SNAPSHOTDB
=
"
${
snapshotprefix
}${
DATABASE
}
"
test
$bUseSnapshot
4DB
-eq
1
&&
SNAPSHOTDB
=
"
${
snapshotprefix
}${
DATABASE
}
"
OUTFILE
=
"
${
BACKUP_TARGETDIR
}
/
$(
get_outfile
${
DATABASE
}
)
.sql"
myrc
=
0
# drop snapshot db first - just in case
test
$bUseSnapshot
-eq
1
&&
(
if
[
$bUseSnapshot
4DB
-eq
1
]
;
then
echo
-n
" snapshot ... "
su
${
PGUSER
}
-c
"dropdb
${
SNAPSHOTDB
}
"
>
/dev/null 2>&1
su
${
PGUSER
}
-c
"psql
${
BACKUP_PARAMS
}
-c
\"
CREATE DATABASE
${
SNAPSHOTDB
}
WITH TEMPLATE
${
DATABASE
}
;
\"
"
>
/dev/null
fetchrc
>
/dev/null
)
if
!
su
${
PGUSER
}
-c
"psql
${
BACKUP_PARAMS
}
-c
\"
CREATE DATABASE
${
SNAPSHOTDB
}
WITH TEMPLATE
${
DATABASE
}
;
\"
"
>
/dev/null 2>&1
;
then
echo
-n
" nope, using origin ... "
bUseSnapshot4DB
=
0
SNAPSHOTDB
=
"
${
DATABASE
}
"
fi
fi
if
[
$myrc
-eq
0
]
;
then
echo
-n
"backup ... "
if
su
${
PGUSER
}
-c
"pg_dump
${
BACKUP_PARAMS
}
-Fp
${
SNAPSHOTDB
}
>
$OUTFILE
"
;
then
fetchrc
>
/dev/null
test
$bUseSnapshot
-eq
1
&&
(
test
$bUseSnapshot
4DB
-eq
1
&&
(
echo
-n
"delete snapshot ... "
su
${
PGUSER
}
-c
"dropdb
${
SNAPSHOTDB
}
"
)
...
...
@@ -101,7 +108,7 @@ function pgsql.backup(){
db._compressDumpfile
"
$OUTFILE
"
else
fetchrc
test
$bUseSnapshot
-eq
1
&&
su
${
PGUSER
}
-c
"dropdb
${
SNAPSHOTDB
}
"
test
$bUseSnapshot
4DB
-eq
1
&&
su
${
PGUSER
}
-c
"dropdb
${
SNAPSHOTDB
}
"
fi
else
cecho error
"ERROR!"
...
...
@@ -172,21 +179,6 @@ else
fi
# case $1 in
# backup)
# test $SERVICEFOUND -eq 1 && pgsql.backup
# ;;
# restore)
# shift 1
# test $SERVICEFOUND -eq 1 && pgsql.restore $*
# ;;
# *)
# echo ERROR: wrong syntax:
# echo $0 $*
# exit 1
# esac
echo
"__DB__
$SERVICENAME
INFO:
$0
$*
[
$SERVICENAME
] 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