Problem running script(s)

Hello,

I have quite a weird problem with running my scripts.

Problem:
I have a script, that basically runs every day at 3AM and takes a backup from my router.
It works perfectly fine, but after some time (1 day or more) the script stops working. With error message: script error: action failed (6).

I’ve found a temporary solution for that. If I restart my router, then this script works fine again. But I really don’t want to restart my router every day.

Script:

:global getDateTime do={
  :local thisdate [/system clock get date];
  :local year [:pick $thisdate 7 11];
  :local month [:pick $thisdate 0 3];
  
  :if ($month="jan") do={[:set $month "01"]};
  :if ($month="feb") do={[:set $month "02"]};
  :if ($month="mar") do={[:set $month "03"]};
  :if ($month="apr") do={[:set $month "04"]};
  :if ($month="may") do={[:set $month "05"]};
  :if ($month="jun") do={[:set $month "06"]};
  :if ($month="jul") do={[:set $month "07"]};
  :if ($month="aug") do={[:set $month "08"]};
  :if ($month="sep") do={[:set $month "09"]};
  :if ($month="oct") do={[:set $month "10"]};
  :if ($month="nov") do={[:set $month "11"]};
  :if ($month="dec") do={[:set $month "12"]};
  
  :local day [:pick $thisdate 4 6];
  :local datetimestring ([$day] . "." . [$month] . "." . [$year]);
  
  :return ($datetimestring)

}

/system backup save name=("disk1/backups/" . [$getDateTime] . ".backup")
/export file=("disk1/backups/" . [$getDateTime] . ".rsc")

Router information:
Model: 951G-2HnD
Firmware: 6.42.6
RouterOS: 6.42.6

PS: I’ve only added one script, because other scripts have the same problem.

Anyone?

Tried using local instead of global? Not “:global getDateTime” but “:local getDateTime”? If you have few scripts and they all have this function - they overwrite it and maybe it’s causing the problem if they are doing it in the same time?

+1
Try

:do {
:local getDateTime do={
  :local thisdate [/system clock get date];
  :local year [:pick $thisdate 7 11];
  :local month [:pick $thisdate 0 3];
  
  :if ($month="jan") do={[:set $month "01"]};
  :if ($month="feb") do={[:set $month "02"]};
  :if ($month="mar") do={[:set $month "03"]};
  :if ($month="apr") do={[:set $month "04"]};
  :if ($month="may") do={[:set $month "05"]};
  :if ($month="jun") do={[:set $month "06"]};
  :if ($month="jul") do={[:set $month "07"]};
  :if ($month="aug") do={[:set $month "08"]};
  :if ($month="sep") do={[:set $month "09"]};
  :if ($month="oct") do={[:set $month "10"]};
  :if ($month="nov") do={[:set $month "11"]};
  :if ($month="dec") do={[:set $month "12"]};
  
  :local day [:pick $thisdate 4 6];
  :local datetimestring ([$day] . "." . [$month] . "." . [$year]);
  
  :return ($datetimestring)
}

:do {/system backup save name=("disk1/backups/" . [$getDateTime] . ".backup")} on-error={:log warning message="Backup failed..."}
:do {/export file=("disk1/backups/" . [$getDateTime] . ".rsc")} on-error={:log warning message="Export failed..."}
} on-error={:log warning message="Script failed..."}

and see log for error report

Hello and thank you for your answers. I’ll test your modified script and replay after some days.

Hello!

The script works BUT after some time it does not work again. But I accidentally stumbled upon a problem that my flash drive, where these backups go, is read only.
When I restart my router, then the flash drive is perfectly fine but after some time it is read only again. Can’t even delete files from there.

I’m trying a different flash drive, maybe it’s dying.

Thank you.

New flash drive solved the problem.

Thank you all!

Hi, I have a same problem with RB3011 router, coud you tell me how to chhange the flash memory? please.
Thanks
Regards