Community discussions

MUM Europe 2020
 
Michal.Podoski
just joined
Topic Author
Posts: 6
Joined: Thu Jan 05, 2006 12:14 am
Location: Poland - Warsaw
Contact:

Changing the MMM/DD/YYYY date format.

Sun Feb 12, 2006 9:42 pm

Hi!

I have a problem. I'm creating a automated backup system, and i need to save files attached to an email. And it would be nice if the router could name the file: inentity/date/time.

The problem occures when adding in the backup name [/system clock get date] - because of "/" marks. Mabey someone has a tip how to change the date format to MMMDDYYYY.. It can be done with regular expressions, but I can't find if RouterOS supports them.

Thanks for any help.

Regards
Michal Podoski
 
changeip
Forum Guru
Forum Guru
Posts: 3804
Joined: Fri May 28, 2004 5:22 pm

Mon Feb 13, 2006 1:39 am

You can try this:

:local d [/system clock get date]
:local p1 [:find $d "/"]
:local p2 [:find $d "/" $p1+1]
:local mydate ([:pick $d 0 $p1] . "." . [:pick $d ($p1 + 1) $p2] . "." . [:pick $d ($p2 + 1) ($p2 + 5)])
:put $mydate

If you are using script to backup with you can add that into it and use mydate variable as necessary. You could get away with stuffing all that onto a single command and not using vars - stepping thru it with vars shows you how its done though.

Sam
 
Michal.Podoski
just joined
Topic Author
Posts: 6
Joined: Thu Jan 05, 2006 12:14 am
Location: Poland - Warsaw
Contact:

Mon Feb 13, 2006 6:46 pm

Hi!

It don't seem like I have in 2.8 a ICE command called :pick.

I solved the problem this way:

1. backup_start:

/system backup save
/system script run [/system script find name=backup_proceed]

2. backup_proceed

:delay 10s
:global nazwa
:set nazwa ([/file get [/file find type=backup] name])
:global backup
:set backup ([/system identity get name] . "_" . $nazwa)
/file remove [/file find type=backup]
/system backup save name=($backup)
/system script run [/system script find name=backup_mail]

3. backup_mail
:delay 10s
/tool e-mail send \
from=([/system identity get name] . "@.mydomain") \
to="michalp@mydomain" \
subject=($backup) \
file=([/file find type=backup])
/file remove [/file find type=backup]
/system script run [/system script find name=backup_clear]

4. backup_clear

:unset backup
:unset nazwa

And it works:))))

Regards
Michal Podoski
 
the263
just joined
Posts: 1
Joined: Mon Mar 06, 2006 6:47 pm

Thu Mar 09, 2006 10:59 am

it is that a question?

the routeros 2.9.2 the default form is that!!
 
Inkhomi
just joined
Posts: 2
Joined: Mon Feb 10, 2020 5:23 pm

Re: Changing the MMM/DD/YYYY date format.

Mon Feb 10, 2020 5:38 pm

In one line:

Month.Day.Year:
:put [([:pick [/system clock get date] ([:find [/system clock get date] "/"] + 1) [:find [/system clock get date] "/" ([:find [/system clock get date] "/" ] +1)]] . "." . [:pick [/system clock get date] 0 [:find [/system clock get date] "/"]] . "." . [:pick [/system clock get date] ([:find [/system clock get date] "/" ([:find [/system clock get date] "/" ] +1)] + 1) ([:find [/system clock get date] "/" ([:find [/system clock get date] "/" ] +1)] + 5)])]

Day.Month.Year:
:put [([:pick [/system clock get date] ([:find [/system clock get date] "/"] + 1) [:find [/system clock get date] "/" ([:find [/system clock get date] "/" ] +1)]] . "." . [:pick [/system clock get date] 0 [:find [/system clock get date] "/"]] . "." . [:pick [/system clock get date] ([:find [/system clock get date] "/" ([:find [/system clock get date] "/" ] +1)] + 1) ([:find [/system clock get date] "/" ([:find [/system clock get date] "/" ] +1)] + 5)])]

Year Month Day:
:put [([:pick [/system clock get date] ([:find [/system clock get date] "/" ([:find [/system clock get date] "/" ] +1)] + 1) ([:find [/system clock get date] "/" ([:find [/system clock get date] "/" ] +1)] + 5)] . "." . [:pick [/system clock get date] 0 [:find [/system clock get date] "/"]] . "." . [:pick [/system clock get date] ([:find [/system clock get date] "/"] + 1) [:find [/system clock get date] "/" ([:find [/system clock get date] "/" ] +1)]])]

Trigger Script with YearMonthDay.backup as name:
/system backup save name=([([:pick [/system clock get date] ([:find [/system clock get date] "/" ([:find [/system clock get date] "/" ] +1)] + 1) ([:find [/system clock get date] "/" ([:find [/system clock get date] "/" ] +1)] + 5)] . "." . [:pick [/system clock get date] 0 [:find [/system clock get date] "/"]] . "." . [:pick [/system clock get date] ([:find [/system clock get date] "/"] + 1) [:find [/system clock get date] "/" ([:find [/system clock get date] "/" ] +1)]])].backup)
 
Inkhomi
just joined
Posts: 2
Joined: Mon Feb 10, 2020 5:23 pm

Re: Changing the MMM/DD/YYYY date format.

Fri Feb 14, 2020 4:42 pm

Finally, script to push your daily backup to an external FTP server while maintaining dates:

/tool fetch address=ADDRESS port=PORT user=USER mode=ftp password=PASSWORD src-path=([([:pick [/system clock get date] ([:find [/system clock get date] "/" ([:find [/system clock get date] "/" ] +1)] + 1) ([:find [/system clock get date] "/" ([:find [/system clock get date] "/" ] +1)] + 5)] . "." . [:pick [/system clock get date] 0 [:find [/system clock get date] "/"]] . "." . [:pick [/system clock get date] ([:find [/system clock get date] "/"] + 1) [:find [/system clock get date] "/" ([:find [/system clock get date] "/" ] +1)]])].".backup") dst-path=("/REMOTE/FTP/PATH/".([([:pick [/system clock get date] ([:find [/system clock get date] "/" ([:find [/system clock get date] "/" ] +1)] + 1) ([:find [/system clock get date] "/" ([:find [/system clock get date] "/" ] +1)] + 5)] . "." . [:pick [/system clock get date] 0 [:find [/system clock get date] "/"]] . "." . [:pick [/system clock get date] ([:find [/system clock get date] "/"] + 1) [:find [/system clock get date] "/" ([:find [/system clock get date] "/" ] +1)]])].".backup")) upload=yes;

Who is online

Users browsing this forum: No registered users and 18 guests