Skip to content

Commit e1d64b8

Browse files
authored
On-the-fly gzip compression
Reduces backup time, free space requirement and disk writes.
1 parent c8e0374 commit e1d64b8

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

bin/v-backup-user

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,7 @@ if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB" != '*' ]; then
205205

206206
# Backup files
207207
cd $HOMEDIR/$user/web/$domain
208-
tar -cpf $tmpdir/web/$domain/domain_data.tar * ${fargs[@]}
209-
210-
# Compress archive
211-
gzip -$BACKUP_GZIP $tmpdir/web/$domain/domain_data.tar
208+
tar -cpf- * ${fargs[@]} |gzip -$BACKUP_GZIP - > $tmpdir/web/$domain/domain_data.tar.gz
212209
done
213210

214211
# Print total
@@ -307,25 +304,23 @@ if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL" != '*' ]; then
307304

308305
# Backup emails
309306
cd $HOMEDIR/$user/mail/$domain_idn
307+
accounts=()
310308
for account in $(ls); do
311309
exclusion=$(echo "$MAIL" |tr ',' '\n' |grep "$domain:")
312310
exclusion=$(echo "$exclusion" |tr ':' '\n' |grep "^$account$")
313311

314312
# Checking exlusions
315313
if [ -z "$exclusion" ] && [[ "$MAIL_SYSTEM" =~ exim ]]; then
316-
echo "$(date "+%F %T") + $account@$domain" |\
317-
tee -a $BACKUP/$user.log
318-
touch $tmpdir/mail/$domain/accounts.tar
319-
tar -rpf $tmpdir/mail/$domain/accounts.tar $account
314+
accounts+=($account)
320315
else
321316
echo "$(date "+%F %T") excluding mail account $account" |\
322317
tee -a $BACKUP/$user.log
323318
fi
324319
done
325320

326321
# Compress archive
327-
if [ -e "$tmpdir/mail/$domain/accounts.tar" ]; then
328-
gzip -$BACKUP_GZIP $tmpdir/mail/$domain/accounts.tar
322+
if [ ${#accounts[@]} -gt 0 ]; then
323+
tar -cpf- ${accounts[@]} |gzip -$BACKUP_GZIP - > $tmpdir/mail/$domain/accounts.tar.gz
329324
fi
330325
done
331326

@@ -445,10 +440,7 @@ if [ "$USER" != '*' ]; then
445440
echo -e "$(date "+%F %T") adding $udir" |tee -a $BACKUP/$user.log
446441

447442
# Backup files and dirs
448-
tar -cpf $tmpdir/user_dir/$udir.tar $udir
449-
450-
# Compress arhive
451-
gzip -$BACKUP_GZIP $tmpdir/user_dir/$udir.tar
443+
tar -cpf- $udir |gzip -$BACKUP_GZIP - > $tmpdir/user_dir/$udir.tar.gz
452444
fi
453445
done
454446
set +f

0 commit comments

Comments
 (0)