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
Merge requests
!151
pg backup: disconnect after 21:00 and before 05:00
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
pg backup: disconnect after 21:00 and before 05:00
pgsql-snapshot-fallback
into
master
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
Hahn Axel (hahn)
requested to merge
pgsql-snapshot-fallback
into
master
4 months ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
174b597c
1 commit,
4 months ago
1 file
+
22
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
plugins/localdump/pgsql.sh
+
22
−
1
Options
@@ -45,8 +45,12 @@ function pgsql.backup(){
local
snapshotprefix
=
"snapshot_"
local
bUseSnapshot
local
bUseSnapshot4DB
local
bDisconnect
local
iHour
;
typeset
-i
bUseSnapshot
=
0
typeset
-i
bDisconnect
=
0
typeset
-i
iHour
;
iHour
=
$(
date
+%H
)
create_targetdir
@@ -70,6 +74,14 @@ function pgsql.backup(){
echo
"INFO: create database failed for snapshots - dumping databases directly"
fi
# disconnect after 21:00 and before 05:00
if
[
$bUseSnapshot
-eq
1
]
;
then
if
[
$iHour
-ge
21
]
||
[
$iHour
-lt
5
]
;
then
echo
"INFO: clients will be disconnected for snapshot database creation"
bDisconnect
=
1
fi
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
@@ -86,13 +98,22 @@ function pgsql.backup(){
# drop snapshot db first - just in case
if
[
$bUseSnapshot4DB
-eq
1
]
;
then
echo
-n
" snapshot .
..
"
echo
-n
" snapshot ."
su
${
PGUSER
}
-c
"dropdb
${
SNAPSHOTDB
}
"
>
/dev/null 2>&1
echo
-n
"."
test
$bDisconnect
-ne
0
&&
su
${
PGUSER
}
-c
"psql
${
BACKUP_PARAMS
}
-c
\"
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = '
${
DATABASE
}
'
AND pid <> pg_backend_pid();
\"
"
>
/dev/null
echo
-n
"."
if
!
su
${
PGUSER
}
-c
"psql
${
BACKUP_PARAMS
}
-c
\"
CREATE DATABASE
${
SNAPSHOTDB
}
WITH TEMPLATE
${
DATABASE
}
;
\"
"
>
/dev/null
;
then
echo
-n
"Fallback using origin ... "
bUseSnapshot4DB
=
0
SNAPSHOTDB
=
"
${
DATABASE
}
"
fi
echo
-n
" "
fi
if
[
$myrc
-eq
0
]
;
then
Loading