Site icon David Yin's Blog

Switch to bzip2 compression on my server backup scripts

Previously I used gzip as compression tool to compress the web site files and mysql database.  It is still working on my Linode server. I learned something from the compairasion from this post .

So I tried to use bzip instead of gzip on my backup script.

Here is two examples.

1) Mysqldump file, which is a text sql file.

The original sql file is 52,317KB

Bzip2 is smaller than gzip file. It reduced about 15%.

2) Website files, including php, jpeg, png, css, any files used in web site.

The original tar gile is 187,670KB

Bzip2 is better. Backup file size is reduced by about 17%.

The following screenshot is the second example.

Because I am using it as a backup tool, the space occuppied is very important. To save the disk space, I chose bzip2 to replace gzip.

 

So my mysql database backup script is changed as below:


#!/bin/bash
### MySQL Server Login Info ###
MUSER="MySQL User name"
MPASS="MySQL Pass"
MHOST="localhost"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
BAK="/home/usera/backup/mysql"
GZIP="$(which gzip)"
BZIP2="$(which bzip2)"
### FTP SERVER Login info ###
FTPU="FTP User name"
FTPP="FTP Pass"
FTPS="backup.dreamhost.com"
NOW=$(date +"%d-%m-%Y")
[ ! -d $BAK ] && mkdir -p $BAK || /bin/rm -f $BAK/*
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
FILE=$BAK/$db.$NOW-$(date +"%T").gz
$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $BZIP2> $FILE
done
lftp -u $FTPU,$FTPP -e "mkdir /vps/backup/mysql/$NOW;cd /vps/backup/mysql/$NOW; mput /home/usera/backup/mysql/*; quit" $FTPS
find /home/usera/backup/mysql -ctime +4 -exec rm {} \;

 

 

Exit mobile version