APLawrence - Information and Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds Get APLawrence.com by RSS











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Home > Kerio > Kerio Connect Archive Script
Printer Friendly Version




Kerio Connect Archive Script




2011/11/17

Yesterday I mentioned testing how well Kerio Connect's new automatic reindexing responds to deliberate abuse. It turns out that it responds well, so I took advantage of that to create an automatic archiving script.

This is a simple need that I am sure Kerio will add someday. The problem is that some users simply will not ever clean up their INBOX. As it grows larger, the system slows down because it has to search the #msgs directory for free slots. Large directories just bog things down; archiving prevents that.

As written here, this should run once a month. It creates dated subfolders of INBOX and moves older email into these. Here i used the "ctime" to decide age, but you could also open each message and use internal dates.

You can see the result here:

archive folder

The 2011_11_16 folder was by this script created from older messages in INBOX. When it runs next month, it will create another subfolder of INBOX.

As it can take time for the automatic index checking to take place, I have this set to run at 1 minute past midnight on the 1st of the month. By the time I get up in the morning, the reindexing should be long done.



This script is provided without guarantee, warranty or anything else. Use at your own risk and check results carefully. IF YOU DON'T UNDERSTAND THE SCRIPT, YOU PROBABLY SHOULDN'T USE IT!

This script depends apon the background reindexing features introduced in Kerio Connect 7.3 and will not work on earlier versions. It may not work on later versions because of structural changes to Kerio..

Finally, this was tested on a Linux system. Perl can run on Windows but you would need to change the script.

I use the temporary directory with the rename to avoid the reindexer finding messages before everything is copied into place.. this way, it all appears at once.

#!/usr/bin/perl
$KERIO="/opt/kerio/mailserver/store/mail/aplawrence.com/";
$SAFE="/root/kdir";  # put it wherever you like
@t=localtime(time()-(3600 * 24)); # go back one day

chdir($KERIO);
foreach (<*>) {
  next if /#public$/;
  # add anyone else you want to skip
  $who=$_;
  print "$_\n";
$dir=sprintf("%4d_%0.2d_%0.2d",$t[5]+1900,$t[4]+1,$t[3]);
exit 1 if (-e "$KERIO/$who/INBOX/$dir");
# already exists
if (not -e "$SAFE/$who") {
  mkdir("$SAFE/$who") or exit 1;
}
if (not -e "$SAFE/$who/$dir") {
  mkdir("$SAFE/$who/$dir") or exit 1;
  mkdir("$SAFE/$who/$dir/#msgs") or exit 1;
  mkdir("$SAFE/$who/$dir/#assoc") or exit 1;
}
chdir ("$KERIO/$who/INBOX/");
foreach (<*.fld>) {
  print "$who $_\n";
  system("/bin/cp $_ $SAFE/$who/$dir");
  # for windows   system("copy  $_ $SAFE/$who/$dir");
}
chdir("#msgs");
$rightnow=time();
foreach(<*.eml>) {
  @stats=stat $_;
  $howold=($rightnow - $stats[10]) / (3600 * 24); # days old
  next if $howold < 7;
  print "$who $_ $howold\n";
  rename $_,"$SAFE/$who/$dir/#msgs/$_";
}
rename "$SAFE/$who/$dir","$KERIO/$who/INBOX/$dir";
}
 

A more complex script could archive by the correspondent or anything else you might glean from the message content. Your imagination is the only limit.


If this page was useful to you, please click to help others find it:  
Your +1's can help friends, contacts, and others on the web find the best stuff when they search.


Comments?




More Articles by Anthony Lawrence - Find me on Google+



Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar


Kerio Connect Mailserver

Kerio Control Firewall

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!


book graphic unix and linux troubleshooting guide




Buy Kerio from a dealer who knows tech: I sell and support

Kerio Connect Mail server, Control, Workspace and Operator licenses and subscription renewals




pavatar.jpg

This post tagged:

       - Kerio
       - Kerio Info
       - Kerio Pricing
       - Mail




Unix/Linux Consultants

Skills Tests

Guest Post Here