synchronize two address-list certain time

I need that, sync two address-list every so often, some form? No idea how I … Obviously they are two separate mikritok two different X86 …

you could give some details - like both lists are updated independently, and then has to be synced, or only one of them is updated, and other should contain the entries. So, how is it?

Hi!

There is a similar task.
All changes happen on master ROS, on slave lists only are copied.
Prompt how probably to make?

you will have to make some external tool to do that. You can look at API or scripting. My choice would be to make API and database to synchronize and push only changes.

I know this is a late reply, but I had the same problem. The address lists that I need to sync are fairly small so I managed to do it by scripting on both routers.

Script available from:http://binaryheartbeat.blogspot.com/2015/03/mirkotik-synchronize-address-list.html

If you use an API application, you don’t even need to schedule a sync. You can keep the API connection on, and sync as soon as an item is added or removed to the address list.

e.g. with PHP (run from command line, not a web page!)

<?php
use PEAR2\Net\RouterOS;

require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';

$master = new RouterOS\Client('master-router-ip', 'admin', 'password');
$slaveUtil = new RouterOS\Util($slave = new RouterOS\Client('slave-router-ip', 'admin', 'password'));
$slaveUtil->setMenu('/ip firewall address-list');

$addressLists = array('List1', 'List2');

$master->sendAsync(
    new RouterOS\Request('/ip firewall address-list listen'),
    function ($response) use ($addressLists, $slave, $slaveUtil) {
        if (in_array($response('list'), $addressLists, true)) {
            if (null !== $response('.dead')) {
                //Removed
                $slaveUtil->remove(
                    $slaveUtil->find(
                        RouterOS\Query::where('list', $response('list'))->andWhere('address', $response('address'))
                    )
                );
            } else {
                //Added
                $slaveUtil->add(
                    array(
                        'list' => $response('list'),
                        'address' => $response('address')
                    )
                );
            }
        }
    }
);
$master->loop(); 

Or if you insist on not using a 3rd device, you can use something similar to jurgenskrause’s suggestion… Except that his can be implemented in a more simple and efficient fashion…

On the master, schedule:

#Semicolon separated list of Address Lists you want to sync
:local lists {"List1";"List2"}

#Filename of export (must match receiving router import filename)
:local exportFile "ExportAddressList.rsc"

:local fileContents "/ip firewall address-list\n"
:foreach i in=$lists do={
    :set $fileContents ($fileContents . "remove [find list=\"" . $i . "\"]\n")
    :foreach j in=[/ip firewall address-list print as-value where list=$i] do={
        :set $fileContents ($fileContents . "add list=\"" . ($j->"list") . "\" address=\"" . ($j->"address") . "\"\n")
    }
}

#Only the first time
:if ([/file print count-only where name=$exportFile] = 0) {
    /file print file=$exportFile
    :delay 2s
}

/file set $exportFile contents=$fileContents

On slave, schedule:

#Filename of export (must match receiving router import filename)
 :local importFile "ExportAddressList.rsc"

 #IP Address of router with existing address list(s)
 :local hostIP 1.2.3.4

 #FTP Username and Password
 :local ftpUser username
 :local ftpPassword userpassword

 /tool fetch address=$hostIP src-path=$importFile dst-path=$importFile mode=ftp user=$ftpUser password=$ftpPassword
 /import $importFile

Clearly boen_robot has far more Mikrotik Scripting experience, that is a very neat solution indeed.

How would you go about (in the second example), making sure that entries are also removed?

Oh. Yeah… I should’ve added a remove there… OK, I’ve fixed it above, so that the old address list is cleared before the items are (re)added.

Hi. I try to synchronize by example 1, and I get this error:

PHP Fatal error:  Uncaught exception 'PEAR2\Net\RouterOS\DataFlowException' with message 'Asynchonous commands must have a tag.' in phar:///home/kolan/sync/PEAR2_Net_RouterOS-1.0.0b5.phar/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/RouterOS/Client.php:359
Stack trace:
#0 /home/kolan/sync/sync.php(34): PEAR2\Net\RouterOS\Client->sendAsync(Object(PEAR2\Net\RouterOS\Request), Object(Closure))
#1 {main}
  thrown in phar:///home/kolan/sync/PEAR2_Net_RouterOS-1.0.0b5.phar/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/RouterOS/Client.php on line 359

what I’m doing wrong?)