Community discussions

MikroTik App
 
msatter
Forum Guru
Forum Guru
Topic Author
Posts: 2897
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

[Project] SMART configuration export/import

Sun Sep 05, 2021 8:36 am

I want to start a project which tackles the export not being flexible enough to be used as basic backup and restore option. The current full backup option provided by Mikrotik is sometimes broken and then all the backups made are binned. It is wise to make always also exports on big changes so you can manually restore the configuration you worked so hard on to get right.

It would be nice if Mikrotik would share the script to make the normal export so we don't have to find out on our own how to walk the tree of all the sections in the configuration.

An example (not working) how an smartimport file could look
local keywords "raw led dhcp"
local replace "filter nat mangle raw"
local skip false
:local section do={:if ($1 in $keywords) do={local skip true; local selected $1} else={$1; local skip false; :if ($1 in $replace) do={remove [find]} } on-error={:log warning "Section $1 not available on this device"; local skip true}
:local replace do={$1} on-error={:log error "Section $1 not available on this device. IMPORT ABORTED!!"; :error }
:local toadd do={:if (skip = false) do={add $1} else={:log warning "Skipped adding $1 in $selected"}} on-error={:log warning "Line $1 could not be added in $selected"}
:local toset do={:if (skip = false) do={set $1} else={:log warning "Skipped setting $1 in $selected"}} on-error={:log warning "Line $1 could not be set in $selected"}

$section "/ip firewall mangle"
$toadd "comment=nothing"
$toadd "comment=nothing"
$section "/ip firewall RAW"
$toadd "comment=nothing"
$toadd "comment=nothing"
$section "/interface ethernet switch port"
$toset "0 default-vlan-id=0"
$toset "1 default-vlan-id=0"
$toset "2 default-vlan-id=0"
$replace "/system script"
add comment=nothing
add comment=nothing
I have scripting to create the export lines if I have each line in variable and write those to a file and rename it afterwards "rsc.txt" to "rsc".

So everyone, and I mean everyone, who want to help in coding this is welcome to chime in is welcome!

Started by this request made: viewtopic.php?f=1&t=178045#p877044
Last edited by msatter on Mon Sep 06, 2021 9:11 am, edited 4 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: [Project] SMART configuration export/import

Sun Sep 05, 2021 10:14 am

Are you sure everyone???...

Better split the project on parts, for reassemble it together later, or too many things go on field, and cause only confusion and problem.

example
Part 1) Choose the "right" export format to be used: better export non-terse (default) or terse, better non-verbose (default compact) or verbose?
Part 2) How to identify sections: wireless for interface/wireless, ntp for system/ntp, user is keyword for system users, user-manager?
Better use explicit sections "/interface bridge"?
Part 3) Export to file only multiple selected sections (already possible only single section/subtree), Import from full file only specfic sections.
Part 4) On export modify - add - remove - option to censore some username / password / email fields (hide-sensitive do not cover all sensible fields)
Part 5) adapt syntax changes on import / export: not full list, but only some examples here: viewtopic.php?f=1&t=177714&p=873532&hil ... ge#p873532
Part 6) Modify values on the fly on Imported sections.
After done part 6 check what remain to do at the point.
 
msatter
Forum Guru
Forum Guru
Topic Author
Posts: 2897
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: [Project] SMART configuration export/import

Sun Sep 05, 2021 12:18 pm

1 This for later and if it comes with the export script by Mikrotik then it is handled in one go.
2 The keywords are now in a string but the should be in an array so matching is unique
3 See point one.
4 The onset is to have this for internal use and if for external, then for export also keywords that should not be written.
5 Same limitations as backup. However Mikrotik is having an conversion routine when you import a backup from 6 in 7.
6 I think that is out of scope and you will have to modify the RSC export file manually.

I think I have write support to ask for the export script that will advance this greatly so that it can be adapted to a 'smart'-export....support request created.

Schedules, scipts and any other lines that contain " can't be send to a function or is troublesome to send. Those will be in the export keywords (/system schedule). Manual import is no problem so there could be an option leave those untouched and use normal import. They can be in the same file and just add but the remove first can be triggered by the $section.

Update the example script with replace but that one is tricky and needs testing. I left out the first remove because of that. Added :error to stop processing after logging the cause.
 
msatter
Forum Guru
Forum Guru
Topic Author
Posts: 2897
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: [Project] SMART configuration export/import

Tue Sep 21, 2021 3:24 pm

Got a final answer from support and they can't help more than they already did.

Support points to the list of consultants with whivh I can get premium sopport.

With help op support I already managed to extract a partial structure, from default config. A complete export is to big to fit in an array so I am stuck on that.
Exporting to an external location and reading back in chunks or if possible read directly from file.

Who is online

Users browsing this forum: ko00000000001 and 16 guests