Leaderboard (728 x 90)
Showing posts with label Mail. Show all posts
Showing posts with label Mail. Show all posts

Monday, July 25, 2022

Zimbra Mysql Crash Recovery

In the event of database corruption it may be necessary to manually perform database recovery. See Bug 15797 for an example of an issue with mysql that will require database recovery. In that example, a warning message like the following appeared in the mysql error log:

InnoDB: Serious error! InnoDB is trying to free page 716
InnoDB: though it is already marked as free in the tablespace!
InnoDB: The tablespace free space info is corrupt.
InnoDB: You may need to dump your InnoDB tables and recreate the whole
InnoDB: database!

Before beginning a full database recovery, check to see if the corruption may be limited to a single mboxgroup or a single user within an mboxgroup. This type of corruption frequently lets the server run normally for extended periods of time, with crashes occurring only when an affected user attempts to access certain mailbox items. If this is the case, it may be possible to dump, drop and recover only the affected entries without disrupting the database as a whole. Please see the instructions in the Mysql Crash Recovery (alternate method) article.

Overview of Recovery Process

  1. Configure mysql to start in recovery mode
  2. Generate SQL dumps of all relevant databases
  3. Remove all existing (and possibly corrupt) databases
  4. Re-create all databases
  5. Repopulate the databases with the data from the SQL dumps
  6. Test databases and start all ZCS services

Details of Recovery Process

1. Configure mysql to start in recovery mode

  1. Edit the file /opt/zimbra/conf/my.cnf and add a line like innodb_force_recovery = 1 under the [mysqld] section (Note that it may be necessary to increase the recovery level depending on the extent of the database corruption, as shown at the end of the database dump step)
  2. Save the file and re-start mysqld
mysql.server start

2. Generate SQL dumps of all databases

  1. Load some mysql configuration into shell variables (i.e. $mysql_socket and $mysql_root_password; note that you will use these again in step 3)
  2. Make a list of the existing databases
  3. Create a directory to hold the SQL dumps
  4. Generate the SQL dumps from the database list
source ~/bin/zmshutil ; zmsetvars
mysql --batch --skip-column-names -e "show databases" | grep -e mbox -e zimbra > /tmp/mysql.db.list

Note: If you are using ZCS v8.8.x with Chat/Talk enabled then you should take Chat database dump as well

mysql --batch --skip-column-names -e "show databases" | grep -e mbox -e zimbra -e chat > /tmp/mysql.db.list
mkdir /tmp/mysql.sql 
for db in `cat /tmp/mysql.db.list`; do
     mysqldump $db -S $mysql_socket -u root --password=$mysql_root_password > /tmp/mysql.sql/$db.sql
     echo "Dumped $db"
     sleep 10
 done

Note: If you encounter any mysql errors while dumping the databases, start over by re-editing /opt/zimbra/conf/my.cnf, incrementing the value for innodb_force_recovery by one, and restarting mysqld. It is critical to update this incrementally - 1, 2, 3, and only if needed 4. 4 and above can cause DB corruption. Please see MySQL's Forcing InnoDB Recovery guide for more information.

Note: Starting 8.7 , path of mysqldump has been changed from /opt/zimbra/mysql/bin/mysqldump to /opt/zimbra/common/bin/mysqldump . Please update the command accordingly if you are doing this for a system >= ZCS 8.7.x

Note: An error of "bash: /tmp/mysql.sql/$db.sql: ambiguous redirect" probably indicates your using an apostrophe or single quote ' rather than a tick ` -- which is one the same key as the tilde ~ .

Note: Do not reboot the machine, as some Operating Systems will remove all contents in the /tmp directory during the reboot sequence, i.e. your /tmp/mysql.sql will be removed.

HINT Did the dump work or not, try grep -L "Dump completed" /tmp/mysql.sql/*.sql [those that didn't] and grep "Dump completed" /tmp/mysql.sql/*.sql [those that did].

3. Remove all existing (and possibly corrupt) databases

Note: Take a copy of /opt/zimbra/db/data before dropping the databases. This will ensure a copy of old database.

Note that we drop the zimbra database last because the mboxgroup* databases depend on it

for db in `cat /tmp/mysql.db.list |grep mbox`
do
    mysql -u root --password=$mysql_root_password -e "drop database $db"
    echo -e "Dropped $db"
done
mysql -u root --password=$mysql_root_password -e "drop database zimbra"

Remove existing InnoDB tablespace and log files

rm -rf /opt/zimbra/db/data/ib*

Note: First, use with caution - this shouldn't need to be used often. Issue came about because of some rsync issues. Can't dump db's because of 'connection' issues at this point? One could move the /opt/zimbra/db/data directory - mv /opt/zimbra/db/data /opt/zimbra/db/data-old and then make the db - mkdir /opt/zimbra/db/data w/ ownership of zimbra:zimbra . Remove the innodb_force_recovery line from /opt/zimbra/conf/my.cnf . Then recreate a default mysql db by running /opt/zimbra/libexec/zmmyinit --sql_root_pw $mysql_root_password and then attempt this steps over again to confirm you can drop them. Also note that you may have to reset the zimbra password manually in mysql, then set it again in Zimbra with the instructions from this page: http://wiki.zimbra.com/wiki/Resetting_LDAP_%26_MySQL_Passwords

4. Re-create all databases

  1. Run mysql in non-recovery mode
    1. Remove the innodb_force_recovery line from /opt/zimbra/conf/my.cnf
    2. Save the file and restart mysqld
  2. Re-create the databases from the database list
mysql.server restart
for db in `cat /tmp/mysql.db.list`
do
    mysql -e "create database $db character set utf8"
    echo "Created $db"
done

5. Repopulate the databases with the data from the SQL dumps

Import the data from the SQL dumps. Note that we import the zimbra database first because the mboxgroup databases depend on it

mysql zimbra < /tmp/mysql.sql/zimbra.sql
for sql in /tmp/mysql.sql/mbox*
do
    mysql `basename $sql .sql` < $sql
    echo -e "Updated `basename $sql .sql` \n"
done

Note : If you are using ZCS v8.8.x with Chat/Talk enabled then you should import chat db as well.

mysql chat < /tmp/mysql.sql/chat.sql

6. Test databases and start all ZCS services

Note that this is an example query. If you know of any particular databases that were corrupt, you may want to construct other queries to verify normal access to the data.

mysql zimbra -e "select * from mailbox order by id desc limit 1"

Once you are satisfied that the databases are restored intact, start the rest of the zimbra services.

zmcontrol start

Check /opt/zimbra/log/mysql_error.log and /opt/zimbra/log/mailbox.log for database errors.


Reference: https://wiki.zimbra.com/wiki/Mysql_Crash_Recovery

Friday, September 28, 2012

How to force Sendmail to use smarthost without DNS

1. make sure your smarthost is in /etc/hosts.
2. Create /etc/mail/service.switch file and put following two lines inside:

hosts files
aliases files.

3.Replace this line in /etc/mail/submit.mc file.

define(`SMART_HOST',`my smarthost from /etc/hosts')dnl

4. Go to /etc/mail and type "m4 sendmail.mc > /etc/sendmail.cf" to build new sendmail.cf.
5. type /etc/init.d/sendmail restart

Friday, April 20, 2012

How to move MailArchiva and its data from one server to another


These instructions describe how to move MailArchiva and its data from one server to another

Directories#

There is no complex database replication procedure to perform. Copying MailArchiva from one machine to another is as simple as copying a few directories over to another machine (almost!).
(1) Install a clean copy of MailArchiva on the new server.
(2) Copy the following directories & files from the old server to the new server

Server Configuration#

C:\Program Files\MailArchiva\server\webapps\ROOT\WEB-INF\conf\* (windows)
/usr/local/mailarchiva/server/webapps/ROOT/WEB-INF/conf/* (linux)

Logging Configuration#

C:\Program Files\MailArchiva\server\webapps\ROOT\WEB-INF\classes\log4j.xml (windows)
/usr/local/mailarchiva/server/webapps/ROOT/WEB-INF/classes/log4j.xml

License File (EE only)#

C:\Program Files\MailArchiva\server\webapps\ROOT\WEB-INF\classes\license.lic (windows)
/usr/local/mailarchiva/server/webapps/ROOT/WEB-INF/classes/license.lic

Audit & Log Files#

C:\Program Files\MailArchiva\server\logs\* (windows) /usr/local/mailarchiva/server/logs/* (linux)
C:\Program Files\MailArchiva\server\webapps\ROOT\WEB-INF\logs\* (windows)
/usr/local/mailarchiva/server/webapps/ROOT/WEB-INF/logs/* (linux)
C:\Program Files\MailArchiva\server\webapps\ROOT\WEB-INF\logs\index\* (windows)
/usr/local/mailarchiva/server/webapps/ROOT/WEB-INF/logs/index* (linux)\

Volumes#

Copy all files in all volume store paths and index paths
(copying indexes over is optional)
Since there are potentially a large number of files in the store path, on Linux when using the cp command you may receive the errors "too many arguments"
To workaround this, follow one of the methods in the following article: http://www.linuxjournal.com/article/6060

Thursday, August 5, 2010

Where is default configuration path for spamassassin?

The default rules directory is /usr/share/spamassassin
The site rules directory is /etc/mail/spamassassin
The updated rules directory is /var/lib/spamassassin

Monday, July 5, 2010

Outlook Express Error Code : 0×800C0133

ข้อผิดพลาดหมายเลข 0×800C0133 เกิดขึ้นจากการที่ Outlook Express
ไม่สามารถจัดการกับ Inbox ที่มีขนาดเกิน 2 กิกะไบต์ได้นั่นเอง
โดยทั้งนี้ไม่ขึ้นอยู่กับจำนวนอีเมลล์ที่รับได้
ขึ้นตอนการแก้ไขทำได้หลายวิธีด้วยกัน แต่แนะนำให้ถือโอกาสนี้
สังคายนา Inbox ของคุณซะเลยก็ดีเหมือนกันนะ

ขั้นแรก สร้างเมลล์บ็อกซ์ขึ้นมาใหม่
โดยคลิ้กขวาบนรายการ Local Folders ที่อยู่ในกรอบหน้าต่างทางขวา
เลือกคำสั่ง New Folder ตั้งชื่อ เช่น 2008Q1 ซึ่งหมายถึงอีเมลล์
3เดือนแรกของปี 2008

จากนั้นใน Inbox คลิ้กเลือกอีเมลล์ตั้งแต่เดือนมกรา-มีนาคม คลิ้กขวา
เลือกคำสั่ง Move to Foder… เลือกย้ายไปที่โฟลเดอร์ 2008Q1
เพียงแค่นี้อีเมลล์ 3 เดือนแรกของปีก็จะถูกย้ายออกไปจาก Inboxแล้ว

ขั้นตอนต่อไป ก็คือการลดขนาด Inbox ด้วยการคลิ้กเมนู
File–>Compact โปรแกรม OE จะลดขนาดไฟล์ Inbox ลง
โดยคุณสามารถตรวจสอบขนาดไฟล์อินบ็อกซ์ได้ที่
C:\Document and Settings\(user)\Local Settings\Application Data\
Identities\{GIU}\Microsoft\Outlook Express
จะเห็นว่าไฟล์ Inbox.dbx มีขนาดลดลงแล้ว ให้ลองคลิ้กรับเมลล์อีกครั้ง

Reference: http://blog.ibiz.co.th/2008/12/15/oe-outlook-express-error-code-0x800c0133/