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
b2ce0c42
Commit
b2ce0c42
authored
6 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
pgsql handle env variables to disable snapshots or set times for disconnect
parent
174b597c
No related branches found
No related tags found
1 merge request
!152
Pgsql env variables to configure snapshot
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
plugins/localdump/pgsql.sh
+36
-17
36 additions, 17 deletions
plugins/localdump/pgsql.sh
with
36 additions
and
17 deletions
plugins/localdump/pgsql.sh
+
36
−
17
View file @
b2ce0c42
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
# 2024-10-02 ah v1.5 rename backup and restore function
# 2024-10-02 ah v1.5 rename backup and restore function
# 2024-12-13 ah v1.6 backup uses a snapshot db
# 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
# 2024-12-16 ah v1.7 on snapshot mode it can fallback for single database to normal pg_dump of origin
# 2024-12-17 ah v1.8 handle env variables to disable snapshots or set times for disconnect
# ================================================================================
# ================================================================================
if
[
-z
"
$BACKUP_TARGETDIR
"
]
;
then
if
[
-z
"
$BACKUP_TARGETDIR
"
]
;
then
...
@@ -46,11 +47,21 @@ function pgsql.backup(){
...
@@ -46,11 +47,21 @@ function pgsql.backup(){
local
bUseSnapshot
local
bUseSnapshot
local
bUseSnapshot4DB
local
bUseSnapshot4DB
local
bDisconnect
local
bDisconnect
local
iHour
;
local
mytime
typeset
-i
bUseSnapshot
=
0
typeset
-i
bUseSnapshot
=
0
typeset
-i
bDisconnect
=
0
typeset
-i
bDisconnect
=
0
typeset
-i
iHour
;
iHour
=
$(
date
+%H
)
# handle config from jobs/env
LD_PGSQL_SNAPSHOTS
=
"
${
LD_PGSQL_SNAPSHOTS
:-
1
}
"
LD_PGSQL_DISCONNECT_BEFORE
=
"
${
LD_PGSQL_DISCONNECT_BEFORE
:-
00
:00
}
"
LD_PGSQL_DISCONNECT_AFTER
=
"
${
LD_PGSQL_DISCONNECT_AFTER
:-
24
:00
}
"
echo
"
${
LD_PGSQL_DISCONNECT_BEFORE
}
_
${
LD_PGSQL_DISCONNECT_AFTER
}
"
\
|
grep
-q
"[0-2][0-9]:[0-5][0-9]_[0-2][0-9]:[0-5][0-9]"
\
||
echo
"ERROR: LD_PGSQL_DISCONNECT_BEFORE and LD_PGSQL_DISCONNECT_AFTER must be in the format HH:MM"
mytime
=
"
$(
date
+%H:%M
)
"
create_targetdir
create_targetdir
...
@@ -60,8 +71,13 @@ function pgsql.backup(){
...
@@ -60,8 +71,13 @@ function pgsql.backup(){
# ----- GO
# ----- GO
# prevent could not change directory to "/root": Permission denied
# prevent could not change directory to "/root": Permission denied
cd
/tmp
cd
/tmp
||
exit
# Enable snapshots?
if
[
"
$LD_PGSQL_SNAPSHOTS
"
=
"0"
]
;
then
echo
"INFO: Snapshots disabled by LD_PGSQL_SNAPSHOTS=0"
bUseSnapshot
=
0
else
# Detect a readonly or writeable postgres host.
# Detect a readonly or writeable postgres host.
TESTDB
=
"imlbackup_createtest"
TESTDB
=
"imlbackup_createtest"
su
${
PGUSER
}
-c
"dropdb
${
TESTDB
}
"
>
/dev/null 2>&1
su
${
PGUSER
}
-c
"dropdb
${
TESTDB
}
"
>
/dev/null 2>&1
...
@@ -73,12 +89,15 @@ function pgsql.backup(){
...
@@ -73,12 +89,15 @@ function pgsql.backup(){
else
else
echo
"INFO: create database failed for snapshots - dumping databases directly"
echo
"INFO: create database failed for snapshots - dumping databases directly"
fi
fi
fi
# disconnect
after 21:00 and before 05:00
#
enable
disconnect
?
if
[
$bUseSnapshot
-eq
1
]
;
then
if
[
$bUseSnapshot
-eq
1
]
;
then
if
[
$iHour
-ge
21
]
||
[
$iHour
-lt
5
]
;
then
if
[
"
$mytime
"
\<
"
$LD_PGSQL_DISCONNECT_BEFORE
"
]
||
[
"
$mytime
"
\>
"
$LD_PGSQL_DISCONNECT_AFTER
"
]
;
then
echo
"INFO: clients will be disconnected for snapshot database creation"
echo
"INFO: clients will be disconnected for snapshot database creation
.
"
bDisconnect
=
1
bDisconnect
=
1
else
echo
"INFO: clients will NOT be disconnected for snapshot database creation - which may fail then."
fi
fi
fi
fi
...
...
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