Community discussions

MikroTik App
用户头像
Jotne
Forum Guru
Forum Guru
Topic Author
Posts: 3218
Joined: Sat Dec 24, 2016 11:17 am
Location:Magrathean

Gmail v1.6备份配置[SOLVED]

Fri Feb 25, 2022 9:03 pm

Backup script to send config to Gmail account.
Code:Select all
# # Created Jotne 2023 v1.6 # # 1.6 Fixed script for x86 devicews (Credit rextended) # 1.5 Fixed for router missing serial # 1.4 Added Router OS version # 1.3r Revised by rextended # 1.3 / 1.2 try to fix v6/v7 compability # 1.1 added "show-sensitive" # 1.0 initial release # # Takes two different backup and send then to email # # backup.rsc readable backup # Certificates, the Dude and Usermanager are also NOT exported or backed up fully and should be backed up separately # Can be used to restore config to different routers # # backup.bin binary backup # Binary backup that can only be used to fully restored the same router. # :local email "@gmail.com" :local rscfn "backup" :local bakfn "bin" /system :local date [clock get date] :local time [clock get time] :local info [identity get name] :local board ([resource get board-name]) :local files "$rscfn.rsc,$bakfn.backup" :local Version [resource get version] /system :local serial "undefined" :if (!($board~"(x86|CHR)")) do={ :global testrbsn "NO RouterBOARD" :execute ":global testrbsn; :set testrbsn [/system routerboard get serial-number]" :delay 1s :set serial $testrbsn :set testrbsn } else={ :if ($board="x86") do={:set serial [license get software-id]} :if ($board="CHR") do={:set serial [license get system-id]} } :if ($Version~"^7") do={ [:parse "/export show-sensitive file=$rscfn.rsc"] } else={ /export file="$rscfn.rsc" } :delay 2s /system backup save name="$bakfn" :delay 2s /tool e-mail send to="$email" subject="Mikrotik: Backup $info $Version $serial" file="$files" body="Automatic Backup of $info $serial at $date $time" :delay 20s :execute "/file remove $files" :log info "Backup router=$info serial=$serial ok"

PS Since gmail are free, I suggest you make a new email for your backup files.

----------------------------------------------------------------------------------------
UseSplunk>to log/monitor your雷竞技网站Router(s). See link below.:mrgreen:

MikroTik->Splunk
Last edited byJotneon Mon Apr 03, 2023 9:55 am, edited 10 times in total.
Top
用户头像
Amm0
Forum Guru
Forum Guru
Posts: 2251
Joined: Sun May 01, 2016 7:12 pm
Location:California

Re: Script comparability v6<->v7 problems

Fri Feb 25, 2022 11:11 pm

Their syntax checker kicks in... But you could still cheat with [:parse ":export ..."].
Code:Select all
{ :local vermajor [:tonum [:pick [/system resource get version] 0 1]] :if ($vermajor > 6) do={ [:parse "export show-sensitive file=backup.rsc"] } else={ :export file=backup.rsc } }
I always thought it strange they didn't just add "show-sensitive" as option in the V6 codeline, even if it's implied in V6. That wouldn't break annoying thing in V6, but avoid needing a stupid [:parse ""] thing for a common task. (and yes, I'm sure they need to deal with BOTH show-sensitive and hide-sensitive in V6, but scripts would then be portable between V6/V7)
Top
用户头像
Jotne
Forum Guru
Forum Guru
Topic Author
Posts: 3218
Joined: Sat Dec 24, 2016 11:17 am
Location:Magrathean

Re: Script comparability v6<->v7 problems

Sat Feb 26, 2022 12:29 am

Perfect. Did learn some new today, so thank you for the help:)

Was just what I needed and have tested the script on various version and works fine.
Code:Select all
# # Created Jotne 2022 v1.3 # # 1.1 Added "show-sensitive" # 1.3 Fixed v6/v7 compability # # Takes two different backup and send then to email # # backup.rsc readable backup # Certificates, the Dude and Usermanager are also NOT exported or backed up fully and should be backed up separately. Can be used to restore config to different routers # # backup.bin binary backup # Binary backup that can only be used to fully restored the same router. # :local email "@gmail.com" :if ([:tonum [:pick [/system resource get version] 0 1]] > 6) do={ [:parse "export show-sensitive file=backup.rsc"] } else={ :export file=backup.rsc } :delay 2s /system backup save name=bin :delay 2s :local date [/system clock get date] :local time [/system clock get time] :local info [/system identity get name] :local serial [/system routerboard get serial-number] :local files "backup.rsc,bin.backup" /tool e-mail send to="$email" subject="Mikrotik: Backup $info $serial" file=$files body="Automatic Backup of $info $serial at $date $time." :delay 20s /file remove backup.rsc /file remove bin.backup :log info message="Backup router=$info serial=$serial ok"
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11426
Joined: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: Script comparability v6<->v7 problems

Sat Feb 26, 2022 10:48 am

[:parse "export show-sensitive file=backup.rsc"]
cause error on v6 because the presence of show-sensitive

edit: never cut with "..." again, cause confusion
Last edited byrextendedon Sun Feb 27, 2022 12:40 am, edited 4 times in total.
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11426
Joined: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: Script comparability v6<->v7 problems

Sat Feb 26, 2022 11:09 am

Revised by REX code

# # Created Jotne 2022 v1.3r # # 1.3r Revised by REX # 1.3 / 1.2 try to fix v6/v7 compability # 1.1 added "show-sensitive" # 1.0 initial release # # Takes two different backup and send then to email # # backup.rsc readable backup # Certificates, the Dude and Usermanager are also NOT exported or backed up fully and should be backed up separately # Can be used to restore config to different routers # # backup.bin binary backup # Binary backup that can only be used to fully restored the same router. # { :local email "@gmail.com" :local rscfn "backup" :local bakfn "bin" /system :local date [clock get date] :local time [clock get time] :local info [identity get name] :local serial [routerboard get serial-number] :local files "$rscfn.rsc,$bakfn.backup" /system resource :if ([get version]~"^7") do={ [:parse "/export show-sensitive file=$rscfn.rsc"] } else={ /export file="$rscfn.rsc" } :delay 2s /system backup save name="$bakfn" :delay 2s /tool e-mail send to="$email" subject="Mikrotik: Backup $info $serial" file="$files" body="Automatic Backup of $info $serial at $date $time" :delay 20s :execute "/file remove $files" :log info "Backup router=$info serial=$serial ok" }
Edit: put back the [ ] on :parse for v7 (invalid syntax but, thank to "if", never executed on v6)
Last edited byrextendedon Sun Feb 27, 2022 12:28 am, edited 6 times in total.
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11426
Joined: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: Script comparability v6<->v7 problems

Sat Feb 26, 2022 11:21 am

Related:
(not tested on v7)

save and restore global variables on reboot
viewtopic.php?f=9&t=170591&p=883422#p883422

Save RouterBOARD full backup of everything [configuration, certificates, host key, router users (no passwords), user-manager, dude, other files]
viewtopic.php?f=1&t=175360&p=858564#p858564


eidt:added note not tested on v7
Last edited byrextendedon Sun Feb 27, 2022 12:41 am, edited 2 times in total.
Top
用户头像
Jotne
Forum Guru
Forum Guru
Topic Author
Posts: 3218
Joined: Sat Dec 24, 2016 11:17 am
Location:Magrathean

Re: Script comparability v6<->v7 problems

Sat Feb 26, 2022 12:01 pm

Does not work. Tested in 7.1.2

Pasting this to terminal, does not give anything.
Code:Select all
:parse "/export show-sensitive file=test.rsc"
But this works:
Code:Select all
[:parse "/export show-sensitive file=test.rsc"]
Top
用户头像
Amm0
Forum Guru
Forum Guru
Posts: 2251
Joined: Sun May 01, 2016 7:12 pm
Location:California

Re: Script comparability v6<->v7 problems

Sat Feb 26, 2022 5:00 pm

We wouldn't be here if either V7 or V6 just ignored a meaningless "hide-sensitive" or "show-sensitive" – that seem like something MT should fix somehow...

Does not work. Tested in 7.1.2

Pasting this to terminal, does not give anything.
Code:Select all
:parse "/export show-sensitive file=test.rsc"
But this works:
Code:Select all
[:parse "/export show-sensitive file=test.rsc"]

":parse"alonecreates a :typeof "code", at "runtime". But the context that :parse used matters, since it acts more like a script do={} function – so it's more confusing than it appears. You can see the "code" type here:
Code:Select all
:put [:parse "/ip address print"] #(eval /ip address print) :put [:typeof [:parse "/ip address print"]] # code
Before my time in RouterOS, but believe ":parse" was a way to create functions before the ":global fn do={}" way. So if you view that ":parse " is same as do={}, then " :parse" is a definition of something runnable, why :parse at CLI doesn't run anything.
Top
用户头像
Jotne
Forum Guru
Forum Guru
Topic Author
Posts: 3218
Joined: Sat Dec 24, 2016 11:17 am
Location:Magrathean

Re: Script comparability v6<->v7 problems

Sat Feb 26, 2022 5:37 pm

My version do work at both 6 and 7. What do I need to make rextendeds script to work on 7.x?
Top
用户头像
Amm0
Forum Guru
Forum Guru
Posts: 2251
Joined: Sun May 01, 2016 7:12 pm
Location:California

Re: Script comparability v6<->v7 problems

Sat Feb 26, 2022 9:54 pm

My version do work at both 6 and 7. What do I need to make rextendeds script to work on 7.x?
@Jonte, which one, and what problem you having? I can offer what see in @rextended's examples below, but can't vouch that's all the V7 issues.

save and restore global variables on reboot
viewtopic.php?f=9&t=170591&p=883422#p883422

I didn't try this one, but I DO know it won't detect functions right in V7. "eval" is now "evl", here no :parse be needed, just different string to look for in V7 vs V6 to fix that one.
Code:Select all
:global x do={:put "blah"} # Version 7 it's ";evl(" that need to be :find /system script environment print detail where name=x # 3 name="x" value=";(evl (evl /putmessage=blah))" # But in Version 6, it's ";eval" that's @rextended uses /system script environment print detail where name=x # 1 name="x" value=";(eval (eval /putmessage=blah))"
Basically those are :typeof str, but represent the "compiled script" which why @rextended excludes them. Only issue how he's identifying them similar ":if ($majorversion>6) do={} else={}" thing.


Save RouterBOARD full backup of everything [configuration, certificates, host key, router users (no passwords), user-manager, dude, other files]
viewtopic.php?f=1&t=175360&p=858564#p858564
This one has a different problem. I don't know exactly why but the "$byemail ..." lines need be wrapped in a parenthesis. Only did a quick test, but changing the ALL the $byemail lines like this:
Code:Select all
# did not work in V7 $bymail $dsubj="Certificate $certname $date $time" $dfile="auto_$certname.p12" # works in V7 ($bymail $dsubj="Certificate $certname $date $time" $dfile="auto_$certname.p12") # NOTE: I'm not sure the $ in $dsubj= needed
I've found being using a "command subdirectory" to then "short form" find/get/set's sometimes causes odd issues in V7. Do something like "/certificate", then your code does make the script more human readable – but RouterOS "script compiler" seems to needs more help to figure stuff out when you do that. So putting commands or functions with parameters in parenthesis and/or brackets often helps MT's hidden script compiler. In theory, I wouldn't say you should need them, but the ($bymail ...) fixed @rextended's backup script on v7.2rc4 in my quick test.
Top
用户头像
Jotne
Forum Guru
Forum Guru
Topic Author
Posts: 3218
Joined: Sat Dec 24, 2016 11:17 am
Location:Magrathean

Re: Script comparability v6<->v7 problems

Sat Feb 26, 2022 10:11 pm

@Jonte, which one, and what problem you having? I can offer what see in @rextended's examples below, but can't vouch that's all the V7 issues.
My latest postet script do work on both 6 and 7, but version rextended posted does not work on v7.
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11426
Joined: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: Script comparability v6<->v7 problems

Sun Feb 27, 2022 12:24 am

My version do work at both 6 and 7. What do I need to make rextendeds script to work on 7.x?

(I have edited previous post)
The "related" link are not fully tested on v7 (see the dates of the posts...)

Ok, I understand why you do not understand:

The code itself is formally valid until not executed,
(for be more precise, is invalid the "show-sensitive" inside, not the use of the [ ])
the condition is never meet and never executed on v6
Put back [ ] on my "revision" work again on v7

我的修改只有解释一些“短的提示cut" or better style of coding...

For example: put / in front of export, because "export" export only current section.
:parse and :execute both consider / as start point, but if on future thath change, script is already ready...

Another example
all this
Code:Select all
if ([:tonum [:pick [/system resource get version] 0 1]] > 6) do={ # translated: pick one character from the start of the version string, convert it to a number, if the resulting number is greater than 6 do ...

can be replaced with simpler and fastly readable
Code:Select all
/system resource :if ([get version]~"^7") do={ # translated: if the version string contains "7" at the beginning do ...
it work until version 70.x do not come out on year 2345 (for fixit on year 2345, simply add \. at the end, if someone of us is stil alive...)
If sometime on the future 8.x come out, probably the syntax change again, but if on 8, 9, 10 etc, is identical, use something like "^(7|8|9|10)"


For precision (tested on 6.47.10):
:parse "export file=backup.rsc" on v6 do not work like on v7
[:parse "export file=backup.rsc"] this work on both (but on v7 the new default do not export the sensitive data)
[:parse "export show-sensitive file=backup.rsc"] work only on v7 and NOT on v6, because have show-sensitive inside, not recognized on v6
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11426
Joined: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: Script comparability v6<->v7 problems

Sun Feb 27, 2022 1:16 am


I didn't try this one, but I DO know it won't detect functions right in V7. "eval" is now "evl", here no :parse be needed, just different string to look for in V7 vs V6 to fix that one.
Code:Select all
:global x do={:put "blah"} # Version 7 it's ";evl(" that need to be :find /system script environment print detail where name=x # 3 name="x" value=";(evl (evl /putmessage=blah))" # But in Version 6, it's ";eval" that's @rextended uses /system script environment print detail where name=x # 1 name="x" value=";(eval (eval /putmessage=blah))"

probably the fix for work on both v6 and v7 is to replace

v6 only code

:if ([:typeof [:find $vvalue "(eval " -1]] = "nil") do={
with

v6 and v7 code

:if (([:typeof [:find $vvalue "(eval " -1]] = "nil") and ([:typeof [:find $vvalue "(evl " -1]] = "nil")) do={
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11426
Joined: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: Script comparability v6<->v7 problems

Sun Feb 27, 2022 1:42 am


This one has a different problem. I don't know exactly why but the "$byemail ..." lines need be wrapped in a parenthesis. Only did a quick test, but changing the ALL the $byemail lines like this:
Code:Select all
# did not work in V7 $bymail $dsubj="Certificate $certname $date $time" $dfile="auto_$certname.p12" # works in V7 ($bymail $dsubj="Certificate $certname $date $time" $dfile="auto_$certname.p12") # NOTE: I'm not sure the $ in $dsubj= needed
[...]

the ($bymail ...) fixed @rextended's backup script on v7.2rc4 in my quick test.

Thanks.

The correct syntax iswithout $in front of dsubj and dfile,
(caused for make consistant name of variables using replace $oldvarname with $newvarname, without removing $ when is not to be placed)
AND if used $var inside the strings, parenthesys ( ) must be used.
no need to use ( ) when the string not contain $varname
Thanks to you I just discover this strange behaviour.

Correct lines are (I have corrected the original script)
Code:Select all
$bymail dsubj=("Certificate $certname $date $time") dfile=("auto_$certname.p12") $bymail dsubj=("Host Key $date $time") dfile="auto_host-key_dsa,auto_host-key_dsa.pub,auto_host-key_rsa,auto_host-key_rsa.pub" $bymail dsubj=("User Export $date $time") dfile="auto_user_export.rsc" $bymail dsubj=("Backup $date $time") dfile="auto_backup.backup" $bymail dsubj=("Database User-Manager $date $time") dfile="auto_user-manager.umb" $bymail dsubj=("Database The Dude $date $time") dfile="auto_thedude.db"
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11426
Joined: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: Script comparability v6<->v7 problems

Sun Feb 27, 2022 2:08 am

[...] in V7. "eval" is now "evl", here no :parse be needed

I need to use this on v6
Code:Select all
:if ($vtype~"^(ip-prefix|ip6-prefix)\$") do={:execute ":global $vname [[:parse \":return $vvalue\"]]"}
because someone on the past broken the ":toip" function and for convert 1.1.1.0/27 to ip-prefix variable type I need to use this hack...

v6 ip-prefix example code

[rex@MATRIX] > :global test 1.1.1.0/24 [rex@MATRIX] > :put [:typeof $test] ip-prefix [rex@MATRIX] > :global test "1.1.1.0/24" [rex@MATRIX] > :put [:typeof $test] str [rex@MATRIX] > :global test [:toip "1.1.1.0/24"] [rex@MATRIX] > :put [:typeof $test] nil [rex@MATRIX] > :global test [[:parse ":return 1.1.1.0/24"]] [rex@MATRIX] > :put [:typeof $test] ip-prefix
Top
用户头像
Jotne
Forum Guru
Forum Guru
Topic Author
Posts: 3218
Joined: Sat Dec 24, 2016 11:17 am
Location:Magrathean

Re: Script comparability v6<->v7 problems

Sun Feb 27, 2022 11:31 am

Thanks for the update and explanation rextended:)
Now it work both on 7.x and 6.x
Top
msatter
Forum Guru
Forum Guru
Posts: 2853
Joined: Tue Feb 18, 2014 12:56 am
Location:Netherlands / Nīderlande

Re: Script comparability v6<->v7 problems

Sun Feb 27, 2022 12:54 pm

Sound familiar:viewtopic.php?p=881126&hilit=v7#p881126

It was a long time age...even before the Russian war.
Top
用户头像
Amm0
Forum Guru
Forum Guru
Posts: 2251
Joined: Sun May 01, 2016 7:12 pm
Location:California

Re: Script comparability v6<->v7 problems

Mon Feb 28, 2022 6:00 pm

Sound familiar:viewtopic.php?p=881126&hilit=v7#p881126

It was a long time age...even before the Russian war.
Yeah it not only ":export XXXX-sensitive" attributes that differ subtle ways. I've been using V7 as excuse to re-writing my V6 scripts as functions, which has worked out well so far: basically everything is aparameterized function. So if you combine [:parse] WITH a function to apply @rextended's route table fix in above post...

Code:Select all
:global rosmajorver [:tonum [:pick [/system resource get version] 0 1]] :global rtlookup :set $rtlookup do={ :if ($rosmajorver>6) do={ :return [[:parse "/routing table find where name=$1"]] } else={ :return $1 } } # >> :put [$rtlookup main] # *0

With that above your firewall script, like so:
Code:Select all
/ip firewall nat find where routing-mark=[$rtlookup "main"]

The function will hide the "ugly" :parse, and in theory you can use extend the above function to validate the route table for V6 etc. But using functions is how I've generically solve any some of oddities without a lot of ":if () do={}"'s everywhere.

Note: I know the code works for "main", but didn't test too much – more example of an approach to the next "show-sensitive".
Top
用户头像
Amm0
Forum Guru
Forum Guru
Posts: 2251
Joined: Sun May 01, 2016 7:12 pm
Location:California

Re: Script comparability v6<->v7 problems

Mon Feb 28, 2022 6:25 pm

[...] in V7. "eval" is now "evl", here no :parse be needed
I need to use this on v6
Code:Select all
:if ($vtype~"^(ip-prefix|ip6-prefix)\$") do={:execute ":global $vname [[:parse \":return $vvalue\"]]"}
because someone on the past broken the ":toip" function and for convert 1.1.1.0/27 to ip-prefix variable type I need to use this hack...
Oh that's a fun one! In the: "very cleaver solution, but annoying it's needed" category – but be a long wait for some ":toip-prefix" (or fixing/paramerizing :toip and other :toX) built-in.... Quite the path:
a :execute "background script", that's generated dynamically via :parse, to update a global variable used in the current – all because only a ":global" type definition will actually do a convert from string to a "ip[6]-prefix" type, BUT where you can define a global is limited. Somehow @rextended approach here does works, pretty nifty.
Top
用户头像
Jotne
Forum Guru
Forum Guru
Topic Author
Posts: 3218
Joined: Sat Dec 24, 2016 11:17 am
Location:Magrathean

Re: Backup config to Gmail v1.4

Mon May 09, 2022 10:35 am

Script updated to v1.4

Now also sends router version information in the subject. Faster to see when router was upgraded.
Code:Select all
# # Created Jotne 2022 v1.4 # # 1.4 Added Router OS version # 1.3r Revised by REX # 1.3 / 1.2 try to fix v6/v7 compability # 1.1 added "show-sensitive" # 1.0 initial release # # Takes two different backup and send then to email # # backup.rsc readable backup # Certificates, the Dude and Usermanager are also NOT exported or backed up fully and should be backed up separately # Can be used to restore config to different routers # # backup.bin binary backup # Binary backup that can only be used to fully restored the same router. # :local email "@gmail.com" :local rscfn "backup" :local bakfn "bin" /system :local date [clock get date] :local time [clock get time] :local info [identity get name] :local serial [routerboard get serial-number] :local files "$rscfn.rsc,$bakfn.backup" :local Version [resource get version] :if ($Version~"^7") do={ [:parse "/export show-sensitive file=$rscfn.rsc"] } else={ /export file="$rscfn.rsc" } :delay 2s /system backup save name="$bakfn" :delay 2s /tool e-mail send to="$email" subject="Mikrotik: Backup $info $Version $serial" file="$files" body="Automatic Backup of $info $serial at $date $time" :delay 20s :execute "/file remove $files" :log info "Backup router=$info serial=$serial ok"
Last edited byJotneon Mon May 09, 2022 12:27 pm, edited 1 time in total.
Top
用户头像
own3r1138
Long time Member
Long time Member
Posts: 669
Joined: Sun Feb 14, 2021 12:33 am
Location:Pleiades
Contact:

Re: Backup config to Gmail v1.4

Mon May 09, 2022 10:58 am

Hi,
Thanks for the post.
Can the binary version restore the user manager? if yes can it be used to restore between CHRs or it must be on the same machine.
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11426
Joined: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: Backup config to Gmail v1.4

Mon May 09, 2022 11:15 am

v6 or v7?

user-manager has is own separate databse, backup restore only customer, router, profiles and user, but without any profile assigned to users, sessions and the rest.
Top
用户头像
own3r1138
Long time Member
Long time Member
Posts: 669
Joined: Sun Feb 14, 2021 12:33 am
Location:Pleiades
Contact:

Re: Backup config to Gmail v1.4

Mon May 09, 2022 11:18 am

v6 or v7?

user-manager has is own separate databse, backup restore only customer, router, profiles and user, but without any profile assigned to users, sessions and the rest.
Hi,
V7 is there any way that I can BK my user-manager automatically? sessions are no problem if reset but profile and start times are very important :d
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11426
Joined: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: Backup config to Gmail v1.4

Mon May 09, 2022 11:20 am

You can try my "Save RouterBOARD full backup of everything [configuration, certificates, host key, router users (no passwords), user-manager, dude, other files]"
viewtopic.php?f=1&t=175360&p=858564#p858564
Top
用户头像
own3r1138
Long time Member
Long time Member
Posts: 669
Joined: Sun Feb 14, 2021 12:33 am
Location:Pleiades
Contact:

Re: Backup config to Gmail v1.4

Mon May 09, 2022 11:23 am

Well, Thankyou for sharing I will give it a try. is the
:local certpass "myprivatepass"
refers to PSK for certificate export?
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11426
Joined: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: Backup config to Gmail v1.4

Mon May 09, 2022 11:28 am

@Jotne
Script updated to v1.4
When something needs to be run on both versions, don't use syntax compatible only with v7;)
Code:Select all
:local Version [/system/resource get version] -> :local Version [resource get version]
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11426
Joined: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: Backup config to Gmail v1.4

Mon May 09, 2022 11:41 am

Well, Thankyou for sharing I will give it a try. is the
:local certpass "myprivatepass"
refers to PSK for certificate export?
yes... iscert-pass:roll:
Top
用户头像
Jotne
Forum Guru
Forum Guru
Topic Author
Posts: 3218
Joined: Sat Dec 24, 2016 11:17 am
Location:Magrathean

Re: Backup config to Gmail v1.4

Mon May 09, 2022 12:28 pm

When something needs to be run on both versions, don't use syntax compatible only with v7;)

Code:Select all
:local Version [/system/resource get version] -> :local Version [resource get version]

Good catch, updated.
Top
Term
Frequent Visitor
Frequent Visitor
Posts: 86
Joined: Thu Jan 11, 2018 11:42 pm

Re: Backup config to Gmail v1.4

Mon Aug 08, 2022 10:54 pm

Hi,
thank you for this script. Works fine. Just note, how can I change name of files?
now I have backup.rsc , bin.backup

want to have for example $info.backup, so it will be ie RB4011.backup

Tried to add it, script stopped work for me.

Thank you
Code:Select all
:local email "my@email.com" :local rscfn "$info. "-" .$date. "-" .$time" :local bakfn "$info. "-" .$date. "-" .$time"
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11426
Joined: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: Backup config to Gmail v1.4

Mon Aug 08, 2022 11:57 pm

date contain special character /
time contain special character :
and the routerboard name alsocancontain special characters

but ignoring that, your syntax is wrong (and why use two variables to store same things inside...)
Code:Select all
:local email "my@email.com" :local rscfn "$info-$date-$time" :local bakfn "$info-$date-$time" # or :local email "my@email.com" :local rscfn ($info . "-" . $date . "-" . $time) :local bakfn ($info . "-" . $date . "-" . $time)
Top
Term
Frequent Visitor
Frequent Visitor
Posts: 86
Joined: Thu Jan 11, 2018 11:42 pm

Re: Backup config to Gmail v1.4

Tue Aug 09, 2022 6:41 pm

Code:Select all
:local email "my@email.com" :local rscfn "$info-$date-$time" :local bakfn "$info-$date-$time" # or :local email "my@email.com" :local rscfn ($info . "-" . $date . "-" . $time) :local bakfn ($info . "-" . $date . "-" . $time)
tried both, doesn't work fine.
Attachments are now:
--.rsc
--.backup
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11426
Joined: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: Backup config to Gmail v1.4

Tue Aug 09, 2022 6:45 pm

It was an example to explain the syntax to you, it wasn't to correct your version of the script.

This still remains valid:you can't create a filename with invalid characters in it, do you understand that?
date contain special character /
time contain special character :
and the routerboard name alsocancontain special characters
Top
用户头像
Halfeez92
Member Candidate
Member Candidate
Posts: 101
Joined: Tue Oct 30, 2012 12:58 pm
Location:127.0.0.1
Contact:

Re: Backup config to Gmail v1.4

Thu Oct 27, 2022 7:57 am

Script updated to v1.4

Now also sends router version information in the subject. Faster to see when router was upgraded.
Code:Select all
# # Created Jotne 2022 v1.4 # # 1.4 Added Router OS version # 1.3r Revised by REX # 1.3 / 1.2 try to fix v6/v7 compability # 1.1 added "show-sensitive" # 1.0 initial release # # Takes two different backup and send then to email # # backup.rsc readable backup # Certificates, the Dude and Usermanager are also NOT exported or backed up fully and should be backed up separately # Can be used to restore config to different routers # # backup.bin binary backup # Binary backup that can only be used to fully restored the same router. # :local email "@gmail.com" :local rscfn "backup" :local bakfn "bin" /system :local date [clock get date] :local time [clock get time] :local info [identity get name] :local serial [routerboard get serial-number] :local files "$rscfn.rsc,$bakfn.backup" :local Version [resource get version] :if ($Version~"^7") do={ [:parse "/export show-sensitive file=$rscfn.rsc"] } else={ /export file="$rscfn.rsc" } :delay 2s /system backup save name="$bakfn" :delay 2s /tool e-mail send to="$email" subject="Mikrotik: Backup $info $Version $serial" file="$files" body="Automatic Backup of $info $serial at $date $time" :delay 20s :execute "/file remove $files" :log info "Backup router=$info serial=$serial ok"
The script does not work. I put in script with "don't require permission". Where did it goes wrong?
Top
用户头像
Jotne
Forum Guru
Forum Guru
Topic Author
Posts: 3218
Joined: Sat Dec 24, 2016 11:17 am
Location:Magrathean

Re: Backup config to Gmail v1.4

Thu Oct 27, 2022 8:01 am

Add script in between {