Skip to content

Commit 952e977

Browse files
Function for importing large Database (hestiacp#4125)
* Create v-import-database * Make minor changes --------- Co-authored-by: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com>
1 parent 2cbddb4 commit 952e977

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

bin/v-import-database

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
# info: import database
3+
# options: USER DB PATH
4+
#
5+
# example: v-import-database alice mydb /full/path/to.sql
6+
#
7+
# This function for importing database.
8+
9+
#----------------------------------------------------------#
10+
# Variables & Functions #
11+
#----------------------------------------------------------#
12+
13+
# Argument definition
14+
user=$1
15+
database=$2
16+
dump=$3
17+
18+
# Includes
19+
# shellcheck source=/etc/hestiacp/hestia.conf
20+
source /etc/hestiacp/hestia.conf
21+
# shellcheck source=/usr/local/hestia/func/main.sh
22+
source $HESTIA/func/main.sh
23+
# shellcheck source=/usr/local/hestia/func/db.sh
24+
source $HESTIA/func/db.sh
25+
# shellcheck source=/usr/local/hestia/func/rebuild.sh
26+
source $HESTIA/func/rebuild.sh
27+
# load config file
28+
source_conf "$HESTIA/conf/hestia.conf"
29+
30+
#----------------------------------------------------------#
31+
# Verifications #
32+
#----------------------------------------------------------#
33+
34+
check_args '3' "$#" 'DATABASE USER'
35+
is_format_valid 'database' 'user'
36+
is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
37+
is_object_valid 'user' 'USER' "$user"
38+
is_object_unsuspended 'user' 'USER' "$user"
39+
is_object_valid 'db' 'DB' "$database"
40+
41+
if [ ! -f "$dump" ]; then
42+
echo "Error: dump file doesn't exist"
43+
log_event "$E_NOTEXIST" "$ARGUMENTS"
44+
exit "$E_NOTEXIST"
45+
fi
46+
47+
# Check db existence
48+
db_data=$(grep "DB='$database'" $HESTIA/data/users/$user/db.conf)
49+
50+
parse_object_kv_list "$db_data"
51+
#Fix issue #1084 with "Upper case not allowed with PGSQL"
52+
if [ "$TYPE" == "pgsql" ]; then
53+
usersmall=$(echo "$user" | tr '[:upper:]' '[:lower:]')
54+
else
55+
usersmall=$user
56+
fi
57+
58+
# Perform verification if read-only mode is enabled
59+
check_hestia_demo_mode
60+
61+
#----------------------------------------------------------#
62+
# Action #
63+
#----------------------------------------------------------#
64+
65+
# Import dump
66+
case $TYPE in
67+
mysql) import_mysql_database "$dump" ;;
68+
pgsql) import_pgsql_database "$dump" ;;
69+
esac
70+
71+
#----------------------------------------------------------#
72+
# Hestia #
73+
#----------------------------------------------------------#
74+
75+
# Logging
76+
log_event "$OK" "$ARGUMENTS"
77+
78+
exit

0 commit comments

Comments
 (0)