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
174b597c
Commit
174b597c
authored
3 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
disconnect after 21:00 and before 05:00
parent
198738d8
No related branches found
No related tags found
1 merge request
!151
pg backup: disconnect after 21:00 and before 05:00
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
plugins/localdump/pgsql.sh
+22
-1
22 additions, 1 deletion
plugins/localdump/pgsql.sh
with
22 additions
and
1 deletion
plugins/localdump/pgsql.sh
+
22
−
1
View file @
174b597c
...
...
@@ -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
...
...
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