Community discussions

MikroTik App
 
petterg
Member Candidate
Member Candidate
Topic Author
Posts: 230
Joined: Wed Sep 16, 2009 2:55 pm

Partial export / import of config

Sun Dec 02, 2012 4:19 am

I'm thinking of syncing firewall rules between two routers, and I came across the method explained in the last post of this thread: http://forum.mikrotik.com/viewtopic.php?f=2&t=59240

But how can I sync only some of the rules?

I was thinking one way to go would be to prefix the comment of all the rules that I want to sync with the text "sync". So on the source router the script could be
/ip firewall filter export file="EXPORT.FW_filters" [find comment ~"^sync.*"]
and on the destination router the script could be
/tool fetch mode=tftp address=MAIN_ROUTER_IP src-path=EXPORT.FW_filter.rsc
#TODO: do some errorcheck here. Abort script if file not downloaded ok
/ip firewall filter remove [find comment ~"^sync.*"]
/import file=EXPORT.FW_Lists.rsc
/file remove EXPORT.FW_Lists.rsc
Now the issue is, export seems not to allow the use of find to limit what is exported. How can I get around this issue?

I found some examples that were 10 years old where they used
export from=1,4
which apparently exported a selection of rules. That syntax seems not to be valid any more.
 
petterg
Member Candidate
Member Candidate
Topic Author
Posts: 230
Joined: Wed Sep 16, 2009 2:55 pm

Re: Partial export / import of config

Mon Dec 03, 2012 12:06 pm

bump
 
petterg
Member Candidate
Member Candidate
Topic Author
Posts: 230
Joined: Wed Sep 16, 2009 2:55 pm

Re: Partial export / import of config

Mon Dec 03, 2012 3:59 pm

I guess the lack of replies to this thread is because it's not possible to filter on export.

What about textfile editing? Is it possible to make a script that extracts only some of the lines from the export file into a new file that can be used for import?

What I need is something similar to
cat export.rsc |grep "comment=sync" > import.rsc
So how can the grep functionality be performed in routeros?
 
jaduke
just joined
Posts: 11
Joined: Sat Nov 24, 2012 12:39 am

Re: Partial export / import of config

Mon Dec 03, 2012 8:30 pm

I guess the lack of replies to this thread is because it's not possible to filter on export.

What about textfile editing? Is it possible to make a script that extracts only some of the lines from the export file into a new file that can be used for import?

What I need is something similar to
cat export.rsc |grep "comment=sync" > import.rsc
So how can the grep functionality be performed in routeros?
I think you'll need to download the export file to a local system, delete the rules that you don't need/want either manually or via grep, then upload that to the destination router for import.

Since it seems that the format of the export is basically a script to be executed on the destination, you should be fine with the process outlined above.

Cheers,
Jon
 
petterg
Member Candidate
Member Candidate
Topic Author
Posts: 230
Joined: Wed Sep 16, 2009 2:55 pm

Re: Partial export / import of config

Tue Dec 04, 2012 12:01 pm

Except that grep does not exist in routeros. What would a command to perform something similar to grep on a file look like in routeros?
 
jaduke
just joined
Posts: 11
Joined: Sat Nov 24, 2012 12:39 am

Re: Partial export / import of config

Tue Dec 04, 2012 10:26 pm

Except that grep does not exist in routeros. What would a command to perform something similar to grep on a file look like in routeros?
Grep, as far as I know, does not exist in ROS, but once you download the file, you can grep it locally, modifying it to your specification for the new device import. That was what I was trying to say above.

Cheers,
Jon
 
petterg
Member Candidate
Member Candidate
Topic Author
Posts: 230
Joined: Wed Sep 16, 2009 2:55 pm

Re: Partial export / import of config

Wed Dec 05, 2012 3:46 pm

I want this to be a script. If I have to do things on my pc in order to run the script, it's kind of pointless to use a script. Then it would be easier to do all changes on both routers manually.

Who is online

Users browsing this forum: FurfangosFrigyes, Laxity, shahzaddj1 and 175 guests