Просмотр исходного кода

Function for importing large Database (#4125)

* Create v-import-database
* Make minor changes

---------

Co-authored-by: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com>
Adion Gorani 2 лет назад
Родитель
Сommit
3b68b3790d
1 измененных файлов с 78 добавлено и 0 удалено
  1. 78 0
      bin/v-import-database

+ 78 - 0
bin/v-import-database

@@ -0,0 +1,78 @@
+#!/bin/bash
+# info: import database
+# options: USER DB PATH
+#
+# example: v-import-database alice mydb /full/path/to.sql
+#
+# This function for importing database.
+
+#----------------------------------------------------------#
+#                Variables & Functions                     #
+#----------------------------------------------------------#
+
+# Argument definition
+user=$1
+database=$2
+dump=$3
+
+# Includes
+# shellcheck source=/etc/hestiacp/hestia.conf
+source /etc/hestiacp/hestia.conf
+# shellcheck source=/usr/local/hestia/func/main.sh
+source $HESTIA/func/main.sh
+# shellcheck source=/usr/local/hestia/func/db.sh
+source $HESTIA/func/db.sh
+# shellcheck source=/usr/local/hestia/func/rebuild.sh
+source $HESTIA/func/rebuild.sh
+# load config file
+source_conf "$HESTIA/conf/hestia.conf"
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+check_args '3' "$#" 'DATABASE USER'
+is_format_valid 'database' 'user'
+is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
+is_object_valid 'user' 'USER' "$user"
+is_object_unsuspended 'user' 'USER' "$user"
+is_object_valid 'db' 'DB' "$database"
+
+if [ ! -f "$dump" ]; then
+	echo "Error: dump file doesn't exist"
+	log_event "$E_NOTEXIST" "$ARGUMENTS"
+	exit "$E_NOTEXIST"
+fi
+
+# Check db existence
+db_data=$(grep "DB='$database'" $HESTIA/data/users/$user/db.conf)
+
+parse_object_kv_list "$db_data"
+#Fix issue #1084 with "Upper case not allowed with PGSQL"
+if [ "$TYPE" == "pgsql" ]; then
+	usersmall=$(echo "$user" | tr '[:upper:]' '[:lower:]')
+else
+	usersmall=$user
+fi
+
+# Perform verification if read-only mode is enabled
+check_hestia_demo_mode
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+# Import dump
+case $TYPE in
+	mysql) import_mysql_database "$dump" ;;
+	pgsql) import_pgsql_database "$dump" ;;
+esac
+
+#----------------------------------------------------------#
+#                       Hestia                             #
+#----------------------------------------------------------#
+
+# Logging
+log_event "$OK" "$ARGUMENTS"
+
+exit