File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments