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: new upstream bug

2023-06-14 Thread Kai Lindenberg
Dear Maintainer,

a new upstream bug was filed on github 
https://github.com/cyrusimap/cyrus-imapd/issues/4532.

Best
-Kai



Bug#1037346: cyrus-imapd: all emails disappeared after upgrading from bullseye to bookworm (similar to #1007965)

2023-06-11 Thread Kai Lindenberg
Package: cyrus-imapd
Version: 3.6.1-4
Severity: important

Dear Maintainer,

today I upgraded our famliy+friends email server system from bullseye to
bookworm including the cyrus-imapd upgrade to v3.6.1-4.

Unfortunately, all mails of all users disappeared and new inboxes were
autocreated when users logged in:

--syslog-
Jun 11 12:27:15 xxx cyrus/imaps[1730301]: autocreateinbox: User x, INBOX
was successfully created
-

The emails were still in the non-uuid directory of the cyrus spool dir. I did
not figure out how this happened, but I solved it by

1. extracting a list of all sub-mailboxes of all users from the filesystem
structure,
2. re-creating the same sub-mailboxes with the cm command of cyradm,
3. and hard-linking all directory content to the new uuid dirs (with the help
of mbpath)

The issue is now solved for me, but I can provide additional system
information and logs if needed.

(same report goes to https://github.com/cyrusimap/cyrus-imapd/issues/4035)

-Kai



-- System Information:
Debian Release: 12.0
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 6.1.0-9-amd64 (SMP w/4 CPU threads; PREEMPT)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages cyrus-imapd depends on:
ii  cyrus-common  3.6.1-4
ii  libc6 2.36-9
ii  libcom-err2   1.47.0-2
ii  libsasl2-22.1.28+dfsg-10
ii  libssl3   3.0.9-1
ii  libwrap0  7.6.q-32
ii  zlib1g1:1.2.13.dfsg-1

Versions of packages cyrus-imapd recommends:
ii  rsync  3.2.7-1

cyrus-imapd suggests no packages.

-- no debconf information