Skip to content

Commit c61f1bd

Browse files
authored
Allow Directadmin backups in tar.zst format
Allow zst format when this is enabled in Directadmin: https://docs.directadmin.com/directadmin/backup-restore-migration/backups.html#how-to-enable-zstd-compression-for-backups Tested with both formats, and working for me.
1 parent fa86a71 commit c61f1bd

File tree

1 file changed

+83
-45
lines changed

1 file changed

+83
-45
lines changed

bin/v-import-directadmin

Lines changed: 83 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@ source /etc/hestiacp/hestia.conf
1919
# load config file
2020
source_conf "$HESTIA/conf/hestia.conf"
2121

22-
if [ ! -e /usr/bin/rsync ] || [ ! -e /usr/bin/file ]; then
23-
echo "#######################################"
24-
echo "rsync not installed, try install it"
25-
echo "This script need: rsync, file"
26-
echo "#######################################"
27-
if [ -e /etc/redhat-release ]; then
28-
echo "Run: yum install rync file"
29-
else
30-
echo "Run: apt-get install rsync file"
31-
fi
32-
exit 3
22+
# 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
3333
fi
34+
3435
# Put this to 0 if you want use bash -x to debug it
3536
debug=1
3637
hestia_package=default
@@ -63,42 +64,79 @@ tput sgr0
6364
tput setaf 2
6465
echo "Checking provided file..."
6566
tput sgr0
66-
if file $backup_file | grep -q -c "gzip compressed data,"; then
67-
tput setaf 2
68-
echo "OK - Gziped File"
69-
tput sgr0
70-
if [ ! -d /backup/${tmp_dir} ]; then
71-
echo "Creating tmp.."
72-
mkdir /backup/${tmp_dir}
73-
fi
74-
echo "Extracting backup..."
75-
if [ "$debug" != 0 ]; then
76-
tar xzvf $backup_file -C /backup/${tmp_dir} 2>&1 \
77-
| while read extracted_file; do
78-
ex=$((ex + 1))
79-
echo -en "wait... $ex files extracted\r"
80-
done
81-
else
82-
tar xzf $backup_file -C /backup/${tmp_dir}
83-
fi
84-
if [ $? -eq 0 ]; then
85-
tput setaf 2
86-
echo "Backup extracted whitout errors..."
87-
tput sgr0
88-
else
89-
tput setaf 1
90-
echo "Error on backup extraction, check your file, try extract it manually"
91-
tput sgr0
92-
delete_tmp
93-
exit 1
94-
fi
67+
68+
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
99+
100+
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
131+
95132
else
96-
tput setaf 1
97-
echo "Error 3 not-gzip - no standard gziped backup provided of file not installed ( Try yum install file, or apt-get install file )"
98-
tput sgr0
99-
delete_tmp
100-
exit 3
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
101138
fi
139+
102140
cd /backup/${tmp_dir}/
103141
main_dir=$(pwd)
104142
echo "Access tmp directory $main_dir"

0 commit comments

Comments
 (0)