Dear Michael,

On Tue, 13 Jun 2023 21:43:34 +1000 Michael Stockenhuber 
<michael.stockenhu...@gmail.com> wrote:

> Thank you very much for this report and a possible solution. Exactly the
> same happened to me on upgrade to bookworm. Can you please elaborate how
> you did this in detail? I really would be in trouble if I lose the emails.
> I know this is a big ask but I would really appreciate your help.

Sure, I created a small quick'n'dirty helper script to automate some things 
(see below), I added the comments for this post. The script was created 
iteratively while figuring out how the recovering might work. I worked on the 
live system and relied on my backup. I did not spent any time to make the 
script fail-safe or even readable, sorry. (Be sure to backup the spool 
directory......)

===============================

#!/bin/bash
# the cyrus spool dir
SPOOLDIR=/var/spool/cyrus/mail/
# first argument is relative spool dir of user e.g.: $ scriptname k/user/kai
# extract user and reformat for cm command of cyadmin
# k/user/kai -> user.kai                
USER=$(echo $1|cut -d/ -f 2,3|tr "/" ".")        
# find all mailboxes of user and reformat for cm
MBXLIST=$(find $SPOOLDIR$1 -type d|cut -d/ -f 1-8 --complement|tr "/ " "._")
# generate a script for cyradm to create new mailboxes
for MBX in $MBXLIST; do
echo cm $USER.$MBX
done > creatembx.cyradm
echo starting shell to examine the situation
echo creatembx.cyradm created to feed cyradm \(please review\)
echo continue with exit
# start a shell to check cyradmin script and general situation
# you need to feed the cyradmin script to cyadmin with
# $ cat creatembx.cyradm | cyradm --user cyrus localhost
bash
# generate a script to hard-link to the new location
for MBX in $MBXLIST; do
# get path of created mailbox
NEWPATH=$(/usr/lib/cyrus/bin/mbpath $USER.$MBX)
# get original path of mailbox
OLDPATH=$SPOOLDIR$1/${MBX//\./\/}
# link it
echo ln -f ${OLDPATH//_/\\ }/\* $NEWPATH
done | tee linkmbx.bash
echo linkmbx.bash created, please review before executing
echo manual work:
echo 1. might be too many argument, review output
echo 2. main inbox not linked, create inbox_recovered

======================================

(be sure you understand each step of the script and be sure that it fits to 
your configuration.)

You need to apply this script for all users on your systems (~20 users on my 
system). Then you should see all sub-mailboxes filled with mails.

I treated the INBOX differently because the server was already receiving new 
mail and out them into the INBOX. To avoid any interferences I created a 
mailbox inbox_recovered for each user with cyradm:

$ cyradm --user cyrus localhost
xxx.xxx> cm user.kai.inbox_recovered
ctrl-d

and hard-linked the mails with

$ cd `mbpath user.kai.inbox_recovered`
$ ln -f /var/spool/cyrus/mail/k/user/kai/* .

(these are the commands from by bash history)

some final thoughts:
- I did all the operations as the user cyrus
- I used hard-linking to avoid copying 10s of Gigs of mails....
- it fails with unusual characters because of not escaping them
- new mailbox use underscore instead of blank (did not want to escape too)

Total time for my system: 6 hours with analysis, learnings, and recovering

Feel free to ask, if anything was too unclear, of if you want to know why I 
did sth this way (sometime there might be a reason, sometimes I did not know 
better)

Good luck
Kai

Reply via email to