Topic: iRedmail server restore
==== Required information ====
- iRedMail version: 0.9.0
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): LDAP
- Linux/BSD distribution name and version: Ubuntu 14.04
- Related log if you're reporting an issue:
====
Hello ,
I was looking for some easy steps to restore iRedmail server I found this script but it's not working with me if we look into it and get it to work it will be great thing for the community
this code is not mine all the credit goes to Ted (http://www.coxbros.us/wiki/index.php/Ted's_iRedMail_LDAP_Restore_Script) :
#!/bin/bash
#
# iRedMail LDAP Restore
# - uses slapcat restore
# - based on:
# http://www.iredmail.org/wiki/index.php?title=IRedMail/FAQ/Backup#How_to_restore_from_LDIF_file
BACKUPFILE="2013.01.29.03.00.02.ldif"
iRedMailDir="/root/iRedMail-0.8.3"
BACKUPDIR="/root/ldap_backup" # No Trailing Slash!
BACKUPYR=`date | awk -F' ' {'printf("%s\n"), $6'};`
BACKUPM=`date | awk -F' ' {'printf("%s\n"), $2'};`
# Not the most elegant solution, but it works
# Put together all of the above to create a path
BACKUPPATH=`echo $BACKUPDIR"/"$BACKUPYR"/"$BACKUPM"/";`
SERVICE=slapd;
SERVICECMD=/sbin/service;
SLAPD=/etc/openldap/slapd.conf
LDAPDIRPATH=/var/lib/ldap/heroesinc.us
SLAPADD=`which slapadd`
# Get Started
echo ""
echo "Beginning LDAP Restoration..."
# Ensure the backup directory exists and go there.
if [ -d $BACKUPPATH ]
then
echo "Directory $BACKUPPATH exists!"
cd $BACKUPPATH
else
echo "Creating directory $BACKUPPATH"
mkdir -p $BACKUPPATH
cd $BACKUPPATH
fi
# Ensure backup exists or go fetch it.
if [ -f $BACKUPFILE ]
then
echo "Found $BACKUPFILE!"
else
echo "ERROR: Please copy your LDIF file to $BACKUPPATH. Exiting..."
exit
fi
# Ensure LDAP Server is NOT running!!!
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "$SERVICE service running, shutting it down..."
$SERVICECMD $SERVICE stop
else
echo "$SERVICE is not running..."
fi
# Backup old LDAP dbs
# This doesn't work:
#
#echo "Determine ldap path..."
#TDCTMP=`cat $SLAPD | grep directory | awk -F" " {'printf("%s\n"), $2'};`
#LDAPDIRPATH=`echo $TDCTMP | awk -F"\n" {'printf("%s\n"), $1'};`
#echo "... path is $LDAPDIRPATH"
if [ "$(ls -A $LDAPDIRPATH)" ]; then
echo "Moving old LDAP data from $LDAPDIRPATH to $BACKUPPATH"
mv $LDAPDIRPATH/* $BACKUPPATH
else
echo "ERROR: $LDAPDIRPATH is empty, data missing."
echo " exiting."
exit
fi
# Check for successful backup
echo "Verifying Backup..."
if [ "$(ls -A $LDAPDIRPATH)" ]; then
echo "ERROR: $LDAPDIRPATH is not Empty, backup failed! Exiting..."
exit
else
echo "$LDAPDIRPATH is Empty, backup verified."
fi
# Restore new db
echo "Restoring database..."
cp $BACKUPPATH/DB_CONFIG $LDAPDIRPATH
$SLAPADD -f $SLAPD -l $BACKUPPATH/$BACKUPFILE
# fix permissions
chown ldap:ldap $LDAPDIRPATH/*
# Restart LDAP db
$SERVICECMD $SERVICE start
$SERVICECMD $SERVICE restart
echo "Restore Complete!"
echo "Now login to phpLDAPAdmin and reset the passwords for vmail and vmailadmin to these:"
cat $iRedMailDir/iRedmail.tips | grep cn=vmail
----
Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.