Skip to content

Commit

Permalink
Merge pull request #50 from deniska-666/master
Browse files Browse the repository at this point in the history
Typo Fixing
  • Loading branch information
beeyev authored Apr 6, 2024
2 parents a5a5ae6 + 3a1aae1 commit 37e3493
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
16 changes: 8 additions & 8 deletions BackupAndUpdate.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand All @@ -417,12 +417,12 @@ 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;
} 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;
};
}
Expand Down Expand Up @@ -450,16 +450,16 @@ 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]). 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;

: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;
Expand Down
43 changes: 24 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@ 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:
**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**
> Make sure that your device identity does not contain any spaces or specific symbols! `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.
**Important!** Don't forget to provide correct email address for backups and pay attention a `scriptMode` variable.
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:
Expand All @@ -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)
Expand All @@ -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. 🎉






## Acknowledgements
I would like to extend my sincere gratitude to the following individuals who have contributed to this project:
Expand Down

0 comments on commit 37e3493

Please sign in to comment.