Thursday, October 4, 2007

Automatic Backup Data To TAPE

If you want run scheduler for backup your data from disk to tape, please follow its steps below. Make sure your tape drive(s) is installed properly.

Check with command below assume that your tape drive(s) is /dev/st0 or /dev/nst0 or /dev/tape. Before run this command please insert tape into drive.

[root@intranet~]# mt -f /dev/st0 status

SCSI 2 tape drive:
File number=0, block number=0, partition=0.
Tape block size 512 bytes. Density code 0x40 (DLT1 40 GB, or Ultrium).
Soft error count since last status=0
General status bits on (41010000):
BOT ONLINE IM_REP_EN


If your tape drive is OK then please create script to backup your data and place into one location or path.

# vi backup.sh

#!/bin/sh
###################################
# Konang Supian #
# 04 Okt 2007 MDGTI #
###################################
# File naming : day.month.year
suffix=$(date +%d.%m.%Y)
# Path to save file
echo Creating New Directory ....
dir=/usr/backup
dir1=$dir/$suffix
/bin/mkdir -p $dir1
# Daily Backup DB Mysql
echo Compressing DB MySQL ....
/bin/tar -zcf $dir1/mysql.$suffix.tar.gz /var/lib/mysql
# Daily Backup Source Program
echo Compressing Source Program ....
/bin/tar -zcf $dir1/source.$suffix.tar.gz /aplikasi
# Daily Backup DNS Zone
echo Compressing DNS Zone Data ....
/bin/tar -zcf $dir1/named.$suffix.tar.gz /var/named/chroot/var/named
# Writes to TAPE
echo FULL BACUP TO TAPE ....
/bin/tar cvf /dev/st0 $dir
echo ------------
echo FINISH REK
echo ------------



Edit your crontab :

# crontab -e

# Backup Harian DB Mysql, Source Program & DNS - pukul 05:00 pagi
0 5 * * * /root/backup.sh

[LIST TAPE]
#
/bin/tar -tvf /dev/st0

Example:
[root@intranet~]# tar -tvf /dev/st0

drwxr-xr-x root/root 0 2007-10-04 10:09:16 usr/backup/04.10.2007/
-rw-r--r-- root/root 12409437 2007-10-04 10:36:25 usr/backup/04.10.2007/mysql.04.10.2007.tar.gz
-rw-r--r-- root/root 228892698 2007-10-04 10:36:46 usr/backup/04.10.2007/source.04.10.2007.tar.gz


[EXTRACT TAPE]
# /bin/tar -xvf /dev/st0

[REWIND & EJECT TAPE]
# /bin/mt -f /dev/st0 rewoffl

Wednesday, September 26, 2007

Create LDAP Addressbook from Qmail Account

#!/usr/bin/perl

# Filename: import.pl
# Create LDAP addressbook or account by read vpopmail database on MYSQL
# konangsupian@gmail.com
# 13 Okt 2006
# ------------------------
# Updated Sept 2007
# Command shell to get realname & username from vpopmail database.
# mysql -u vpopmail -pmyvpopmailpasswd -e "use vpopmail; select pw_gecos,pw_name from mycompany_com;" > mycompany.txt


$ou = "addressbook";
open(LOGFILE,"mycompany.txt") or die("Could not open file.");
while (<LOGFILE>) {
chop($_);
@pisah = split("\t",$_);
$email = $pisah[1]."\@mycompany\.com";
$realname = $pisah[0];
@name = split(" ",$realname);
$var = "";
$var .= "\r\n\r\n";
$var .= "dn: cn=$realname ($email),ou=$ou,dc=mycompany,dc=com\r\n";
$var .= "objectClass: top\r\n";
$var .= "objectClass: person\r\n";
$var .= "objectClass: organizationalPerson\r\n";
$var .= "objectClass: inetOrgPerson\r\n";
#$var .= "objectClass: user\r\n";
$var .= "cn: $realname ($email)\r\n";
$var .= "givenName: $realname\r\n";
$var .= "sn: $name[0]\r\n";
$var .= "mail: $email\r\n";
$var .= "physicalDeliveryOfficeName: Gd. Kwarnas Pramuka Jl. Medan Merdeka Timur No. 6 Jakarta\r\n";
$var .= "postalAddress: Gd. Kwarnas Pramuka Jl. Medan Merdeka Timur No. 6 Jakarta\r\n";
$var .= "o: MYCOMPANY\r\n";
$var .= "l: Jakarta\r\n";
$var .= "ou: $ou\r\n";
$var .= "st: DKI\r\n";
$var .= "postalCode: 10110\r\n";
$var .= "telephoneNumber: +62-21-12345\r\n";
$var .= "facsimileTelephoneNumber: +62-21-54321\r\n";
$var .= "pager: +62-\r\n";
$var .= "mobile: +62-\r\n";
$var .= "homePhone: +62-\r\n";
#$var .= "associatedDomain: internaldomain.com\r\n";
#$var .= "ou: mdgti\r\n";
#$var .= "userPassword: {MD5}yFfXwwYLUsJXeqTg==\r\n";
print $var;
}
close($LOGFILE);

# End of import.pl


Action on shell
# ./import.pl > mycompany.ldif

Import data to LDAP with command :
# ldapadd -x -v -c -D "dc=mycompany,dc=com" -W < mycompany.ldif
Enter password: ********

*** Done ****


Sunday, September 23, 2007

Qmail Cluster ? Qmail Partitioning ? Qmail - Postfix Collaboration

Why I use questions on title above?
Because I' m not sure with my concept below is called Qmail Cluster.
Clustering that I get from here is :


CLUSTERING - Clustering is a technology using two or more computers that function together as a single entity for fault tolerance and load balancing. This can increase reliability and uptime in a client/server environment. One computer will sense when another computer is failing or getting bogged down and will take over full operation or just some of its tasks, depending on whether it's a complete fail-over design or just load balancing.

I agree that my design below on picture is called Qmail Partitioning because in my design there is no fail over function and or take over function. In my design only separate a single domain into some server that separated by location on same WAN/MPLS.

I am not writing completely because I assume you are Linux/Unix system administrator so you can get complete of Qmail and Postfix resources at their official site :

http://www.qmail.org/
http://www.lifewithqmail.org/
http://www.postfix.org/



Qmail Cluster, Qmail Partitioning, Qmail - Postfix CollaborationNote : my design above is already tested and running well.

Please review my design above and drop your comment below.

Wednesday, September 19, 2007

Configure Awstats for Qmail Log

You may have Qmail statistic before read this article. I don't know what you have is better or similar with this one, Awstats Qmail log analyzer. But if you have time you may try this one.

To create Awstats to analyze Qmail Log you have to prepare :

  1. Log repository, put on crontab and will grep qmail log every 10 minutes. May this not accurate because the log can be duplicate but you can sort this for unique row. Place this log at /var/log/awstats.qmail

    [getlog.sh]
    #!/bin/sh
    #!/bin/sh
    cat /var/log/qmail/qmail-pop3d/current > /var/log/awstats.qmail
    cat /var/log/qmail/qmail-send/current >> /var/log/awstats.qmail
    cat /var/log/qmail/qmail-smtpd/current >> /var/log/awstats.qmail


  2. Awstats, download this cute statistics from http://awstats.sourceforge.net/
  3. Get the script tools that will be used for at ../path/to/awstats/tools. You only need maillogconvert.pl script.
  4. Create the small program from Phil Hagen named "qmail2awstats.pl" and
    [qmail2awstats.pl]
    #!/usr/bin/perl
    # written by phil hagen on 27sep03

    while (<>) {
    @months = ('NUL', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); $hostname = `hostname`;
    # $hostname = `hostname -s`;
    chomp $hostname;
    $line = $_;
    $line =~ s/\d{4}-(\d{2})-(\d{2}) (\d{2}:\d{2}:\d{2}).\d{9} (.*)/$months[$1] $2 $3 $hostname qmail: 0000000000.000000 $4/; print $line;
    }

  5. Edit the Awstats configuration that placed or may have to create at /etc/awstats/awstats.mail.conf that called only short name "mail" later in awstats command.

    [/etc/awstats/awstats.mail.conf]
    LogFile="/usr/local/bin/tai64nlocal < /var/log/awstats.qmail |\
    /var/www/htdocs/awstats/tools/qmail2awstats.pl | \
    /var/www/htdocs/awstats/tools/maillogconvert.pl standard | "

    SiteDomain="mail.mydomain.com"
    HostAliases="mail.mydomain.com"
    DirData="/data/awstats"
    DirCgi="/awstats"
    DirIcons="/awstatsicons"
    AllowToUpdateStatsFromBrowser=0
    AllowFullYearView=2
    LogType=M
    LogFormat="%time2 %email %email_r %host %host_r %method %url %code %bytesd"
    LevelForBrowsersDetection=0
    LevelForOSDetection=0
    LevelForRefererAnalyze=0
    LevelForRobotsDetection=0
    LevelForWormsDetection=0
    LevelForSearchEnginesDetection=0
    LevelForFileTypesDetection=0
    ShowMenu=1
    ShowSummary=HB
    ShowMonthStats=HB
    ShowDaysOfMonthStats=HB
    ShowDaysOfWeekStats=HB
    ShowHoursStats=HB
    ShowDomainsStats=0
    ShowHostsStats=HBL
    ShowAuthenticatedUsers=0
    ShowRobotsStats=0
    ShowEMailSenders=HBML
    ShowEMailReceivers=HBML
    ShowSessionsStats=0
    ShowPagesStats=0
    ShowFileTypesStats=0
    ShowFileSizesStats=0
    ShowBrowsersStats=0
    ShowOSStats=0
    ShowOriginStats=0
    ShowKeyphrasesStats=0
    ShowKeywordsStats=0
    ShowMiscStats=0
    ShowHTTPErrorsStats=0
    ShowSMTPErrorsStats=1

    Why the awstats configuration must be at /etc/awstats ? Here is the DOC:

    # AWSTATS CONFIGURE FILE 6.6
    #-----------------------------------------------------------------------------
    # Copy this file into awstats.www.mydomain.conf and edit this new config file
    # to setup AWStats (See documentation in docs/ directory).
    # The config file must be in /etc/awstats, /usr/local/etc/awstats or /etc (for
    # Unix/Linux) or same directory than awstats.pl (Windows, Mac, Unix/Linux...)
    # To include an environment variable in any parameter (AWStats will replace
    # it with its value when reading it), follow the example:
    # Parameter="__ENVNAME__"
    # Note that environment variable AWSTATS_CURRENT_CONFIG is always defined with
    # the config value in an AWStats running session and can be used like others.
    #-----------------------------------------------------------------------------


  6. Create directory to save the log data
    # mkdir -p /data/awstats

  7. Add and change the cgi alias on apache, the configuration is :
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

    <Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
    </Directory>

    Alias /awstatsclasses "/var/www/htdocs/awstats/wwwroot/classes/"
    Alias /awstatscss "/var/www/htdocs/awstats/wwwroot/css/"
    Alias /awstatsicons "/var/www/htdocs/awstats/wwwroot/icon/"
    ScriptAlias /awstats/ "/var/www/htdocs/awstats/wwwroot/cgi-bin/"

    <Directory "/var/www/htdocs/awstats/wwwroot">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
    </Directory>

    Restart apache.
  8. Create and or add in crontab :
    #Awstats mail statistics
    */10 * * * * /var/www/htdocs/awstats/tools/getlog.sh
    */15 * * * * /var/www/htdocs/awstats/wwwroot/cgi-bin/awstats.pl -update -config=mail > /dev/null

  9. Run at your browser to access your mail statistics :
    http://www.mydomain.com/awstats/awstats.pl?config=mail

  10. Done.

    Awstats for Qmail

Search Linux Resources