Bug#1037346: Lost all emails during update

2023-07-01 Thread Phil Dibowitz
OK I've updated my copy of the script to properly handle both 
underscores and spaces:


https://github.com/jaymzh/recover-cyrus/blob/main/recover_cyrus_user.sh

Hope that helps others!

On 7/1/23 18:32, Phil Dibowitz wrote:

Aha, I figured out the issue.

Your script does:

   ln -f ${OLDPATH//_/\\ }/\* $NEWPATH

But the substitution there is incorrect - the folders with `_` in them, 
actually have that in their file path.


On 7/1/23 15:24, Phil Dibowitz wrote:

Kai,

I noticed that no emails in nested folders were recovered. Is that 
expected?







--
Phil Dibowitz p...@ipom.com
Open Source software and tech docsInsanity Palace of Metallica
http://www.phildev.net/   http://www.ipom.com/

"Be who you are and say what you feel, because those who mind don't
 matter and those who matter don't mind."
 - Dr. Seuss



Bug#1037346: Lost all emails during update

2023-07-01 Thread Phil Dibowitz

Aha, I figured out the issue.

Your script does:

  ln -f ${OLDPATH//_/\\ }/\* $NEWPATH

But the substitution there is incorrect - the folders with `_` in them, 
actually have that in their file path.


On 7/1/23 15:24, Phil Dibowitz wrote:

Kai,

I noticed that no emails in nested folders were recovered. Is that 
expected?





--
Phil Dibowitz p...@ipom.com
Open Source software and tech docsInsanity Palace of Metallica
http://www.phildev.net/   http://www.ipom.com/

"Be who you are and say what you feel, because those who mind don't
 matter and those who matter don't mind."
 - Dr. Seuss



Bug#1037346: Lost all emails during update

2023-07-01 Thread Phil Dibowitz

Kai,

I noticed that no emails in nested folders were recovered. Is that expected?


--
Phil Dibowitz p...@ipom.com
Open Source software and tech docsInsanity Palace of Metallica
http://www.phildev.net/   http://www.ipom.com/

"Be who you are and say what you feel, because those who mind don't
 matter and those who matter don't mind."
 - Dr. Seuss



Bug#1037346: Lost all emails during update

2023-06-14 Thread Kai Lindenberg
Dear Michael,

On Tue, 13 Jun 2023 21:43:34 +1000 Michael Stockenhuber 
 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



Bug#1037346: Lost all emails during update

2023-06-13 Thread Michael Stockenhuber
Dear Kai,
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.
Best regards
Michael

PS. I may have a delay answering, I am down under.