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
5db6976a
Commit
5db6976a
authored
2 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
pg_dump in temp dir to harden backup directory
parent
3fb73b6c
Branches
Branches containing commit
No related tags found
1 merge request
!154
pg_dump in temp dir to harden backup directory
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
plugins/localdump/pgsql.sh
+12
-7
12 additions, 7 deletions
plugins/localdump/pgsql.sh
with
12 additions
and
7 deletions
plugins/localdump/pgsql.sh
+
12
−
7
View file @
5db6976a
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
# ================================================================================
# ================================================================================
#
#
# LOCALDUMP :: POSTGRES
# LOCALDUMP :: POSTGRES
#
c
reate gzipped plain text backups from each scheme
#
C
reate gzipped plain text backups from each scheme
#
#
# --------------------------------------------------------------------------------
# --------------------------------------------------------------------------------
# ah - Axel Hahn <axel.hahn@iml.unibe.ch>
# ah - Axel Hahn <axel.hahn@iml.unibe.ch>
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
# 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
# 2024-12-17 ah v1.8 handle env variables to disable snapshots or set times for disconnect
# 2025-02-03 ah v1.9 pg_dump in temp directory; dump file will be moved to backup dir
# ================================================================================
# ================================================================================
if
[
-z
"
$BACKUP_TARGETDIR
"
]
;
then
if
[
-z
"
$BACKUP_TARGETDIR
"
]
;
then
...
@@ -65,9 +66,6 @@ function pgsql.backup(){
...
@@ -65,9 +66,6 @@ function pgsql.backup(){
create_targetdir
create_targetdir
# ----- change owner of directory because of su command
chown
${
PGUSER
}
.
"
${
BACKUP_TARGETDIR
}
"
# ----- GO
# ----- GO
# prevent could not change directory to "/root": Permission denied
# prevent could not change directory to "/root": Permission denied
...
@@ -112,12 +110,13 @@ function pgsql.backup(){
...
@@ -112,12 +110,13 @@ function pgsql.backup(){
test
$bUseSnapshot4DB
-eq
1
&&
SNAPSHOTDB
=
"
${
snapshotprefix
}${
DATABASE
}
"
test
$bUseSnapshot4DB
-eq
1
&&
SNAPSHOTDB
=
"
${
snapshotprefix
}${
DATABASE
}
"
OUTFILE
=
"
${
BACKUP_TARGETDIR
}
/
$(
get_outfile
${
DATABASE
}
)
.sql"
OUTFILE
=
"
${
BACKUP_TARGETDIR
}
/
$(
get_outfile
${
DATABASE
}
)
.sql"
TMPOUTFILE
=
"/tmp/
$(
get_outfile
${
DATABASE
}
)
.sql"
myrc
=
0
myrc
=
0
# drop snapshot db first - just in case
# drop snapshot db first - just in case
if
[
$bUseSnapshot4DB
-eq
1
]
;
then
if
[
$bUseSnapshot4DB
-eq
1
]
;
then
echo
-n
"
snapshot ."
echo
-n
"snapshot ."
su
${
PGUSER
}
-c
"dropdb
${
SNAPSHOTDB
}
"
>
/dev/null 2>&1
su
${
PGUSER
}
-c
"dropdb
${
SNAPSHOTDB
}
"
>
/dev/null 2>&1
echo
-n
"."
echo
-n
"."
test
$bDisconnect
-ne
0
&&
su
${
PGUSER
}
-c
"psql
${
BACKUP_PARAMS
}
-c
\"
test
$bDisconnect
-ne
0
&&
su
${
PGUSER
}
-c
"psql
${
BACKUP_PARAMS
}
-c
\"
...
@@ -137,14 +136,20 @@ function pgsql.backup(){
...
@@ -137,14 +136,20 @@ function pgsql.backup(){
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
}
>
$
TMP
OUTFILE
"
;
then
fetchrc
>
/dev/null
fetchrc
>
/dev/null
test
$bUseSnapshot4DB
-eq
1
&&
(
test
$bUseSnapshot4DB
-eq
1
&&
(
echo
-n
"delete snapshot ... "
echo
-n
"delete snapshot ... "
su
${
PGUSER
}
-c
"dropdb
${
SNAPSHOTDB
}
"
su
${
PGUSER
}
-c
"dropdb
${
SNAPSHOTDB
}
"
)
)
db._compressDumpfile
"
$OUTFILE
"
echo
-n
"move temp to target ... "
if
mv
"
$TMPOUTFILE
"
"
$OUTFILE
"
;
then
db._compressDumpfile
"
$OUTFILE
"
else
fetchrc
cecho error
"Failed."
fi
else
else
fetchrc
fetchrc
test
$bUseSnapshot4DB
-eq
1
&&
su
${
PGUSER
}
-c
"dropdb
${
SNAPSHOTDB
}
"
test
$bUseSnapshot4DB
-eq
1
&&
su
${
PGUSER
}
-c
"dropdb
${
SNAPSHOTDB
}
"
...
...
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