IRedMail/FAQ/Backup

From iRedMail

(Difference between revisions)
Jump to: navigation, search
(How to restore from LDIF file)
Line 163: Line 163:
* Remove whole data in OpenLDAP data directory defined in LDAP config file "slapd.conf". For example:
* Remove whole data in OpenLDAP data directory defined in LDAP config file "slapd.conf". For example:
{{cfg|/etc/openldap/slapd.conf|<pre>
{{cfg|/etc/openldap/slapd.conf|<pre>
 +
...
database    bdb
database    bdb
suffix      dc=iredmail,dc=org
suffix      dc=iredmail,dc=org
directory  /var/lib/ldap/iredmail.org
directory  /var/lib/ldap/iredmail.org
-
 
+
...
-
rootdn      cn=Manager,dc=iredmail,dc=org
+
-
rootpw      {SSHA}x3u+xafd0npLHGuLEsIUXgGqbClzjg9x
+
</pre>}}
</pre>}}
-
So you should remove all files in directory '''"/var/lib/ldap/iredmail.org"'''. But don't remove this directory itself.
+
So you should remove all files under directory '''"/var/lib/ldap/iredmail.org"'''. But don't remove this directory itself.
* Make sure OpenLDAP server is '''NOT''' running, then restore backup LDIF file with command '''"slapadd"'''.
* Make sure OpenLDAP server is '''NOT''' running, then restore backup LDIF file with command '''"slapadd"'''.

Revision as of 12:45, 12 April 2012

Contents


Backup MySQL Databases

Backup with shell script

iRedMail ships a shell script to help backup MySQL databases: iRedMail-x.y.z/tools/backup_mysql.sh. You can always get the latest version from source code repo here: https://bitbucket.org/zhb/iredmail/src

Please read header of this file carefully before you execute it:

# Purpose:  Backup specified mysql databases with command 'mysqldump'.

###########################
# REQUIREMENTS
###########################
#
#   * Required commands:
#       + mysqldump
#       + du
#       + bzip2 or gzip     # If bzip2 is not available, change 'CMD_COMPRESS'
#                           # to use 'gzip'.
#

###########################
# USAGE
###########################
#
#   * It stores all backup copies in directory '/backup' by default, you can
#     change it in variable $BACKUP_ROOTDIR below.
#
#   * Set correct values for below variables:
#
#       BACKUP_ROOTDIR
#       MYSQL_USER
#       MYSQL_PASSWD
#       DATABASES
#       DB_CHARACTER_SET
#       COMPRESS
#       DELETE_PLAIN_SQL_FILE
#
#   * Add crontab job for root user (or whatever user you want):
#
#       # crontab -e -u root
#       1   4   *   *   *   bash /path/to/backup_mysql.sh
#   
#   * Make sure 'crond' service is running, and will start automatically when
#     system startup:
#
#       # ---- On RHEL/CentOS ----
#       # chkconfig --level 345 crond on
#       # /etc/init.d/crond status
#
#       # ---- On Debian/Ubuntu ----
#       # update-rc.d cron defaults
#       # /etc/init.d/cron status
#

###########################
# DIRECTORY STRUCTURE
###########################
#
#   $BACKUP_ROOTDIR             # Default is /backup
#       |- mysql/               # Used to store all backed up databases.
#           |- YEAR.MONTH/
#               |- YEAR.MONTH.DAY/
#                   |- DB.YEAR.MONTH.DAY.MIN.HOUR.SECOND.sql
#                               # Backup copy, plain SQL file.
#                               # Note: it will be removed immediately after
#                               # it was compressed with success and 
#                               # DELETE_PLAIN_SQL_FILE='YES'
#
#                   |- DB.YEAR.MONTH.DAY.HOUR.MINUTE.SECOND.sql.bz2
#                               # Backup copy, compressed SQL file.
#
#       |- logs/
#           |- YEAR.MONTH/
#               |- mysql-YEAR.MONTH.DAY.MIN.HOUR.SECOND.log     # Log file
#

Backup OpenLDAP Data

Backup with shell script

iRedMail ships a shell script to help backup OpenLDAP data: iRedMail-x.y.z/tools/backup_openldap.sh. You can always get the latest version from source code repo here: https://bitbucket.org/zhb/iredmail/src

Please read header of this file carefully before you execute it:

# Purpose:  Dump whole LDAP tree with command 'slapcat'.

###########################
# REQUIREMENTS
###########################
#
#   * Required commands:
#       + slapcat
#       + du
#       + bzip2 or gzip     # If bzip2 is not available, change 'CMD_COMPRESS'
#                           # to use 'gzip'.
#

###########################
# USAGE
###########################
#
#   * It stores all backup copies in directory '/backup' by default, you can
#     change it in variable $BACKUP_ROOTDIR below.
#
#   * Set correct values for below variables:
#
#       BACKUP_ROOTDIR
#       COMPRESS
#       DELETE_PLAIN_SQL_FILE
#
#   * Add crontab job for root user (or whatever user you want):
#
#       # crontab -e -u root
#       1   4   *   *   *   bash /path/to/backup_openldap.sh
#   
#   * Make sure 'crond' service is running, and will start automatically when
#     system startup:
#
#       # ---- On RHEL/CentOS ----
#       # chkconfig --level 345 crond on
#       # /etc/init.d/crond status
#
#       # ---- On Debian/Ubuntu ----
#       # update-rc.d cron defaults
#       # /etc/init.d/cron status
#

###########################
# DIRECTORY STRUCTURE
###########################
#
#   $BACKUP_ROOTDIR             # Default is /backup
#       |- ldap/                # Used to store all backed up copies.
#           |- YEAR.MONTH/
#               |- YEAR.MONTH.DAY/
#                   |- YEAR.MONTH.DAY.MIN.HOUR.SECOND.ldif
#                               # Backup copy, plain LDIF file.
#                               # Note: it will be removed immediately after
#                               # it was compressed with success and 
#                               # DELETE_PLAIN_SQL_FILE='YES'
#
#                   |- YEAR.MONTH.DAY.HOUR.MINUTE.SECOND.ldif.bz2
#                               # Backup copy, compressed LDIF file.
#
#       |- logs/
#           |- YEAR.MONTH/
#               |- ldap-YEAR.MONTH.DAY.MIN.HOUR.SECOND.log     # Log file
#

How to restore from LDIF file

Command "slapcat" will dump whole LDAP tree, so you can restore the whole tree with another command "slapadd".

Below example shows how to restore the whole LDAP tree on RHEL/CentOS 5.x.

  • Stop OpenLDAP server:
Terminal:
# /etc/init.d/ldap stop
  • Remove whole data in OpenLDAP data directory defined in LDAP config file "slapd.conf". For example:
File: /etc/openldap/slapd.conf
...
database    bdb
suffix      dc=iredmail,dc=org
directory   /var/lib/ldap/iredmail.org
...

So you should remove all files under directory "/var/lib/ldap/iredmail.org". But don't remove this directory itself.

  • Make sure OpenLDAP server is NOT running, then restore backup LDIF file with command "slapadd".
Terminal:
# slapadd -f /etc/openldap/slapd.conf -l /path/to/backup/backup.ldif
  • It's OK to start OpenLDAP server now, but it will report several errors like below:
Terminal:
# /etc/init.d/ldap start
Stopping slapd:                                            [  OK  ]
/var/lib/ldap/iredmail.org/mailMessageStore.bdb is not owned[WARNING]"
/var/lib/ldap/iredmail.org/objectClass.bdb is not owned by "[WARNING]
/var/lib/ldap/iredmail.org/mtaTransport.bdb is not owned by [WARNING]
/var/lib/ldap/iredmail.org/cn.bdb is not owned by "ldap"    [WARNING]
/var/lib/ldap/iredmail.org/domainName.bdb is not owned by "l[WARNING]
/var/lib/ldap/iredmail.org/ou.bdb is not owned by "ldap"    [WARNING]
/var/lib/ldap/iredmail.org/uid.bdb is not owned by "ldap"   [WARNING]
/var/lib/ldap/iredmail.org/enabledService.bdb is not owned b[WARNING]
/var/lib/ldap/iredmail.org/homeDirectory.bdb is not owned by[WARNING]
/var/lib/ldap/iredmail.org/domainGlobalAdmin.bdb is not owne[WARNING]p"
/var/lib/ldap/iredmail.org/sn.bdb is not owned by "ldap"    [WARNING]
/var/lib/ldap/iredmail.org/mail.bdb is not owned by "ldap"  [WARNING]
/var/lib/ldap/iredmail.org/accountStatus.bdb is not owned by[WARNING]
/var/lib/ldap/iredmail.org/givenName.bdb is not owned by "ld[WARNING]
Checking configuration files for slapd:  config file testing succeeded
                                                           [  OK  ]
Starting slapd:                                            [  OK  ]

You must set correct file permission on newly created bdb files immediately, then restart OpenLDAP service. It won't complain incorrect file permission any more:

Terminal:
# chown ldap:ldap /var/lib/ldap/iredmail.org/*.bdb
# /etc/init.d/ldap restart

That's all.

Personal tools