Skip to content

Commit be81830

Browse files
authored
Issue with restore /*!999999\- enable the sandbox mode */
Fixes the issue with https://jira.mariadb.org/browse/MDEV-34203 somehow DirectAdmin uses this version of MariaDB which adds this, and import will only add a empty database, the code will remove the line from the sql file.
1 parent 733c4ab commit be81830

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

bin/v-import-directadmin

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -194,42 +194,52 @@ function run_da_db() {
194194
if [ $? == "1" ]; then
195195
if [ -e "backup/${database_name}.sql" ]; then
196196

197-
#Get the database name
197+
# Get the database name
198198
db=$(grep db_collation backup/"${da_db}" | tr '&' '\n ' | grep SCHEMA_NAME | cut -d "=" -f 2)
199199

200200
tput setaf 2
201201
echo " Create and restore ${db} "
202202
tput sgr0
203203
mysql -e "CREATE DATABASE $db"
204-
mysql "${db}" < backup/"${db}".sql
205-
#Get all the users of the database
206-
while IFS= read -r line; do
207204

205+
# Preprocess the SQL file to remove problematic lines: https://jira.mariadb.org/browse/MDEV-34203
206+
grep -vE '^/\*!(999999\\-)' "backup/${database_name}.sql" > "backup/${database_name}_processed.sql" 2>/dev/null
207+
208+
# Import the preprocessed SQL file with --force to ignore errors and continue
209+
mysql --force "${db}" < "backup/${database_name}_processed.sql"
210+
211+
if [ $? -ne 0 ]; then
212+
tput setaf 1
213+
echo "Error importing database $db"
214+
tput sgr0
215+
continue
216+
fi
217+
218+
# Get all the users of the database
219+
while IFS= read -r line; do
208220
selectdb_line=$(echo "$line" | grep passwd)
209221
if [ ! -z "$selectdb_line" ]; then
210-
211-
db_user=$(echo "$selectdb_line" | tr '&' '\n ' | grep "${directadmin_user}" | cut -d "=" -f 1)
212-
encoded_md5=$(echo "$selectdb_line" | tr '&' '\n ' | grep passwd | cut -d "=" -f 2)
213-
md5=$(urldecode "$encoded_md5")
222+
db_user=$(echo "$selectdb_line" | tr '&' '\n ' | grep "${directadmin_user}" | cut -d "=" -f 1)
223+
encoded_md5=$(echo "$selectdb_line" | tr '&' '\n ' | grep passwd | cut -d "=" -f 2)
224+
md5=$(urldecode "$encoded_md5")
214225

215226
echo "DB: $db"
216227
echo "udb: $db_user"
217228
echo "Password: ${md5}"
218229

219230
echo "DB='$db' DBUSER='$db_user' MD5='$md5' HOST='localhost' TYPE='mysql' CHARSET='UTF8' U_DISK='0' SUSPENDED='no' TIME='$time' DATE='$date'" >> /usr/local/hestia/data/users/"$directadmin_user"/db.conf
220231
fi
221-
222232
done < "backup/${da_db}"
223233

224-
# Leave hestia restore passwords and create users
234+
# Leave Hestia to restore passwords and create users
225235
tput setaf 2
226-
echo "Rebuild databases files for $directadmin_user"
236+
echo "Rebuild database files for $directadmin_user"
227237
tput sgr0
228238
"$BIN"/v-rebuild-databases "$directadmin_user"
229239
fi
230240
else
231241
tput setaf 1
232-
echo "Error: Cant restore database $db already exists in mysql server"
242+
echo "Error: Can't restore database $db, it already exists on the MySQL server"
233243
tput sgr0
234244
fi
235245
done

0 commit comments

Comments
 (0)