I have some problems tough
the script always runs if I manually run from the CLI (/sys script run DailyBackup), and presents debugging info in the screen.
if run from "run script" button, or scheduler, it will often crash and never finish. I suspect I should have to escape the output somehow, pipe it to log?
The Backup file is always generated, sometimes with an "could not read all configuration files" warning, but that is typical behavior, AFAIK.
The RSC file on the other hand, is always truncated at ~~4Kb, terminating in the /system scripts section.
Code: Select all
#
#variables to know to delete yesterdays files
#
:global BKNAME
:global OLDBKNAME
/log info message="======script===backup===INIT=========="
#
:local HOST [/sys identity get name]
:local PLACA [/sys reso get board-name]
:local date [/sys clock get date]
:local time [/sys clock get time]
:local DD [:pick $date 4 6 ]
:local MES [:pick $date 0 3 ]
:local AAAA [:pick $date 7 11 ]
:local HH [:pick $time 0 2]
:local MM [:pick $time 3 5]
:local NOMEBK "$HOST-$PLACA-$AAAA-$MES-$DD-$HH$MM"
/log info message="Gerando backup diario"
/log info message="$NOMEBK"
:global OLDBKNAME value=$BKNAME
:global BKNAME "$NOMEBK"
/delay 3;
/log info message="Salvando Backup"
/system backup save name="diario/$NOMEBK" dont-encrypt=yes;
/log info message="Backup Salvo"
/delay 3;
/log info message="Salvando Export"
/system export file="diario/$NOMEBK"
/log info message="Export Salvo"
/delay 3;
/log info message="Removendo BACKUP anterior"
file remove [find where name="diario/$OLDBKNAME.backup"]
/log info message="BACKUP anterior removido"
/delay 3;
/log info message="Removendo RSC anterior"
file remove [find where name="diario/$OLDBKNAME.rsc"]
/log info message="RSC anterior removido"
/delay 3;
/log info message="Enviando RSC via FTP"
/tool fetch upload=yes mode=ftp address=192.168.168.168 user=xxxzzz password=xxxzzz dst-path="/SSD/diario/$BKNAME.rsc" src-path="diario/$BKNAME.rsc"
/log info message="RSC enviado"
/delay 3;
/log info message="Enviando BACKUP via FTP"
##
#remote file uses .bak as mikrotik permissions for drop-only do not like .backup format
##
/tool fetch upload=yes mode=ftp address=192.168.168.168 user=xxxzzz password=xxxzzz dst-path="/SSD/diario/$BKNAME.bak" src-path="diario/$BKNAME.backup"
/log info message="BACKUP enviado"
/delay 3;
/log info message="Gerando CloudBackup"
/system backup cloud upload-file action=create-and-upload replace=[/system backup cloud get value-name=name number=0] password="correct-horse-battery-staple"
/log info message="CloudBackup Salvo"
/delay 3;
#
#
/log info message="======script===backup===END=========="
#