Thursday, July 05, 2007

Using tape backup in Linux (DAT40)

Installed an old tape drive (Seagate DAT40 20/40G), finally worked out a math for backing up critical data into multiple tapes. It is taking a long time for the backup to finish, so I decided to upgrade to an LTO1 drive that supports 100GB per tape uncompressed. That might solve the frequent tape changing.

For backing up and verifying the backup (similar to verify data after burning a cd-r) you can use the command
tar -cvpWlf /dev/st0 /home
Where,
c : create a new archive of /home
v : Verbose output
p : Ignore umask when extracting files i.e. preserve permissions on files
W : attempt to verify the archive after writing it
l : stay in local file system when creating an archive
f : Specify /dev/st0 as tape device (file)
/dev/st0: Tape device name.
/home : Directory to backup

I would like to use bzip2 compression prior to backing up to tape, that requires turning off compression on the tape drive itself. To get the current status of compression, run the command
tapeinfo -f /dev/st0

For setting the compression off
mt -f /dev/nst0 defcompression 0

For setting the compression on
mt -f /dev/nst0 defcompression 1

Tuesday, July 03, 2007

Webserver(lighttpd) access log

We have installed lighttpd and made the basic configuration to serve plain html pages and later while setting up vnstat PHP front end, we made changes to enable cgi module and php.

Now let us configure the access logging (just to know who is looking at our website)

First create a place on the USB HDD to hold the log files
mkdir /opt/log/lighttpd

Install the accesslog module
ipkg install lighttpd-mod-accesslog

modify /etc/lighttpd.conf

uncomment server.modules
and the corresponding closing brace (if you did not install PHP)

insert the line
mod_accesslog
before the closing brace

at the end of the file insert the lines
#### Access log
accesslog.filename = "/opt/log/lighttpd/access.log"

restart lighttpd server
/etc/init.d/S80lighttpd stop
/etc/init.d/S80lighttpd start

you will now have the lighttpd access log in /opt/log/lighttpd/access.log

Monday, July 02, 2007

vnstat PHP frontend

The vnstat frontend runs in PHP. We installed lighttpd but did not install php. Now we will install php and make the necessary changes in the lighttpd.conf to run it in cgi mode.

To run php in cgi mode, install mod_cgi for lighttpd
ipkg install lighttpd-mod-cgi

Now install php and gd for php
ipkg -d opt install php5 php5-cgi php5-mod-gd (dep. libgd, libjpeg, libpng)
the following files will be installed
/opt/etc/php.ini
/opt/usr/bin/php
/opt/usr/lib/php/gd.so
/opt/usr/lib/libgd.so.2.0.0
/opt/usr/lib/libgd.so.2
/opt/usr/lib/libjpeg.so.62.0.0
/opt/usr/lib/libjpeg.so.62
/opt/usr/lib/libpng.so.3.0.0
/opt/usr/lib/libpng12.so.0.0.0
/opt/usr/lib/libpng.so.3
/opt/usr/lib/libpng12.so.0

create symbolic link for php.ini file (by default cgi version of php looks for php.ini in /etc)
ln -s /opt/etc/php.ini /etc/php.ini

To enable mod_cgi in lighttpd, edit vi /etc/lighttpd.conf
uncomment server.modules, the corresponding closing brace and uncomment the line
"mod_cgi",

under #### CGI module add the line
cgi.assign = ( ".php" => "/opt/usr/bin/php" )

for running the php scripts when you hit a directory, index.php needs to be added to index-file.names. For that change the line
index-file.names = ( "index.html", "default.html", "index.htm", "default.htm" )
to
index-file.names = ( "index.html", "default.html", "index.htm", "default.htm", "index.php" )

To enable GD extension in PHP, edit /opt/etc/php.ini, uncomment the line
extension=gd.so

Because we have installed the GD module in a non-standard location, change the line
; Directory in which the loadable extensions (modules) reside.
extension_dir = "/usr/lib/php"
to
; Directory in which the loadable extensions (modules) reside.
extension_dir = "/opt/usr/lib/php"

Restart lighttpd service
/etc/init.d/S80lighttpd stop
/etc/init.d/S80lighttpd start


download the vnstat PHP frontend from here, extract the files to the directory vnstat and copy that to your lighttpd document root

edit config.php under the vnstat PHP frontend directory and change the interfaces as shown below
$iface_list = array('eth0', 'eth1', 'eth2', 'br0');

$iface_title['eth0'] = 'Internal';
$iface_title['eth1'] = 'Internet';
$iface_title['eth2'] = 'eth2';
$iface_title['br0'] = 'Bridge';

also change the vnstat_bin variable to point to the vnstat executable for data collection by the script
$vnstat_bin = '/usr/bin/vnstat';

Now visit your web page at http:/192.168.1.1/vnstat/ for the GUI.

vnstat - network traffic monitor for Linux

install vnstat
ipkg install vnstat

When running vnstat to update the statistics, it will create the stats database in /var/lib/vnstat (/var is in the /tmp directory that is lost after a reboot). If you are using a USB harddrive, you can map that to /opt/lib. To make the mapping automatically at every reboot create a file /etc/init.d/S98vnstatlib paste the lines below

#!/bin/sh

ln -s /opt/lib /var/lib

Now to create the initial text database for the appropriate interfaces you need to run
vnstat -u -i eth0
vnstat -u -i eth1
vnstat -u -i eth2
vnstat -u -i br0

To collect the stats you will have to update the databases regularly by running "vnstat -u" using cron.

enable cron in web interface System -> Cron

create a file /etc/crontabs/root and run the command (it will update the vnstat database every 5 minutes)
echo "*/5 * * * * if [ -x /usr/bin/vnstat ] && [ `ls /var/lib/vnstat/ | wc -l` -ge 1 ]; then /usr/bin/vnstat -u; fi " >> /etc/crontabs/root

restart cron to commit the changes made to the crontab files
/etc/init.d/S60cron restart