Skip to content

Commit c6cf5a3

Browse files
author
AxelGuignard
committed
handle restoring only specific databases when DB_DUMP_BY_SCHEMA was used
1 parent e5b8f60 commit c6cf5a3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

entrypoint

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,17 @@ if [[ -n "$DB_RESTORE_TARGET" ]]; then
146146
mkdir -p $workdir
147147
$UNCOMPRESS < $TMPRESTORE | tar -C $workdir -xvf -
148148
RESTORE_OPTS=${RESTORE_OPTS:-}
149-
cat $workdir/* | mysql $RESTORE_OPTS -h $DB_SERVER -P $DB_PORT $DBUSER $DBPASS $DBDATABASE
149+
# If there are multiple schemas in the archive (e.g. DB_DUMP_BY_SCHEMA was used) and DB_NAMES is set,
150+
# restore only the required databases
151+
if [[ $(ls -1q $workdir/* | wc -l) -gt 1 ]] && [[ -n "$DB_NAMES" ]]; then
152+
for onedb in $DB_NAMES; do
153+
echo "Restoring $onedb from " $workdir/$onedb*
154+
# /!\ If a schema has a name that begins with another one, it will executed multiple times the other one
155+
cat $workdir/$onedb* | mysql $RESTORE_OPTS -h $DB_SERVER -P $DB_PORT $DBUSER $DBPASS
156+
done
157+
else
158+
cat $workdir/* | mysql $RESTORE_OPTS -h $DB_SERVER -P $DB_PORT $DBUSER $DBPASS $DBDATABASE
159+
fi
150160
rm -rf $workdir
151161
/bin/rm -f $TMPRESTORE
152162
else

0 commit comments

Comments
 (0)