Community discussions

MikroTik App
 
User avatar
delix
just joined
Topic Author
Posts: 15
Joined: Mon Aug 06, 2012 12:09 am
Location: Simferopol, Ukraine

Copy current synchronized time/date to flash

Mon Aug 06, 2012 12:28 pm

Hi all!
Pls help me with the an issue! ROs 5.18.
I need a script which would copy current (synchronized) time/date to default time/date on flash, that after reboot or power loss I have last right time. It saves my old graphs(all graphs before default time/date) from overwrite befor next ntp-synchronization.
I know that device could be off for an hour or even more and there would be some blanks after synchronization... Anyway it's better than lose all graphs.

Thank you for advice!
Last edited by delix on Mon Aug 06, 2012 11:39 pm, edited 1 time in total.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 24608
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: Copy current synchronized time/date to flash

Mon Aug 06, 2012 12:34 pm

That script would set the correct time only after RouterOS is fully booted, and in that case, result would be the same as using NTP client on the router.
No answer to your question? How to write posts
 
User avatar
delix
just joined
Topic Author
Posts: 15
Joined: Mon Aug 06, 2012 12:09 am
Location: Simferopol, Ukraine

Re: Copy current synchronized time/date to flash

Mon Aug 06, 2012 1:02 pm

And what if after reboot there's no Internet connection for 5 min more. In this case all graphs would be deleted.
Look close:
Let us pretend it's "18:00, 06 august 2012" on my mikrotik. Than suddenly my ISP felt down. If I wouldn't reboot mikrotik it will be ok, it still draws graphs even there's no Internet connection because time is synchronized. But if I accidentally reboot my router and it couldn't synchronize with ntp-server because of no Internet connection, in this case it kills all graphs. Time would be Jan/01/2002 and it deletes all graphs since this date. BUT if date would be "18:00, 06 august 2012" it leaves graphs untouched up to this date.
Last edited by delix on Wed Aug 08, 2012 3:19 pm, edited 1 time in total.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 24608
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: Copy current synchronized time/date to flash

Mon Aug 06, 2012 1:03 pm

OK I understand. Maybe somebody more skilled in scripting could help.

But still, it is a very rare situation when both the ISP goes down, and also the router is accidentaly rebooted at the same time.
No answer to your question? How to write posts
 
User avatar
delix
just joined
Topic Author
Posts: 15
Joined: Mon Aug 06, 2012 12:09 am
Location: Simferopol, Ukraine

Re: Copy current synchronized time/date to flash

Mon Aug 06, 2012 1:17 pm

No No No! Here in Ukraine its very common situation :lol:
Our Electricity Company sucks!
They switch off electricity for half a day and no UPS could keep charge so long.
Or when ISP down some noobie user might reboot mikrotik just in case it helps.

I think making default time to be the same as current(synchronized) time is very clever solution!
 
andreacoppini
Trainer
Trainer
Posts: 489
Joined: Wed Apr 13, 2005 11:51 pm
Location: Malta, Europe

Copy current synchronized time/date to flash

Mon Aug 06, 2012 4:48 pm

Or maybe MT could stop graphs from being updated until NTP is synchronised.
- No strings attached -

<< Please give good Karma if this post helped you. Press the + button above the Location entry
 
psamsig
Member Candidate
Member Candidate
Posts: 161
Joined: Sun Dec 06, 2009 1:36 pm
Location: Denmark

Re: Copy current synchronized time/date to flash

Mon Aug 06, 2012 8:24 pm

Create this as a script and run it with a scheluder. This may be hard on the NAND, so schedule accordingly, but frequence will be the 'precision' of the saved clock.
/ip dns static {
    :local o [find name=clock.localhost]
    :local datetime
    /system clock {
        :set datetime ([get date] . " " . [get time])
    }
    :if ([:len $o] > 0) do={
        set [:pick $o 0] comment=$datetime
    } else={
        add address=127.0.0.1 disabled=no name=clock.localhost ttl=1d comment=$datetime
    }
}
Create this as an other script, and make a scheduler to run it at startup:
/ip dns static {
    :local o [find name=clock.localhost]
    :if ([:len $o] > 0) do={
        :local datetime [get [:pick $o 0] comment]
        /system clock {
            :if ([:len $datetime] > 0 and [:pick [get date] 7 11] = "1970") do={
                set date=[:pick $datetime 0 11]
                set clock=[:pick $datetime 12 20]
            }
        }
    }
}
 
psamsig
Member Candidate
Member Candidate
Posts: 161
Joined: Sun Dec 06, 2009 1:36 pm
Location: Denmark

Re: Copy current synchronized time/date to flash

Mon Aug 06, 2012 10:06 pm

Or maybe MT could stop graphs from being updated until NTP is synchronised.
+1
Quite a few things should get postponed until NTP is synchronised, e.g. I have often noticed that an IPSec VPN gets established before a response from NTP kicks in, so the tunnel has to get recreated after just a few seconds.
 
psamsig
Member Candidate
Member Candidate
Posts: 161
Joined: Sun Dec 06, 2009 1:36 pm
Location: Denmark

Re: Copy current synchronized time/date to flash

Wed Aug 08, 2012 9:39 pm

How very odd, the NTP package changes the default bootup date, so the second script should be changed to the following:
/ip dns static {
    :local o [find name=clock.localhost]
    :if ([:len $o] > 0) do={
        :local datetime [get [:pick $o 0] comment]
        /system clock {
            :if ([:len $datetime] > 0 and [:pick [get date] 7 11] < "2012") do={
                set date=[:pick $datetime 0 11]
                set clock=[:pick $datetime 12 20]
            }
        }
    }
}
 
User avatar
delix
just joined
Topic Author
Posts: 15
Joined: Mon Aug 06, 2012 12:09 am
Location: Simferopol, Ukraine

Re: Copy current synchronized time/date to flash

Sat Aug 11, 2012 12:23 pm

psamsig thx a lot for your help!
Though, I haven't try your scripts yet =) have no time.
I'd try it in 2 days and report results.

Who is online

Users browsing this forum: cillininfo and 36 guests