From 23e31ae3fd2e83ca983a978b2687b20dcc928e14 Mon Sep 17 00:00:00 2001 From: deniska-666 <137393345+deniska-666@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:21:38 +0100 Subject: [PATCH 1/8] Update BackupAndUpdate.rsc --- BackupAndUpdate.rsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BackupAndUpdate.rsc b/BackupAndUpdate.rsc index fa4d6a8..cad2f47 100644 --- a/BackupAndUpdate.rsc +++ b/BackupAndUpdate.rsc @@ -417,7 +417,7 @@ if ([:len [/system identity get name]] = 0 or [/system identity get name] = "Mik ## Wait until the upgrade is completed :delay 5s; :log info "$SMP routerboard upgrade process was completed, going to reboot in a moment!"; - ## Set scheduled task to send final report on the next boot, task will be deleted when is is done. (That is why you should keep original script name) + ## Set scheduled task to send final report on the next boot, task will be deleted when it is done. (That is why you should keep original script name) /system scheduler add name=BKPUPD-FINAL-REPORT-ON-NEXT-BOOT on-event=":delay 5s; /system scheduler remove BKPUPD-FINAL-REPORT-ON-NEXT-BOOT; :global buGlobalVarUpdateStep 3; :delay 10s; /system script run BackupAndUpdate;" start-time=startup interval=0; ## Reboot system to boot with new firmware /system reboot; From 05dd597d97b8832606022a035b17e7f7cee3d8ab Mon Sep 17 00:00:00 2001 From: deniska-666 <137393345+deniska-666@users.noreply.github.com> Date: Fri, 22 Mar 2024 22:19:27 +0100 Subject: [PATCH 2/8] Update BackupAndUpdate.rsc --- BackupAndUpdate.rsc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BackupAndUpdate.rsc b/BackupAndUpdate.rsc index cad2f47..6d72f9e 100644 --- a/BackupAndUpdate.rsc +++ b/BackupAndUpdate.rsc @@ -422,7 +422,7 @@ if ([:len [/system identity get name]] = 0 or [/system identity get name] = "Mik ## Reboot system to boot with new firmware /system reboot; } else={ - :log info "$SMP It appers that your routerboard is already up to date, skipping this step."; + :log info "$SMP It appears that your routerboard is already up to date, skipping this step."; :set updateStep 3; }; } @@ -453,7 +453,7 @@ if ([:len [/system identity get name]] = 0 or [/system identity get name] = "Mik :log info "$SMP Sending email message, it will take around half a minute..."; :do {/tool e-mail send to=$emailAddress subject=$mailSubject body=$mailBody file=$mailAttachments;} on-error={ :delay 5s; - :log error "$SMP could not send email message ($[/tool e-mail get last-status]). Going to try it again in a while." + :log error "$SMP could not send email message ($[/tool e-mail get last-status]). Will attempt redelivery shortly." :delay 5m; From 4f8bdc4d86ba22d2aa8b265c40bbd019c71ad4b6 Mon Sep 17 00:00:00 2001 From: deniska-666 <137393345+deniska-666@users.noreply.github.com> Date: Fri, 22 Mar 2024 22:29:01 +0100 Subject: [PATCH 3/8] Update BackupAndUpdate.rsc --- BackupAndUpdate.rsc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BackupAndUpdate.rsc b/BackupAndUpdate.rsc index 6d72f9e..4c18fd5 100644 --- a/BackupAndUpdate.rsc +++ b/BackupAndUpdate.rsc @@ -450,7 +450,7 @@ if ([:len [/system identity get name]] = 0 or [/system identity get name] = "Mik # Trying to send email with backups as attachments. :if ($isSendEmailRequired = true) do={ - :log info "$SMP Sending email message, it will take around half a minute..."; + :log info "$SMP Dispatching email message; estimated completion within 30 seconds."; :do {/tool e-mail send to=$emailAddress subject=$mailSubject body=$mailBody file=$mailAttachments;} on-error={ :delay 5s; :log error "$SMP could not send email message ($[/tool e-mail get last-status]). Will attempt redelivery shortly." @@ -459,7 +459,7 @@ if ([:len [/system identity get name]] = 0 or [/system identity get name] = "Mik :do {/tool e-mail send to=$emailAddress subject=$mailSubject body=$mailBody file=$mailAttachments;} on-error={ :delay 5s; - :log error "$SMP could not send email message ($[/tool e-mail get last-status]) for the second time." + :log error "$SMP failed to send email message ($[/tool e-mail get last-status]) for the second time." if ($isOsNeedsToBeUpdated = true) do={ :set isOsNeedsToBeUpdated false; From c76f77b1f7d91df6ba5eb7b10b2e47b2e7af5f6c Mon Sep 17 00:00:00 2001 From: deniska-666 <137393345+deniska-666@users.noreply.github.com> Date: Fri, 22 Mar 2024 22:48:23 +0100 Subject: [PATCH 4/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e6e8d6d..ae66b5c 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ This script allows you to generate daily backups of MikroTik and send them to an ##### 1. Configure parameters Take the [script](https://github.com/beeyev/Mikrotik-RouterOS-automatic-backup-and-update/raw/master/BackupAndUpdate.rsc) and configure it's parameters at the begining of the file. This is not difficult because all parameters are well commented. -**Important!** Don't forget to provide correct email address for backups and pay attention a `scriptMode` variable. +**Important!** Don't forget to provide correct email address for backups and pay attention to `scriptMode` variable. ##### 2. Create new script System -> Scripts [Add] From f2e38f0db152cf18a773d80e2d1bc1508e6ae28e Mon Sep 17 00:00:00 2001 From: deniska-666 <137393345+deniska-666@users.noreply.github.com> Date: Fri, 22 Mar 2024 22:51:18 +0100 Subject: [PATCH 5/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ae66b5c..adfc7dc 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ This script allows you to generate daily backups of MikroTik and send them to an ## How to use > ❗️ **Important** -> Make sure that your device identity does not contain any spaces or specific symbols! `System -> Identity` +> Ensure your device identity is free from spaces and special characters! `System -> Identity` ##### 1. Configure parameters Take the [script](https://github.com/beeyev/Mikrotik-RouterOS-automatic-backup-and-update/raw/master/BackupAndUpdate.rsc) and configure it's parameters at the begining of the file. From 0aaca7eda2f7395cd376b5e32e3f8b344ec2a18d Mon Sep 17 00:00:00 2001 From: deniska-666 <137393345+deniska-666@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:37:22 +0100 Subject: [PATCH 6/8] Update README.md --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index adfc7dc..282c498 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,12 @@ This script allows you to generate daily backups of MikroTik and send them to an ## Features: -- Choose the script's operating mode based on your specific requirements. (See details below) -- The script generates backups of the entire system and exports the configuration. -- Customize your preferred update channel. -- When automatic updates are enabled, you can configure the script to install only patch versions of RouterOS updates. *For example, if the current RouterOS version is v6.43.6, the script will automatically install v6.43.7 (a new patch version) but not v6.44.0 (a new minor version).* -- The script includes essential device information into the email message, making it easy to identify the required backup among multiple devices. -- As a safety measure, the automatic update process will not initiate if the script is unable to send backups via email. +- Select the script's operational mode according to your specific needs (details provided below). +- This script is designed to create full system backups and export configurations. +- Customize the update channel according to your preference. +- With automatic updates activated, the script can be set to apply only patch updates for RouterOS. For instance, should the current RouterOS version be v6.43.6, the script will autonomously upgrade to v6.43.7 (a patch update), while avoiding v6.44.0 (a minor update).* +- The script also incorporates vital device details in the email alerts, facilitating easy identification of the necessary backup among several devices. +- For added security, the script is programmed to stop the automatic update process if it fails to dispatch backups via email. - Routerboard firmware can be upgraded automatically based on the installed RouterOS version. ## Script operating modes: From 4bd912658b48928531331f5377c67c76240d791b Mon Sep 17 00:00:00 2001 From: deniska-666 <137393345+deniska-666@users.noreply.github.com> Date: Sat, 23 Mar 2024 13:37:44 +0100 Subject: [PATCH 7/8] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pay attention to "execute the script by typing `/system script run BackupAndUpdate;` in the Terminal." i might have messed with the command as i don't really know how ' " / works ❤️ --- README.md | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 282c498..23ce2aa 100644 --- a/README.md +++ b/README.md @@ -16,29 +16,29 @@ This script allows you to generate daily backups of MikroTik and send them to an - Routerboard firmware can be upgraded automatically based on the installed RouterOS version. ## Script operating modes: -**Backups only** - script creates system and config backups and sends them to specified email as an attachment. Using email account as storage for your backups. -**Backups and notifications about new RouterOS release** - Except backups, script also checks for new RouterOS firmware release and provides this information in the email. -**Backups and automatic RouterOS upgrade** - Script makes a backup, then checks for new RouterOS version, and if new firmware released, script will initiate upgrade process. By the end, you receive two emails. The first one contains system backups of the previous RouterOS version, the second message will be sent when the upgrade process is done (including backups of the updated system). +**Backups only** - The script generates system and configuration backups and forwards them to a specified email as attachments. It uses your email account as a storage for these backups. +**Backups and notifications about new RouterOS release** - In addition to creating backups, the script also monitors for any new releases of RouterOS firmware and communicates this information via email. +**Backups and automatic RouterOS upgrade** - The script begins by creating a backup, followed by a check for any new versions of RouterOS. If a newer firmware version is detected, the script initiates the upgrade process. Upon completion, two emails are sent: the first includes the system backups from the prior RouterOS version, and the second, sent post-upgrade, contains backups of the updated system. ## How to use > ❗️ **Important** -> Ensure your device identity is free from spaces and special characters! `System -> Identity` +> Ensure your device identity does not contain spaces and special characters! `System -> Identity` ##### 1. Configure parameters Take the [script](https://github.com/beeyev/Mikrotik-RouterOS-automatic-backup-and-update/raw/master/BackupAndUpdate.rsc) and configure it's parameters at the begining of the file. -This is not difficult because all parameters are well commented. +This step is straightforward as all parameters are well-commented. **Important!** Don't forget to provide correct email address for backups and pay attention to `scriptMode` variable. ##### 2. Create new script System -> Scripts [Add] -**Important!** Script name has to be `BackupAndUpdate` -Put the script which you configured earlier into the source area. +**Important!** Script name must be `BackupAndUpdate` +Insert the script which you configured earlier into the source area. ![](https://github.com/beeyev/Mikrotik-RouterOS-automatic-backup-and-update/raw/master/howto/script-name.png) ##### 3. Configure mail server Tools -> Email -Set your email server parameters. If you don't have one, i recommend to use [smtp2go.com](https://smtp2go.com "smtp2go.com") service, it allows sending a thousand emails per month for free. +Configure your email server parameters. If you don't have one, i recommend using the [smtp2go.com](https://smtp2go.com "smtp2go.com") service, which allows sending a thousand emails per month for free. ![](https://github.com/beeyev/Mikrotik-RouterOS-automatic-backup-and-update/raw/master/howto/email-config.png) To check email settings, send a test message by running the following command in terminal: @@ -49,7 +49,7 @@ To check email settings, send a test message by running the following command in ##### 4. Create scheduled task System -> Scheduler [Add] Name: `Backup And Update` -Start Time: `03:10:00` (the start time has to be different for all your mikrotik device in a chain) +Start Time: `03:10:00` (the start time has to be different for all your mikrotik devices in a chain) Interval: `1d 00:00:00` On Event: `/system script run BackupAndUpdate;` ![](https://github.com/beeyev/Mikrotik-RouterOS-automatic-backup-and-update/raw/master/howto/scheduler-task.png) @@ -59,9 +59,14 @@ Or you can use this command to create the task: /system scheduler add name="Firmware Updater" on-event="/system script run BackupAndUpdate;" start-time=03:10:00 interval=1d comment="" disabled=no ``` ##### 5. Test the script -When everything is done, you need to make sure that the script is working correctly. -To do so, open a New Terminal and Log window in your WinBox, then run the script manually by executing this command `/system script run BackupAndUpdate;` in Terminal. -You will see the script working process in the log window. If the script finished without errors, check your email, there is a fresh message with backups from your MikroTik waiting for you 🎉 +Once everything is set up, it's important to verify that the script is functioning properly. +To do this, open a New Terminal and a Log window in your WinBox, then manually execute the script by typing `/system script run BackupAndUpdate;` in the Terminal. +You will see the script the script's operation in the log window. If the script completes without any errors, check your email. You'll find a new message with backups from your MikroTik awaiting you. 🎉 + + + + + ## Contributors From 3a1aae13b9c4a63d47045dc8727e837212b2e3a5 Mon Sep 17 00:00:00 2001 From: deniska-666 <137393345+deniska-666@users.noreply.github.com> Date: Sat, 23 Mar 2024 14:07:43 +0100 Subject: [PATCH 8/8] Update BackupAndUpdate.rsc --- BackupAndUpdate.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BackupAndUpdate.rsc b/BackupAndUpdate.rsc index 4c18fd5..9a91ca6 100644 --- a/BackupAndUpdate.rsc +++ b/BackupAndUpdate.rsc @@ -43,7 +43,7 @@ ## Update channel. Possible values: stable, long-term, testing, development :local updateChannel "stable"; -## Install only patch versions of RouterOS updates. +## Installs only patch versions of RouterOS updates. ## Works only if you set scriptMode to "osupdate" ## Means that new update will be installed only if MAJOR and MINOR version numbers remained the same as currently installed RouterOS. ## Example: v6.43.6 => major.minor.PATCH @@ -341,7 +341,7 @@ if ([:len [/system identity get name]] = 0 or [/system identity get name] = "Mik }; if ($forceBackup = true) do={ - # In this case the script will always send email, because it has to create backups + # In this case the script will always send an email, because it has to create backups :set isSendEmailRequired true; } @@ -396,7 +396,7 @@ if ([:len [/system identity get name]] = 0 or [/system identity get name] = "Mik :set mailAttachments [$buGlobalFuncCreateBackups backupName=$backupNameFinal backupPassword=$backupPassword sensitiveDataInConfig=$sensitiveDataInConfig]; } else={ - :log info ("$SMP There is no need to create a backup."); + :log info ("$SMP Creating a backup is not necessary."); } # Combine first step email