1

Topic: How to cleanup orphaned maildir data

==== Required information ====
- iRedMail version (check /etc/iredmail-release):
- Linux/BSD distribution name and version:
- Store mail accounts in which backend (LDAP/MySQL/PGSQL):
- Web server (Apache or Nginx):
- Manage mail accounts with iRedAdmin-Pro?
- Related log if you're reporting an issue:
======== Required information ====
- iRedMail version (check /etc/iredmail-release): 0.9.6
- Linux/BSD distribution name and version: Ubuntu 16.04 LTS
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx): Nginx
- Manage mail accounts with iRedAdmin-Pro? yes
- Related log if you're reporting an issue:
====

Hello Zhang!

Yesterday I installed a new iRedMail server and migrated all mail accounts to the new machine.
First of all I would like to thank you for the great product!

After migration I noticed that the directory for mail data contained some orphaned maildir files (domains which have been converted to aliases etc.).

How can I cleanup these orphaned directories?
Is there some hidden script which detects orphaned directories which have no reference in vmail-mailbox or vmail-domains?

Best regards,
Bernhard

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: How to cleanup orphaned maildir data

Unfortunately, we don't have such script/tool to help remove orphaned directories. sad

3 (edited by broth 2017-04-16 04:38:36)

Re: How to cleanup orphaned maildir data

Here you go, a quick little bash script which shows orphaned directories:

#!/bin/bash

# Script to find orphaned directories on iRedMail servers
# Created by Bernhard Roth (broth@roth-itk.de) 15.04.2017, Version 1.0

VMAIL_DIR="/var/vmail/vmail1"

echo "SELECT CONCAT(storagebasedirectory, '/', storagenode, '/', maildir) from mailbox;" | mysql vmail | sed -n '1!p' | sed 's/.$//' | sed 's/\/\.\//\//' | sort >/tmp/dbdir

find $VMAIL_DIR -type d -name Maildir -prune -exec dirname {} \;  | sort >/tmp/fsdir

echo -e "\e[31mOrphaned directories:\e[0m"
comm -13 /tmp/dbdir /tmp/fsdir

rm /tmp/dbdir /tmp/fsdir

It creates two sorted lists with directory names from the MySQL database and from the filesystem.
Then both lists are compared and all directories, which are not in the database, are shown.

On my iRedMail server this shows six correct orphaned directories.

I am sure this can be improved and enhanced to work with MariaDB, LDAP etc. but I am not so much a experienced bash script guy smile

Feedback and test reports welcome.