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
077f1f12
Commit
077f1f12
authored
1 month ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
suport backup of single database or given databases
parent
9e4d7848
Branches
Branches containing commit
No related tags found
1 merge request
!156
support backup of single database or given databases
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
localdump.sh
+24
-9
24 additions, 9 deletions
localdump.sh
plugins/localdump/pgsql.sh
+16
-3
16 additions, 3 deletions
plugins/localdump/pgsql.sh
with
40 additions
and
12 deletions
localdump.sh
+
24
−
9
View file @
077f1f12
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
# 2024-03-18 ah fix for db detection from file and cli restore
# 2024-03-18 ah fix for db detection from file and cli restore
# 2024-10-02 ah reset $rc before calling db plugin
# 2024-10-02 ah reset $rc before calling db plugin
# 2024-12-13 ah set gzip compression from 9 to 4
# 2024-12-13 ah set gzip compression from 9 to 4
# 2025-05-01 ah suport backup of single database or given databases
# ======================================================================
# ======================================================================
# --- variables:
# --- variables:
...
@@ -341,9 +342,10 @@ OPTIONS:
...
@@ -341,9 +342,10 @@ OPTIONS:
-h|--help show this help
-h|--help show this help
PARAMETERS:"
PARAMETERS:"
operation - one of
check|
backup|restore; optional parameter
operation - one of backup
|check
|restore; optional parameter
backup dump all databases/ schemes of a given service
backup dump all databases/ schemes of a given service
check show info only if the service is available
check show info only if the service is available
check show info only if the service is available
restore import a dump into same or new database
restore import a dump into same or new database
Without a filename it starts an interactive mode
Without a filename it starts an interactive mode
profile - name of database profiles
profile - name of database profiles
...
@@ -354,17 +356,23 @@ PARAMETERS:"
...
@@ -354,17 +356,23 @@ PARAMETERS:"
EXAMPLES:
EXAMPLES:
$_self
backup
$_self
backup
$_self
backup ALL
$_self
backup ALL
Backup all databases of all found services
Backup all databases of all found services
$_self
backup mysql
$_self
backup mysql
Backup all Mysql databases.
Backup all Mysql databases.
$_self
backup mysql wordpress
Backup all Mysql database "wordpress" only
$_self
check
Show debug info of profile detection for avalable databases
$_self
restore
$_self
restore
Start interactive restore of a database of any service.
Start interactive restore of a database of any service.
$_self
restore sqlite
$_self
restore sqlite
Start interactive restore of an sqlite database.
Start interactive restore of an sqlite database.
$_self
restore <file-to-restore> [<database-name>]
$_self
restore <file-to-restore> [<database-name>]
Restore a given dump file to the origin database scheme or
Restore a given dump file to the origin database scheme or
to a new/ other database with the given name.
to a new/ other database with the given name.
EOH
EOH
}
}
...
@@ -494,8 +502,10 @@ EOH
...
@@ -494,8 +502,10 @@ EOH
h3
"BACKUP [
${
PROFILENAME
}
] ->
${
SERVICENAME
}
"
h3
"BACKUP [
${
PROFILENAME
}
] ->
${
SERVICENAME
}
"
rcbak
=
$rc
rcbak
=
$rc
rc
=
0
rc
=
0
.
$BACKUP_SCRIPT
$mode
databaselist
=
"
$(
sed
"s#^
$SERVICENAME
##"
<<<
$*
)
"
.
$BACKUP_SCRIPT
$mode
$databaselist
test
$rc
-gt
0
&&
j_notify
"db
${
SERVICENAME
}
"
"
$BACKUP_SCRIPT
$mode
was finished with rc=
$rc
"
$rc
test
$rc
-gt
0
&&
j_notify
"db
${
SERVICENAME
}
"
"
$BACKUP_SCRIPT
$mode
was finished with rc=
$rc
"
$rc
_j_runHooks
"230-after-db-service"
"
$rc
"
_j_runHooks
"230-after-db-service"
"
$rc
"
...
@@ -507,6 +517,11 @@ EOH
...
@@ -507,6 +517,11 @@ EOH
show_info_backup_target
show_info_backup_target
rc
=
$rc
+
$rcbak
rc
=
$rc
+
$rcbak
if
grep
-q
"."
<<<
"
$databaselist
"
;
then
echo
"Stopping here after handling
$SERVICENAME
and do not process other profiles."
break
fi
else
else
...
...
This diff is collapsed.
Click to expand it.
plugins/localdump/pgsql.sh
+
16
−
3
View file @
077f1f12
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
# 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
# 2025-02-03 ah v1.9 pg_dump in temp directory; dump file will be moved to backup dir
# 2025-05-01 ah v1.10 suport backup of single database or given databases
# ================================================================================
# ================================================================================
if
[
-z
"
$BACKUP_TARGETDIR
"
]
;
then
if
[
-z
"
$BACKUP_TARGETDIR
"
]
;
then
...
@@ -38,6 +39,12 @@ fi
...
@@ -38,6 +39,12 @@ fi
# FUNCTION
# FUNCTION
# --------------------------------------------------------------------------------
# --------------------------------------------------------------------------------
# get a list of existing databases
function
pgsql.list
(){
sSqlGetDblist
=
"select datname from pg_database where not datistemplate and datallowconn order by datname;"
su
${
PGUSER
}
-c
"psql
${
BACKUP_PARAMS
}
-At -c '
$sSqlGetDblist
' postgres"
2>/dev/null |
grep
-v
"^
$snapshotprefix
"
}
# backup all databases
# backup all databases
function
pgsql.backup
(){
function
pgsql.backup
(){
...
@@ -77,7 +84,7 @@ function pgsql.backup(){
...
@@ -77,7 +84,7 @@ function pgsql.backup(){
bUseSnapshot
=
0
bUseSnapshot
=
0
else
else
# Detect a readonly or writeable postgres host.
# Detect a readonly or writeable postgres host.
TESTDB
=
"imlbackup_createtest"
TESTDB
=
"imlbackup_createtest
_
${
snapshotprefix
}
"
su
${
PGUSER
}
-c
"dropdb
${
TESTDB
}
"
>
/dev/null 2>&1
su
${
PGUSER
}
-c
"dropdb
${
TESTDB
}
"
>
/dev/null 2>&1
if
su
${
PGUSER
}
-c
"psql
${
BACKUP_PARAMS
}
-c
\"
CREATE DATABASE
${
TESTDB
}
;
\"
"
>
/dev/null 2>&1
if
su
${
PGUSER
}
-c
"psql
${
BACKUP_PARAMS
}
-c
\"
CREATE DATABASE
${
TESTDB
}
;
\"
"
>
/dev/null 2>&1
then
then
...
@@ -99,8 +106,14 @@ function pgsql.backup(){
...
@@ -99,8 +106,14 @@ function pgsql.backup(){
fi
fi
fi
fi
sSqlGetDblist
=
"select datname from pg_database where not datistemplate and datallowconn order by datname;"
sDBList
=
"
$*
"
for
DATABASE
in
$(
su
${
PGUSER
}
-c
"psql
${
BACKUP_PARAMS
}
-At -c '
$sSqlGetDblist
' postgres"
2>/dev/null |
grep
-v
"^
$snapshotprefix
"
)
if
[
-z
"
$sDBList
"
]
;
then
sDBList
=
"
$(
pgsql.list
)
"
echo
"INFO: found databases:"
sed
"s#^# - #g"
<<<
"
$sDBList
"
fi
for
DATABASE
in
$sDBList
do
do
echo
-n
"__DB__
${
SERVICENAME
}
backup
$DATABASE
... "
echo
-n
"__DB__
${
SERVICENAME
}
backup
$DATABASE
... "
...
...
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