Skip to content

Commit c4e0c6a

Browse files
authored
Merge pull request hestiacp#4300 from hestiacp/feature/v-dump-database-compression
Add support for Compression v-dump-database
2 parents af0e9bc + 0817b49 commit c4e0c6a

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

bin/v-dump-database

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/bin/bash
2-
# info: Dumps database contents in STDIN / file
3-
# options: USER DATABASE [FILE]
2+
# info: Dumps database contents in STDIN or file optional file can be compressed
3+
# options: USER DATABASE [FILE] [COMPRESSION]
44
#
55
# example: v-dump-database user user_databse > test.sql
6-
# example: v-dump-database user user_databse file
6+
# example: v-dump-database user user_databse file gzip
7+
# example: v-dump-database user user_databse file zstd
78
#
8-
# Dumps database in STDIN or /backup/user.database.type.sql
9+
# Dumps database in STDIN or file (/backup/user.database.type.sql)
10+
# For compression gzip or zstd is supported by default plain sql is used
911

1012
#----------------------------------------------------------#
1113
# Variables & Functions #
@@ -15,6 +17,7 @@
1517
user=$1
1618
database=$2
1719
output=$3
20+
compression=$4
1821

1922
# Includes
2023
# shellcheck source=/etc/hestiacp/hestia.conf
@@ -26,7 +29,7 @@ source $HESTIA/func/db.sh
2629
# load config file
2730
source_conf "$HESTIA/conf/hestia.conf"
2831

29-
check_args '2' "$#" 'USER DATABASE'
32+
check_args '2' "$#" 'USER DATABASE [OUTPUT] [COMPRESSION]'
3033
is_format_valid 'user' 'database'
3134
is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
3235
is_object_valid 'user' 'USER' "$user"
@@ -63,17 +66,30 @@ case $TYPE in
6366
pgsql) dump_pgsql_database ;;
6467
esac
6568

69+
if [ "$compression" = 'zstd' ]; then
70+
extension="sql.zst"
71+
pzstd $dump
72+
rm $dump
73+
dump="$tmpdir/$database.$TYPE.sql.zst"
74+
elif [ "$compression" = 'gzip' ]; then
75+
extension="sql.gz"
76+
gzip $dump
77+
dump="$tmpdir/$database.$TYPE.sql.gz"
78+
else
79+
extension="sql"
80+
fi
81+
6682
if [ "$output" = "file" ]; then
6783
# echo filename for use in the php
68-
echo "${user}_${database}_${TYPE}_${timestamp}.sql"
84+
echo "${user}_${database}_${TYPE}_${timestamp}.${extension}"
6985

70-
cp $dump $BACKUP/${user}_${database}_${TYPE}_${timestamp}.sql
86+
cp $dump $BACKUP/${user}_${database}_${TYPE}_${timestamp}.${extension}
7187

7288
# echo file location for use in the php
73-
echo "$BACKUP/${user}_${database}_${TYPE}_${timestamp}.sql"
89+
echo "$BACKUP/${user}_${database}_${TYPE}_${timestamp}.${extension}"
7490

7591
# cleanup
76-
echo "rm $BACKUP/${user}_${database}_${TYPE}_${timestamp}.sql" | at now + 1 hour
92+
echo "rm $BACKUP/${user}_${database}_${TYPE}_${timestamp}.${extension}" | at now + 1 hour
7793
else
7894
cat $dump
7995
fi

web/download/database/index.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99

1010
$database = quoteshellarg($_GET["database"]);
1111

12-
exec(HESTIA_CMD . "v-dump-database " . $user . " " . $database . " file", $output, $return_var);
12+
exec(
13+
HESTIA_CMD . "v-dump-database " . $user . " " . $database . " file gzip",
14+
$output,
15+
$return_var,
16+
);
1317

1418
if ($return_var == 0) {
1519
header("Content-type: application/sql");

0 commit comments

Comments
 (0)