Skip to content

Commit 3471e66

Browse files
authored
Revert binaries check, and use pzstd instead of unzstd
1 parent c61f1bd commit 3471e66

File tree

1 file changed

+87
-86
lines changed

1 file changed

+87
-86
lines changed

bin/v-import-directadmin

Lines changed: 87 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ source /etc/hestiacp/hestia.conf
2020
source_conf "$HESTIA/conf/hestia.conf"
2121

2222
# Check required binaries
23-
if [ ! -e /usr/bin/rsync ] || [ ! -e /usr/bin/file ] || [ ! -e /usr/bin/zstd ]; then
24-
echo "#######################################"
25-
echo "rsync, file, and/or zstd not installed. Please install them:"
26-
if [ -e /etc/redhat-release ]; then
27-
echo "Run: yum install rsync file zstd"
28-
else
29-
echo "Run: apt-get install rsync file zstd"
30-
fi
31-
echo "#######################################"
32-
exit 3
23+
if [ ! -e /usr/bin/rsync ] || [ ! -e /usr/bin/file ]; then
24+
echo "#######################################"
25+
echo "rsync not installed, try install it"
26+
echo "This script need: rsync, file"
27+
echo "#######################################"
28+
if [ -e /etc/redhat-release ]; then
29+
echo "Run: yum install rync file"
30+
else
31+
echo "Run: apt-get install rsync file"
32+
fi
33+
exit 3
3334
fi
3435

3536
# Put this to 0 if you want use bash -x to debug it
@@ -66,75 +67,75 @@ echo "Checking provided file..."
6667
tput sgr0
6768

6869
if file "$backup_file" | grep -q -c "gzip compressed data"; then
69-
tput setaf 2
70-
echo "OK - Gzipped File"
71-
tput sgr0
72-
73-
if [ ! -d /backup/${tmp_dir} ]; then
74-
echo "Creating temporary directory..."
75-
mkdir /backup/${tmp_dir}
76-
fi
77-
78-
echo "Extracting backup..."
79-
if [ "$debug" != 0 ]; then
80-
tar xzvf "$backup_file" -C /backup/${tmp_dir} 2>&1 | while read -r extracted_file; do
81-
ex=$((ex + 1))
82-
echo -en "wait... $ex files extracted\r"
83-
done
84-
else
85-
tar xzf "$backup_file" -C /backup/${tmp_dir}
86-
fi
87-
88-
if [ $? -eq 0 ]; then
89-
tput setaf 2
90-
echo "Backup extracted without errors..."
91-
tput sgr0
92-
else
93-
tput setaf 1
94-
echo "Error on backup extraction, check your file and try extracting it manually"
95-
tput sgr0
96-
delete_tmp
97-
exit 1
98-
fi
70+
tput setaf 2
71+
echo "OK - Gzipped File"
72+
tput sgr0
73+
74+
if [ ! -d /backup/${tmp_dir} ]; then
75+
echo "Creating temporary directory..."
76+
mkdir /backup/${tmp_dir}
77+
fi
78+
79+
echo "Extracting backup..."
80+
if [ "$debug" != 0 ]; then
81+
tar xzvf "$backup_file" -C /backup/${tmp_dir} 2>&1 | while read -r extracted_file; do
82+
ex=$((ex + 1))
83+
echo -en "wait... $ex files extracted\r"
84+
done
85+
else
86+
tar xzf "$backup_file" -C /backup/${tmp_dir}
87+
fi
88+
89+
if [ $? -eq 0 ]; then
90+
tput setaf 2
91+
echo "Backup extracted without errors..."
92+
tput sgr0
93+
else
94+
tput setaf 1
95+
echo "Error on backup extraction, check your file and try extracting it manually"
96+
tput sgr0
97+
delete_tmp
98+
exit 1
99+
fi
99100

100101
elif file "$backup_file" | grep -q -c "Zstandard compressed data"; then
101-
tput setaf 2
102-
echo "OK - Zstandard Compressed File"
103-
tput sgr0
104-
105-
if [ ! -d /backup/${tmp_dir} ]; then
106-
echo "Creating temporary directory..."
107-
mkdir /backup/${tmp_dir}
108-
fi
109-
110-
echo "Extracting backup..."
111-
if [ "$debug" != 0 ]; then
112-
tar --use-compress-program=unzstd -xvf "$backup_file" -C /backup/${tmp_dir} 2>&1 | while read -r extracted_file; do
113-
ex=$((ex + 1))
114-
echo -en "wait... $ex files extracted\r"
115-
done
116-
else
117-
tar --use-compress-program=unzstd -xf "$backup_file" -C /backup/${tmp_dir}
118-
fi
119-
120-
if [ $? -eq 0 ]; then
121-
tput setaf 2
122-
echo "Backup extracted without errors..."
123-
tput sgr0
124-
else
125-
tput setaf 1
126-
echo "Error on backup extraction, check your file and try extracting it manually"
127-
tput sgr0
128-
delete_tmp
129-
exit 1
130-
fi
102+
tput setaf 2
103+
echo "OK - Zstandard Compressed File"
104+
tput sgr0
105+
106+
if [ ! -d /backup/${tmp_dir} ]; then
107+
echo "Creating temporary directory..."
108+
mkdir /backup/${tmp_dir}
109+
fi
110+
111+
echo "Extracting backup..."
112+
if [ "$debug" != 0 ]; then
113+
tar --use-compress-program=pzstd -xvf "$backup_file" -C /backup/${tmp_dir} 2>&1 | while read -r extracted_file; do
114+
ex=$((ex + 1))
115+
echo -en "wait... $ex files extracted\r"
116+
done
117+
else
118+
tar --use-compress-program=pzstd -xf "$backup_file" -C /backup/${tmp_dir}
119+
fi
120+
121+
if [ $? -eq 0 ]; then
122+
tput setaf 2
123+
echo "Backup extracted without errors..."
124+
tput sgr0
125+
else
126+
tput setaf 1
127+
echo "Error on backup extraction, check your file and try extracting it manually"
128+
tput sgr0
129+
delete_tmp
130+
exit 1
131+
fi
131132

132133
else
133-
tput setaf 1
134-
echo "Error: Unsupported file format or 'file' command not installed (Try 'yum install file' or 'apt-get install file')"
135-
tput sgr0
136-
delete_tmp
137-
exit 3
134+
tput setaf 1
135+
echo "Error: Unsupported file format or 'file' command not installed (Try 'yum install file' or 'apt-get install file')"
136+
tput sgr0
137+
delete_tmp
138+
exit 3
138139
fi
139140

140141
cd /backup/${tmp_dir}/
@@ -177,7 +178,7 @@ echo "Start with databases"
177178
tput sgr0
178179

179180
echo "Get local databases"
180-
mysql -e "SHOW DATABASES" > server_dbs
181+
mysql -e "SHOW DATABASES" >server_dbs
181182
da_db_list=$(ls -1 backup/ | grep ".conf")
182183
function run_da_db() {
183184
for da_db in $da_db_list; do
@@ -194,7 +195,7 @@ function run_da_db() {
194195
echo " Create and restore ${db} "
195196
tput sgr0
196197
mysql -e "CREATE DATABASE $db"
197-
mysql ${db} < backup/${db}.sql
198+
mysql ${db} <backup/${db}.sql
198199
#Get all the users of the database
199200
while IFS= read -r line; do
200201

@@ -208,10 +209,10 @@ function run_da_db() {
208209
echo "udb: $db_user"
209210
echo "Password: ${md5}"
210211

211-
echo "DB='$db' DBUSER='$db_user' MD5='$md5' HOST='localhost' TYPE='mysql' CHARSET='UTF8' U_DISK='0' SUSPENDED='no' TIME='$time' DATE='$data'" >> /usr/local/hestia/data/users/$directadmin_user/db.conf
212+
echo "DB='$db' DBUSER='$db_user' MD5='$md5' HOST='localhost' TYPE='mysql' CHARSET='UTF8' U_DISK='0' SUSPENDED='no' TIME='$time' DATE='$data'" >>/usr/local/hestia/data/users/$directadmin_user/db.conf
212213
fi
213214

214-
done < "backup/${da_db}"
215+
done <"backup/${da_db}"
215216

216217
# Leave hestia restore passwords and create users
217218
tput setaf 2
@@ -256,13 +257,13 @@ for directadmin_domain in $directadmin_domain_list; do
256257
tput sgr0
257258
elif [ -d /home/${directadmin_user}/web/${directadmin_domain} ]; then
258259
echo "Domain $directadmin_domain added, restoring files"
259-
echo $directadmin_domain >> restored_domains
260+
echo $directadmin_domain >>restored_domains
260261
rm -f /home/$directadmin_user/web/$directadmin_domain/public_html/index.html
261262
rm -f /home/$directadmin_user/web/$directadmin_domain/public_html/robots.txt
262263

263264
public_sync_count=0
264-
rsync -av domains/${directadmin_domain}/public_html/ /home/$directadmin_user/web/$directadmin_domain/public_html 2>&1 \
265-
| while read file_dm; do
265+
rsync -av domains/${directadmin_domain}/public_html/ /home/$directadmin_user/web/$directadmin_domain/public_html 2>&1 |
266+
while read file_dm; do
266267
public_sync_count=$(($public_sync_count + 1))
267268
echo -en "-- $public_sync_count restored files\r"
268269
done
@@ -275,8 +276,8 @@ for directadmin_domain in $directadmin_domain_list; do
275276
else
276277
private_sync_count=0
277278

278-
rsync -av domains/${directadmin_domain}/private_html/ /home/$directadmin_user/web/$directadmin_domain/private 2>&1 \
279-
| while read file_dm; do
279+
rsync -av domains/${directadmin_domain}/private_html/ /home/$directadmin_user/web/$directadmin_domain/private 2>&1 |
280+
while read file_dm; do
280281
private_sync_count=$(($private_sync_count + 1))
281282
echo -en "-- $private_sync_count restored files\r"
282283
done
@@ -316,8 +317,8 @@ if [ -e restored_domains ]; then
316317
tmp_pass=$(generate_password)
317318
$BIN/v-add-mail-account $directadmin_user $da_mail_domain $da_imap tmp_pass
318319
if [ "$debug" != 0 ]; then
319-
rsync -av imap/${da_mail_domain}/${da_imap}/Maildir/ /home/${directadmin_user}/mail/${da_mail_domain}/${da_imap} 2>&1 \
320-
| while read backup_file_dm; do
320+
rsync -av imap/${da_mail_domain}/${da_imap}/Maildir/ /home/${directadmin_user}/mail/${da_mail_domain}/${da_imap} 2>&1 |
321+
while read backup_file_dm; do
321322
sk_sync=$((sk_sync + 1))
322323
echo -en "-- $sk_sync restored files\r"
323324
done

0 commit comments

Comments
 (0)