Browse Source

Merge pull request #4415 from ricardo777/patch-2

Allow Directadmin backups in tar.zst format
Jaap Marcus 1 year ago
parent
commit
cc151baf34
1 changed files with 51 additions and 12 deletions
  1. 51 12
      bin/v-import-directadmin

+ 51 - 12
bin/v-import-directadmin

@@ -19,6 +19,7 @@ source /etc/hestiacp/hestia.conf
 # load config file
 # load config file
 source_conf "$HESTIA/conf/hestia.conf"
 source_conf "$HESTIA/conf/hestia.conf"
 
 
+# Check required binaries
 if [ ! -e /usr/bin/rsync ] || [ ! -e /usr/bin/file ]; then
 if [ ! -e /usr/bin/rsync ] || [ ! -e /usr/bin/file ]; then
 	echo "#######################################"
 	echo "#######################################"
 	echo "rsync not installed, try install it"
 	echo "rsync not installed, try install it"
@@ -31,6 +32,7 @@ if [ ! -e /usr/bin/rsync ] || [ ! -e /usr/bin/file ]; then
 	fi
 	fi
 	exit 3
 	exit 3
 fi
 fi
+
 # Put this to 0 if you want use bash -x to debug it
 # Put this to 0 if you want use bash -x to debug it
 debug=1
 debug=1
 hestia_package=default
 hestia_package=default
@@ -63,42 +65,79 @@ tput sgr0
 tput setaf 2
 tput setaf 2
 echo "Checking provided file..."
 echo "Checking provided file..."
 tput sgr0
 tput sgr0
-if file $backup_file | grep -q -c "gzip compressed data,"; then
+
+if file "$backup_file" | grep -q -c "gzip compressed data"; then
 	tput setaf 2
 	tput setaf 2
-	echo "OK - Gziped File"
+	echo "OK - Gzipped File"
 	tput sgr0
 	tput sgr0
+
 	if [ ! -d /backup/${tmp_dir} ]; then
 	if [ ! -d /backup/${tmp_dir} ]; then
-		echo "Creating tmp.."
+		echo "Creating temporary directory..."
 		mkdir /backup/${tmp_dir}
 		mkdir /backup/${tmp_dir}
 	fi
 	fi
+
 	echo "Extracting backup..."
 	echo "Extracting backup..."
 	if [ "$debug" != 0 ]; then
 	if [ "$debug" != 0 ]; then
-		tar xzvf $backup_file -C /backup/${tmp_dir} 2>&1 \
-			| while read extracted_file; do
-				ex=$((ex + 1))
-				echo -en "wait... $ex files extracted\r"
-			done
+		tar xzvf "$backup_file" -C /backup/${tmp_dir} 2>&1 | while read -r extracted_file; do
+			ex=$((ex + 1))
+			echo -en "wait... $ex files extracted\r"
+		done
+	else
+		tar xzf "$backup_file" -C /backup/${tmp_dir}
+	fi
+
+	if [ $? -eq 0 ]; then
+		tput setaf 2
+		echo "Backup extracted without errors..."
+		tput sgr0
+	else
+		tput setaf 1
+		echo "Error on backup extraction, check your file and try extracting it manually"
+		tput sgr0
+		delete_tmp
+		exit 1
+	fi
+
+elif file "$backup_file" | grep -q -c "Zstandard compressed data"; then
+	tput setaf 2
+	echo "OK - Zstandard Compressed File"
+	tput sgr0
+
+	if [ ! -d /backup/${tmp_dir} ]; then
+		echo "Creating temporary directory..."
+		mkdir /backup/${tmp_dir}
+	fi
+
+	echo "Extracting backup..."
+	if [ "$debug" != 0 ]; then
+		tar --use-compress-program=pzstd -xvf "$backup_file" -C /backup/${tmp_dir} 2>&1 | while read -r extracted_file; do
+			ex=$((ex + 1))
+			echo -en "wait... $ex files extracted\r"
+		done
 	else
 	else
-		tar xzf $backup_file -C /backup/${tmp_dir}
+		tar --use-compress-program=pzstd -xf "$backup_file" -C /backup/${tmp_dir}
 	fi
 	fi
+
 	if [ $? -eq 0 ]; then
 	if [ $? -eq 0 ]; then
 		tput setaf 2
 		tput setaf 2
-		echo "Backup extracted whitout errors..."
+		echo "Backup extracted without errors..."
 		tput sgr0
 		tput sgr0
 	else
 	else
 		tput setaf 1
 		tput setaf 1
-		echo "Error on backup extraction, check your file, try extract it manually"
+		echo "Error on backup extraction, check your file and try extracting it manually"
 		tput sgr0
 		tput sgr0
 		delete_tmp
 		delete_tmp
 		exit 1
 		exit 1
 	fi
 	fi
+
 else
 else
 	tput setaf 1
 	tput setaf 1
-	echo "Error 3 not-gzip - no standard gziped backup provided of file not installed ( Try yum install file, or apt-get install file )"
+	echo "Error: Unsupported file format or 'file' command not installed (Try 'yum install file' or 'apt-get install file')"
 	tput sgr0
 	tput sgr0
 	delete_tmp
 	delete_tmp
 	exit 3
 	exit 3
 fi
 fi
+
 cd /backup/${tmp_dir}/
 cd /backup/${tmp_dir}/
 main_dir=$(pwd)
 main_dir=$(pwd)
 echo "Access tmp directory $main_dir"
 echo "Access tmp directory $main_dir"