Open mikes222 opened 1 week ago
Just for reference, this is my interpretation of the second part of the script.
# get path of created mailbox
NEWPATH=$(/usr/lib/cyrus/bin/mbpath $SHORT_USER)
# get original path of mailbox
OLDPATH=$SPOOLDIR$1
if ! [ -d "$OLDPATH" ]; then
err "Old path for $MBX ($OLDPATH) does not exist, please investigate, skipping"
continue
fi
if ! [ -d "$NEWPATH" ]; then
die "New path for $MBX ($NEWPATH) does not exist, you missed creating a mailbox"
fi
# link it
if [ $(ls $OLDPATH | wc -l) -gt 40000 ]; then
echo echo $(ls $OLDPATH | wc -l) items for $OLDPATH
echo find ${OLDPATH} -maxdepth 1 -type f -name \'*\' -exec ln -f {} $NEWPATH \\\;
else
echo ln -f ${OLDPATH//\ /\\ }/\* $NEWPATH
fi | tee rootmbx.bash
chmod 755 rootmbx.bash
echo ----
echo rootmbx.bash created, please review before executing
echo ----
# 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 $SHORT_USER.$MBX)
# get original path of mailbox
OLDPATH=$SPOOLDIR$1/${MBX//\./\/}
if ! [ -d "$OLDPATH" ]; then
err "Old path for $MBX ($OLDPATH) does not exist, please investigate, skipping"
continue
fi
if ! [ -d "$NEWPATH" ]; then
die "New path for $MBX ($NEWPATH) does not exist, you missed creating a mailbox"
fi
# link it
if [ $(ls $OLDPATH | wc -l) -gt 40000 ]; then
echo echo $(ls $OLDPATH | wc -l) items for $OLDPATH
echo find ${OLDPATH} -maxdepth 1 -type f -name \'*\' -exec ln -f {} $NEWPATH \\\;
else
echo ln -f ${OLDPATH//\ /\\ }/\* $NEWPATH
fi
done | tee linkmbx.bash
chmod 755 linkmbx.bash
echo -----
echo linkmbx.bash created, please review before executing and then run it
echo manual work:
echo 1. might be too many argument, review output
echo 2. main inbox not linked, create inbox_recovered and link the contents. See the README for details on how to do that.
remaining open issues:
rootmbx.bash
You saved my life, great script. Just 2 possible enhancements:
ln -f /var/spool/cyrus/mail/m/user/michi/Entw&APw-rfe/* /var/spool/cyrus/mail/uuid/7/k/7kzoshey6w72aqj5tanqe0a5
In this case the german umlaut-a should rather be ....Entw\&APw-rfe...
One more thing, if the directory contains many, many files: The "*" character expands the command line with each file so there may be too many characters in the command line. In this case the
ln
command must be done in other ways. I did it with the following command which however is slower: