Backup scripts

I am new to RouterOS scripting.

I want to automate backups. I am looking for information to format the backup file names with the following information:

$IDENTITY-$ROUTER_MODEL-$ROUTEROS_VERSION-$DATE-$TIME.backup-type

Where $DATE uses the format YYMMDD and $TIME uses the format HHMM.

For example:

MyMikrotik-RB1100-6.42.7-20180906-1348.rsc

or

MyMikrotik-RB1100-6.42.7-20180906-1348.backup

If such information is already available in this forum or wiki just provide links.

Thanks much! :slight_smile:

It seems not to be so hard … here you are: http://bfy.tw/JlQ6

:do {
:local IDENTITY [/system identity get name];
:local MODEL [/system resource get board-name];
:local OSVERSION [/system resource get version];

:local array {""; "jan"; "feb"; "mar"; "apr"; "may"; "jun"; "jul"; "aug"; "sep"; "oct"; "nov"; "dec"}
:local DATE [/system clock get date];
:local day [:pick $DATE 4 6];
:local month ([:find $array [:pick $DATE 0 3]]);
:if ($month < 10) do={:set $month ("0" . $month);}
:local year [:pick $DATE 7 11];
:set $DATE ($year . $month . $day);

:local TIME [/system clock get time];
:local hours [:pick $TIME 0 2];
:local minutes [:pick $TIME 3 5];
:local seconds [:pick $TIME 6 8];
:set $TIME ($hours . $minutes . $seconds);

:do {/system backup save name=($IDENTITY . "-" . $MODEL . "-" . $OSVERSION . "-" . $DATE . "-" . $TIME);
} on-error={:log error message="Backup operation failed..."}

:do {/export file=($IDENTITY . "-" . $MODEL . "-" . $OSVERSION . "-" . $DATE . "-" . $TIME);
} on-error={:log error message="Export operation failed..."}
#
# E-MAIL SCRIPT IF REQUIRED
#
} on-error={:log error message="Export and Backup script failed..."}

E-MAIL SCRIPT

:do {/tool e-mail
 :local adminmail1 someone@emailaddress.com;
 :local gmailid yourgmailaccount@gmail.com;
 :local gmailuser yourgmailaccount@gmail.com;
 :local gmailpwd your password;
 :local gmailport 587;
 :local gmailsmtp [:resolve "smtp.gmail.com"];
 set address=$gmailsmtp port=$gmailport start-tls=yes from=$gmailid user=$gmailuser password=$gmailpwd;
 send to=$adminmail1 subject=("Backup of " . $IDENTITY) file=($IDENTITY . "-" . $MODEL . "-" . $OSVERSION . "-" . $DATE . "-" . $TIME . ".rsc") start-tls=yes;
 send to=$adminmail1 subject=("Backup of " . $IDENTITY) file=($IDENTITY . "-" . $MODEL . "-" . $OSVERSION . "-" . $DATE . "-" . $TIME . ".backup") start-tls=yes;
} on-error={:log error "Backup Email script failed"}

@ADahi
Thank you much for sharing! :smiley: I will try to remember to report my results when I test further.