How to enable gzip (web Page) compression in Apache
First lets be sure your server supports compression, to do that it needs to have the mod_deflate module:
# cat httpd.conf | grep deflate
You should see this:
LoadModule deflate_module modules/mod_deflate.so
If it is commented, comment it out and add following lines :-
# vim /etc/httpd/conf/httpd.conf
#################################################
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
# You can’t compress what is already compressed
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
# Make proxies work as they should.
<IfModule mod_headers.c>
Header append Vary User-Agent
</IfModule>
</IfModule>
#BrowserMatch ^Mozilla/4 gzip-only-text/html
#BrowserMatch ^Mozilla/4\.0[678] no-gzip
#BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
#################################################
How to enable gzip compression in Tomcat
Add the following attributes to the <Connector> in Tomcat’s server.xml to enable gzip compression of responses at line no.- 70 :-
# vim apache-tomcat/conf/server.xml
compression=”on” compressionMinSize=”2048″
compressableMimeType=”text/html,text/xml,text/csv,text/css,text/javascript”
Before
<Connector port=”8080″ protocol=”HTTP/1.1″
connectionTimeout=”20000″
redirectPort=”8443″ /
After
<Connector port=”8080″ protocol=”HTTP/1.1″
connectionTimeout=”20000″
redirectPort=”8443″
compression=”on” compressionMinSize=”2048″
compressableMimeType=”text/html,text/xml,text/csv,text/css,text/javascript” />
backup_script_encrypt.sh (in bzip2 format)
########################################################################
# Application Server Backup ######################################################
# backup_script_encrypt.sh (in-bzip2-format script) ########################################
########################################################################
#!/bin/sh
set -x
set -v
standby=$1
myfile=”Test_Backup`date ‘+%d-%b-%Y-%H-%M’`.tar.bz2″
BACKUPDIR=/backup/htmldaily/
BACKUPFILE=”Test_Backup`date ‘+%d-%b-%Y-%H-%M’`.tar”
cd $BACKUPDIR
tar cvf $BACKUPFILE /var/www/html/
bzip2 -cvf – $BACKUPFILE | openssl enc -aes-256-cbc -pass pass:ABCabc123@ -e | dd of=/backup/htmldaily/$myfile.enc
rm -rvdf $BACKUPFILE
scp /backup/htmldaily/$myfile backup@$standby:/backup/autobackup/htmldaily/
rsync -avzE –progress /backup/htmldaily/$myfile backup@X.X.X.X:/backup/autobackup/htmldaily/
########################################################################
# To decrypt Tesing_Backup.bzip2 file
#
# openssl aes-256-cbc -d -pass pass:ABCabc123@ -in Test_Backup.bzip2.enc -out Test_Backup.bzip2
########################################################################
# -d –decompress
# -c –compress
# -f –force
# -v –verbose
# Password = ABCabc123@
########################################################################
backup_script_encrypt.sh (in tar.gz format)
#########################################################################
# Application Server Backup #######################################################
# backup_script_encrypt.sh (in-bzip2-format script) #########################################
#########################################################################
#!/bin/sh
set -x
set -v
standby=$1
myfile=”Test_Backup`date ‘+%d-%b-%Y-%H-%M’`.tar.gz”
BACKUPDIR=/backup/htmldaily/
BACKUPFILE=”Test_Backup`date ‘+%d-%b-%Y-%H-%M’`.tar”
cd $BACKUPDIR
tar cvf $BACKUPFILE /var/www/html/
tar -zcvf – $BACKUPFILE | openssl enc -aes-256-cbc -pass pass:ABCabc123@ -e | dd of=/backup/htmldaily/$myfile.enc
rm -rvdf $BACKUPFILE
scp /backup/htmldaily/$myfile backup@$standby:/backup/autobackup/htmldaily/
rsync -avzE –progress /backup/htmldaily/$myfile backup@X.X.X.X:/backup/autobackup/htmldaily/
#########################################################################
# To decrypt Test_Backup.bzip2 file
#
# openssl aes-256-cbc -d -pass pass:ABCabc123@ -in Test_Backup.tar.gz.enc -out Test_Backup.tar.gz
#########################################################################
# -d –decompress
# -c –create
# -f –force
# -v –verbose
# -z –gzip
# Password = ABCabc123@
#########################################################################
bzip2: (stdin): trailing garbage after EOF ignored
You may receive the following warning during extraction:
bzip2: (stdin): trailing garbage after EOF ignored
This seems harmless, you can get rid of it by either writing the archive to disk before transfer or using gzip instead of bzip2. The archive still decompresses fine, but tar is apparently outputting some additional garbage when using bzip2 and outputting to stdout. I personally still using bzip2 and stdout, as the advantages (greater compression ratio, no temp disk space required) outweigh the disadvantages.
backup_dump_encrypt.sh (in tar.gz format)
#############################################################################
# Database Server Backup ############################################################
# backup_dump_encrypt.sh (in-tar.gz-format) script #############################################
#############################################################################
#!/bin/sh
set -x
set -v
standby=$1
myfirstfile=”Testing_Backup`date +’%d-%b-%Y-%H-%M’`.sql”
myfile=”Testing_Backup`date +’%d-%b-%Y-%H-%M’`.sql.tar.gz”
# mysql dump, check, scp and report
mysqldump -uroot -pPASSWORD –all-databases –routines –flush-logs –single-transaction –master-data=2 > /backup/mysqldump/$myfirstfile 2> /backup/mysqldump/ORS_err.txt
cd /backup/mysqldump/
tar -zcvf – $myfirstfile | openssl enc -aes-256-cbc -pass pass:ABCabc123@ -e | dd of=/backup/mysqldump/$myfirstfile.tar.gz.enc
rm -rvdf $myfirstfile
scp /backup/mysqldump/$myfile backup@$standby:/backup/mysqldump/
rsync -avzE –progress /backup/mysqldump/$myfile backup@X.X.X.X:/backup/autobackup/mysqldump/
#############################################################################
# To decrypt Tesing_Backup.bzip2 file
#
# openssl aes-256-cbc -d -pass pass:ABCabc123@ -in Testing_Backup.tar.gz.enc -out Testing_Backup.tar.gz
#############################################################################
# -d –decompress
# -c –create
# -f –force
# -v –verbose
# -z –gzip
# Password = ABCabc123@
#############################################################################