Replacing config without reboot

I’m working on some code (existing framework) that needs to merge and replace configuration on the router. The merge part is straightforward, but the replace part isn’t AFAIK. I’ve read http://wiki.mikrotik.com/wiki/Manual:Configuration_Management and it offers no solutions.

Does anyone have any clever ways to replace the whole config while keeping the router from rebooting? I realise this could lead to a drop in connectivity if the new configuration doesn’t use the same IP address but you have the same issue with merging config as well.

RouterOS config is done in real time, reboot is not required. What kind of config are you talking about? Some connections would have to time out, but other than that, mostly you can do it on a live router.

By replace, I mean clear the existing configuration and apply the new one (the equivalent of configure replace in IOS - https://supportforums.cisco.com/document/29696/using-configure-replace-command). My understanding is that the only way to do this would be /system reset-configuration with the new configuration applied using run-after-reset. This of course requires a reset.

I was hoping there might be a way to do it without a reset.

It should be possible to write a program that, from an external computer, sends a /export command to the router, retrieves the
config, does a diff to the new config, and then generates the commands to send to the router to transform the old config
into the new one. That way it is possible to change the config without a reboot.

I’ve looked into the “diff” option but it’s non-trivial - IMHO you need to implement a full parser to do it.

For example, if I send the configuration

/interface set loop comment=“Test Comment”

what is the diff if the configuration is

/interface bridge add name=loop mtu=2000

You also have to cope with the fact that things are keyed on “name” for interfaces but other keys for other sections of the configuration (“list”, “dst-address” etc). As I say, by the time you special case it all you’ve written a parser.


Matt.

I don’t know what you want to achieve, a fully working replace config with anything or a system for practical
use where you e.g. replace or add some firewall rules, addresses, etc.
I think when you want to support a complete reconfiguration including different interface names etc, it is not
reasonable to expect to do it without a reboot.
Change without a reboot should be expected only for incremental changes as they occur during maintenance.

Of course (but it looks like you already considered that), before doing the diff you first need to “flatten” the
config by adding the “/command subcommand” to every “set” and “add” line, and unwrapping the \ line wraps.
I already wrote a perl script to do that, which I use when comparing different router configurations or when
searching for certain patterns in a collection of configurations.

But you are right, doing the changes can be a little complicated in some cases. Especially because in some
situations you need to preserve the order of added items. However, it should be possible to do it.