/system backup save password=$backupPassword name=$bname;
}
:log info ("Bkp&Upd: System backup created. $backupFileSys");
## Export config file
:if ($sensetiveDataInConfig = true) do={
/export compact file=$bname;
} else={
/export compact hide-sensitive file=$bname;
}
:log info ("Bkp&Upd: Config file was exported. $backupFileConfig");
# Checking for new RouterOS version
if ($scriptMode = "osupdate" or $scriptMode = "osnotify") do={
log info ("Bkp&Upd: Checking for new RouterOS version. Current version is: $deviceOsVerInst");
/system package update set channel=$updateChannel;
/system package update check-for-updates;
:delay 5s;
:set deviceOsVerAvail [/system package update get latest-version];
# If there is a problem getting information about available RouterOS from server
:if ([:len $deviceOsVerAvail] = 0) do={
:log warning ("Bkp&Upd: There is a problem getting information about new RouterOS from server.");
:set mailSubject ($mailSubject . " Error: No data about new RouterOS!")
:set mailBody ($mailBody . "\r\n\r\nError occured! \r\nMikrotik couldn't get any information about new RouterOS from server! \r\nWatch additional information in device logs.")
:log info ("Bkp&Upd: New patch version of RouterOS firmware is available.");
} else={
:log info ("Bkp&Upd: New minor version of RouterOS firmware is available. You need to update it manually.");
:set mailSubject ($mailSubject . " New major RouterOS is available: v.$deviceOsVerAvail!");
:set mailBody ($mailBody . "\r\n\r\nNew major RouterOS version is available to install: v.$deviceOsVerAvail ($updateChannel). \r\nYou chose to automatically install only patch updates, so this major update you need to install manually. \r\n$changelogUrl");
:set isOsNeedsToBeUpdated false;
}
}
#Check again, because this variable could be changed during checking for installing only patch updats
if ($isOsNeedsToBeUpdated = true) do={
:set mailSubject ($mailSubject . " New RouterOS is going to be installed! v.$deviceOsVerInst -> v.$deviceOsVerAvail");
:set mailBody ($mailBody . "\r\n\r\nYour Mikrotik will be updated to the new RouterOS version from v.$deviceOsVerInst to v.$deviceOsVerAvail (Update channel: $updateChannel) \r\nFinal report with detailed information will be sent when update process is completed. \r\nIf you have not received second email in the next 5 minutes, then probably something went wrong.");
#!! There is more code connected to this part and first step at the end of the script.
:log info "Bkp&Upd: RouterOS and routerboard upgrading process of was completed. New RouterOS version: v.$deviceOsVerInst, routerboard firmware: v.$deviceRbCurrentFw.";
:set mailSubject "Bkp&Upd: Router - $[:pick $deviceIdentityName 0 18] has been upgraded to the new RouterOS v.$deviceOsVerInst!";
:set mailBody "RouterOS and routerboard upgrading process was completed. \r\nNew RouterOS version: v.$deviceOsVerInst, routerboard firmware: v.$deviceRbCurrentFw. \r\n$changelogUrl $mailBodyDeviceInfo $mailBodyCopyright";
}
##
## SENDING EMAIL
##
# Trying to send email with backups in attachment.
:log error "Bkp&Upd: could not send email message ($[/tool e-mail get last-status]) for the second time."
if ($isOsNeedsToBeUpdated = true) do={
:log warning "Bkp&Upd: script didn't initialise update process due to inability to send backups to email."
}
}
}
:delay 5s;
}
## Remove backups which we have already sent during first step
:if ($updateStep = 1 and [/tool e-mail get last-status] = "succeeded") do={
:log info "Bkp&Upd: File system cleanup."
/file remove $mailAttachments;
:delay 2s;
# Fire update process only if backups were successfully sent
if ($isOsNeedsToBeUpdated = true) do={
## Set scheduled task to upgrade routerboard firmware on the next boot, task will be deleted when upgrade is done. (That is why you should keep original script name)