Forums

Resolved
0 votes
Hi,

I had a crash of my server a few months ago and restored the old mails back to and old backup of my server.
It looks like there are some links to old mails/attachments are not correct

Also the attachments folder is pretty big compared to the user folder sizes
There is a script from kopano to clean orphaned attachments, but this not working because of the location of mysql in ClearOS
ClearOS is using the sandbxed mysql location instead of the default location

Is there somebody how know how to change this in the script ??


location of the script : /usr/share/doc/kopano/db-remove-orphaned-attachments

#!/usr/bin/perl -w
# SPDX-License-Identifier: AGPL-3.0-only

use strict;
use DBI;

my $L1 = 10;
my $L2 = 20;

sub do_error($) {
exit(1);
}

sub readconfig($) {
my ($fn) = @_;
my %options;

open(CFG, $fn) or die("unable to open ".$fn." config file");
while (<CFG>;) {
if ($_ =~ /^\s*[#!]/) {
next;
}
if ($_ =~ /^\s*(\S+)\s*=\s*([^\r]+)\r?$/) {
my $idx = $1;
my $val = $2;
chomp($val);
$val =~ s/\s+$//;
$options{$idx} = $val;
}
}
close(CFG);
return %options;
}

# TODO: parse config, and use settings
if(scalar(@ARGV) < 1) {
print "Usage: $0 <server.cfg>\n";
exit(1);
}

my $servercfg = $ARGV[0];
$servercfg = "/etc/kopano/server.cfg" if (!defined($servercfg));
my %serveropt = readconfig($servercfg);

my $basepath = $serveropt{attachment_path};

my $db = DBI->connect("dbi:mysql:database=".$serveropt{mysql_database}.";host=".$serveropt{mysql_host}, $serveropt{mysql_user}, $serveropt{mysql_password})
or die "Database error: ".$DBI::errstr;

my $res;
my $sth;
my $rows;
my @row;

if (!defined($db)) {
print "did not connect to mysql\n";
exit(1);
}

print "Finding all orphaned attachments...\n";
$sth = $db->prepare("SELECT DISTINCT(instanceid) FROM singleinstances LEFT JOIN hierarchy ON hierarchyid=hierarchy.id WHERE hierarchy.id IS NULL;");
$sth->execute() || die $DBI::errstr;;

if ($sth->rows == 0) {
print "No orphaned attachments found.\n";
exit(0);
}

if ($serveropt{attachment_storage} eq "files") {
print "Processing ".$sth->rows." orphaned attachments\n";

while(@row = $sth->fetchrow_array()) {
my $filename = $basepath."/".($row[0] % $L1)."/".(($row[0] / $L1) % $L2)."/".$row[0];

# can be either with or without compression
system("rm -f ".$filename." ".$filename.".gz");
}
}

$res = $db->do("begin;");
if(!$res) {
do_error(1);
}

print "Cleaning singleinstances...\n";
$sth = $db->prepare("DELETE singleinstances.* FROM singleinstances LEFT JOIN hierarchy ON hierarchyid=hierarchy.id WHERE hierarchy.id IS NULL;");
$sth->execute() || die $DBI::errstr;;

print "Cleaning lob...\n";
$sth = $db->prepare("DELETE lob.* FROM lob LEFT JOIN singleinstances ON lob.instanceid = singleinstances.instanceid WHERE singleinstances.instanceid IS NULL;");
$sth->execute() || die $DBI::errstr;;

print "Flush database changes to disk...\n";
$db->do("commit;");

print "Done.\n";
Saturday, February 04 2023, 10:45 AM
Share this post:
Responses (3)
  • Accepted Answer

    Monday, February 06 2023, 06:09 PM - #Permalink
    Resolved
    1 votes
    I’ve built a email server using iRedMail - looks pretty good, and has amavis and SMTP authentication preconfigured (the latter is missing capability in Kopano/COS) .. uses sogo to provide full capabilities for ActiveSync devices (phones for example). The build uses distribution supplied packages, and just (apparently) does the configuration, so as package security updates (etc) get released (by eg Ubuntu), you stay up to date with security fixes etc. You install (cf. script) on to an Ubuntu LTS. I tried it on Debian, but that lacks one capability that’s In Ubuntu on the SMPT authentication side.
    Like
    1
    The reply is currently minimized Show
  • Accepted Answer

    Monday, February 06 2023, 05:18 PM - #Permalink
    Resolved
    0 votes
    Richard George wrote:

    Personally I've ditched both ClearOS and Kopano .. the former because of it's apparent death, and the latter because of this statement ...

    Statement regarding the closure of the kopano community forum and the end of the community edition

    Note the date of November 2022 ...


    What are you using as an alternative for Kopano ?
    The reply is currently minimized Show
  • Accepted Answer

    Monday, February 06 2023, 04:25 PM - #Permalink
    Resolved
    0 votes
    Personally I've ditched both ClearOS and Kopano .. the former because of it's apparent death, and the latter because of this statement ...

    Statement regarding the closure of the kopano community forum and the end of the community edition

    Note the date of November 2022 ...
    The reply is currently minimized Show
Your Reply