Backup Script

** UNTESTED **

#!/bin/sh

# Remove previous backups to conserve on disk space
rm -f /backups/*

# Apt package list backup
dpkg --get-selections > /backups/dpkg_list_`date +%Y-%m-%d`.txt

# SQL dump
mysqldump -u root -pMYPASSWORD --all-databases > /tmp/mysqlbak
gzip /tmp/mysqlbak
mv /tmp/mysqlbak.gz /backups/dbbackup_`date +%Y-%m-%d`.sql.gz

# Filesystem backup
tar cfj /backups/fsbackup_`date +%Y-%m-%d`.tar.bz2 /etc /var /home

vnStat and vnstat PHP Frontend Installation – CentOS

Yum installation

yum install vnstat

Edit configuration

vim /etc/sysconfig/vnstat

I only have one interface (eth0), you may have more (eth1 etc…)

# see also: vnstat(1)
#
# starting with vnstat-1.6 vnstat can also be
# configured via /etc/vnstat.conf
#
# the following sets vnstat up to monitor eth0
VNSTAT_OPTIONS="-u -i eth0"

Edit configuration

vim /etc/vnstat.conf

Set your default interface

# default interface
Interface "eth0"

Setup your database

vnstat -u -i eth0

Start vnStat service

chkconfig vnstat on

Other commands for vnStat

service vnstat start
service vnstat stop
service vnstat restart
service vnstat status

Check if installation has been successful

vnstat
vnstat -i eth0

Run –help for more commands

vnstat --help

Now install php front end.
Install these if not already installed

yum install httpd php php-gd

Go to the directory you want to install the frontend. i.e. www.domain.com/vnstat/

# make directory
mkdir /home/domain/public_html/vnstat
# change to directory
cd /home/domain/public_html/vnstat
# download frontend files
wget http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.5.1.tar.gz
# untar file
tar xvf vnstat_php_frontend-1.5.1.tar.gz
# delete tar file
rm -f vnstat_php_frontend-1.5.1.tar.gz

Configure vnStat php frontend

vim /home/domain/public_html/vnstat/config.php

Look for the following Strings and edit them

$language = 'en';
$iface_list = array('eth0');
$iface_title['eth0'] = 'Internal';

Check if frontend has been installed correctly
www.domain.com/vnstat/

If you get the following error:

This page contains the following errors:

error on line 10 at column 10: error parsing attribute name
Below is a rendering of the page up to the first error.

Edit your config.php file

vim /home/domain/public_html/vnstat/config.php

Look for

// graphics format to use: svg or png
$graph_format='svg';

Replace svg with png

// graphics format to use: svg or png
$graph_format='png';

CSF Firewall Blocking VPN Internet Access

My CSF firewall seemed to be blocking internet access using my VPN. I could connect to it but could not use the internet connection. Here is a solution to the problem:

Create File

vim /etc/csf/csfpre.sh 

Insert This

iptables -A INPUT -i eth0 -p tcp --dport 1723 -j ACCEPT 
iptables -A INPUT -i eth0 -p gre -j ACCEPT 
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE 
iptables -A FORWARD -i ppp+ -o eth0 -j ACCEPT 
iptables -A FORWARD -i eth0 -o ppp+ -j ACCEPT 

Save File and Give Executable Permissions

chmod +x /etc/csf/csfpre.sh 

Create File

vi /etc/csf/csfpost.sh 

Input Text down

service pptpd stop 
service pptpd start 

Save File and Give Executable Permissions

chmod +x /etc/csf/csfpost.sh 

Restart CSF

csf -r

Install SVN::Notify on CentOS

This assumes you already have an SVN repository setup.

First download perl pre-requisites:

yum install perl-CPAN
perl -MCPAN -e 'install SVN::Notify'
perl -MCPAN -e 'install SVN::Notify::HTML::ColorDiff'

or

yum install perl
perl -MCPAN -e 'install SVN::Notify'
perl -MCPAN -e 'install SVN::Notify::HTML::ColorDiff'

Next download SVN Notify from CPAN:

cd /home
wget http://search.cpan.org/CPAN/authors/id/D/DW/DWHEELER/SVN-Notify-2.83.tar.gz
tar zxf SVN-Notify-2.83.tar.gz
cd SVN-Notify-2.83/

Next run MAKE:

perl Build.PL
./Build
./Build test
./Build install

If that doesn’t work then try:

perl Makefile.PL
make
make test
make install

Now change to your SVN directory and then to the hooks directory:

cd /%SVN LOCATION HERE%/hooks/

Create a post-commit file using vim:

vim post-commit

Add this to the file (replace: to-mail@domain.com/from-mail@domain.com/reply-mail@domain.com

#!/bin/sh
REPOS="$1"
REV="$2"
/usr/local/bin/svnnotify -r $REV -C -d -H HTML::ColorDiff \
-p $REPOS -t to-mail@domain.com --from from-mail@domain.com \
--reply-to reply-mail@domain.com

Save the script and give it execution permission:

chmod +x post-commit

Now every time someone commits to the SVN repository, an email notification will be sent.