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

Add support for Compression v-dump-database

Add support for gzip and zstd
Jaap Marcus 2 лет назад
Родитель
Сommit
4d9c5ce1dc
2 измененных файлов с 29 добавлено и 9 удалено
  1. 24 8
      bin/v-dump-database
  2. 5 1
      web/download/database/index.php

+ 24 - 8
bin/v-dump-database

@@ -1,11 +1,13 @@
 #!/bin/bash
 #!/bin/bash
-# info: Dumps database contents in STDIN / file
-# options: USER DATABASE [FILE]
+# info: Dumps database contents in STDIN or file optional file can be compressed
+# options: USER DATABASE [FILE] [COMPRESSION]
 #
 #
 # example: v-dump-database user user_databse > test.sql
 # example: v-dump-database user user_databse > test.sql
-# example: v-dump-database user user_databse file
+# example: v-dump-database user user_databse file gzip
+# example: v-dump-database user user_databse file zstd
 #
 #
-# Dumps database in STDIN or /backup/user.database.type.sql
+# Dumps database in STDIN or file (/backup/user.database.type.sql)
+# For compression gzip or zstd is supported by default plain sql is used
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                Variables & Functions                     #
 #                Variables & Functions                     #
@@ -15,6 +17,7 @@
 user=$1
 user=$1
 database=$2
 database=$2
 output=$3
 output=$3
+compression=${4-none}
 
 
 # Includes
 # Includes
 # shellcheck source=/etc/hestiacp/hestia.conf
 # shellcheck source=/etc/hestiacp/hestia.conf
@@ -63,17 +66,30 @@ case $TYPE in
 	pgsql) dump_pgsql_database ;;
 	pgsql) dump_pgsql_database ;;
 esac
 esac
 
 
+if [ "$compression" = 'zstd' ]; then
+	extension="sql.zst"
+	pzstd $dump
+	rm $dump
+	dump="$tmpdir/$database.$TYPE.sql.zst"
+elif [ "$compression" = 'gzip' ]; then
+	extension="sql.gz"
+	gzip $dump
+	dump="$tmpdir/$database.$TYPE.sql.gz"
+else
+	extension="sql"
+fi
+
 if [ "$output" = "file" ]; then
 if [ "$output" = "file" ]; then
 	# echo filename for use in the php
 	# echo filename for use in the php
-	echo "${user}_${database}_${TYPE}_${timestamp}.sql"
+	echo "${user}_${database}_${TYPE}_${timestamp}.${extension}"
 
 
-	cp $dump $BACKUP/${user}_${database}_${TYPE}_${timestamp}.sql
+	cp $dump $BACKUP/${user}_${database}_${TYPE}_${timestamp}.${extension}
 
 
 	# echo file location for use in the php
 	# echo file location for use in the php
-	echo "$BACKUP/${user}_${database}_${TYPE}_${timestamp}.sql"
+	echo "$BACKUP/${user}_${database}_${TYPE}_${timestamp}.${extension}"
 
 
 	# cleanup
 	# cleanup
-	echo "rm $BACKUP/${user}_${database}_${TYPE}_${timestamp}.sql" | at now + 1 hour
+	echo "rm $BACKUP/${user}_${database}_${TYPE}_${timestamp}.${extension}" | at now + 1 hour
 else
 else
 	cat $dump
 	cat $dump
 fi
 fi

+ 5 - 1
web/download/database/index.php

@@ -9,7 +9,11 @@ verify_csrf($_GET);
 
 
 $database = quoteshellarg($_GET["database"]);
 $database = quoteshellarg($_GET["database"]);
 
 
-exec(HESTIA_CMD . "v-dump-database " . $user . " " . $database . " file", $output, $return_var);
+exec(
+	HESTIA_CMD . "v-dump-database " . $user . " " . $database . " file gzip",
+	$output,
+	$return_var,
+);
 
 
 if ($return_var == 0) {
 if ($return_var == 0) {
 	header("Content-type: application/sql");
 	header("Content-type: application/sql");