View Single Post
  #1  
Old 11th November 2010, 16:33
Newton.Tricko.Com.Br Newton.Tricko.Com.Br is offline
Junior Member
 
Join Date: Nov 2010
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Thumbs up Howto create a MX Backup to your ISPConfig 2 with automatically sync

Dear all,

I am so happy now to say: that is my first post and my first contribuition to ISPConfig project.

I hope it may help somebody to do that more fast than normal, that is my proposal.

What you will receive at end of this Howto is a MX backup to your hosted domains over the main ISPConfig 2.

I hope you know, but never is too much say again, what you need.

1 - You need a complete ISPConfig 2 operating and running
2 - Another machine with Postfix installed and running, you just need Postfix running at that other machine, that machine will be the MX backup.

Letīs get started!

The steps bellow must be followed on the ISPConfig2 machine.

1 - First, create a new user on your MySQL server named "isp-mx-backup".

2 - Be carefull with the privileges, allow access from the other machine only then grant permission to SELECT on ISPConfig2 database and "isp_isp_web" table.

The steps bellow must be followed on the other machine with Postfix.

1 - Create the query domains script at /root/ispconfig/getMXDomains.php:
Code:
#!/usr/bin/php
<?
  $ispconfigHost = '192.168.0.1'; // set the IP or HOSTNAME to your ISPConfig2
  $ispconfigUser = 'isp-mx-backup'; // change if you created another username than the sugestted
  $ispconfigPass = 'password'; // change to the password of the user
  $ispconfigBase = 'db_ispconfig'; // change to the database name of ISPConfig2

/* No changes needed for the next lines */

  mysql_connect($ispconfigHost,$ispconfigUser,$ispconfigPass) or die('Cannot connect');
  mysql_select_db($ispconfigBase) or die('Cannot select db');
  
  $sql = "SELECT `web_domain` domain FROM `isp_isp_web` WHERE `web_dns_mx`=1";
  $query = mysql_query($sql);
  $num = mysql_num_rows($query);
  if ($num>0){
    $conf = "relay_domains=\"\\\$mydestination";
    while ($data = mysql_fetch_assoc($query)) {
        $conf .= ",{$data['domain']}";
    }
    $conf .= "\"";
  }
  exec("postconf -e {$conf}");
  exec("postconf -e relay_recipient_maps=\"\"");
  exec("/etc/init.d/postfix reload");
  
  mysql_close();
?>
Obs: You may change the interpreter line to the properly path to PHP, if you are not using CentOS distro or RedHat based distro.

2 - Grant execution permission to this script
Code:
chmod +x /root/ispconfig/getMXDomains.php
3 - Put this script to your cronjob
Code:
* */01 * * * /root/ispconfig/getMXDomains.php
4 - Now after create a new domain you must create a new MX entry, the priority must be high then the primary (your ISPConfig 2).

Feel free to comment.

I hope it helps!

Regards!

Last edited by Newton.Tricko.Com.Br; 11th November 2010 at 17:13. Reason: Forget the one step
Reply With Quote
Sponsored Links