Skip to content
المشاريع

beeyev/Mikrotik-RouterOS-automatic-backup-and-update

عرض على GitHub

حول

يرسل هذا السكربت نسخًا احتياطية عبر البريد الإلكتروني، ويحافظ على تحديث البرنامج الثابت لأجهزة MikroTik.

الأنظمة والبنية التحتية

كيف تُقاس هذه الأرقام

ما يمكنك فعله

  • Select the script's operational mode according to your specific needs (details provided below).
  • Creates a full system backup, a configuration export, or both, and sends them by email. The files are removed from the device after sending, so they never pile up in its storage.
  • 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 v7.23.1, the script will autonomously upgrade to v7.23.4 (a patch update), while avoiding v7.24 (a minor update).

النمو المقاس للنجوم

خلال 24 ساعة
٠
خلال 7 أيام
٠
خلال 15 يومًا
٠
خلال شهر
جارٍ جمع السجل

تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.

README.md

الأصل

Mikrotik RouterOS automatic backup and update

This script allows you to generate daily backups of MikroTik and send them to an email address. You can also choose to enable automatic RouterOS upgrades or receive notifications exclusively for new firmware versions.

💡 If you have any ideas about the script or you just want to share your opinion, you are welcome to Discussions, or you can open an issue if you found a bug.

Features:

  • Select the script's operational mode according to your specific needs (details provided below).
  • Creates a full system backup, a configuration export, or both, and sends them by email. The files are removed from the device after sending, so they never pile up in its storage.
  • 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 v7.23.1, the script will autonomously upgrade to v7.23.4 (a patch update), while avoiding v7.24 (a minor update).
  • The script also incorporates vital device details in the email alerts, facilitating easy identification of the necessary backup among several devices.
  • Routerboard firmware is upgraded automatically after a RouterOS update.
  • Works on RouterBOARD devices and on CHR.

Requirements

  • RouterOS v6.49.19 or newer v6, or v7.23 or newer
  • The script must be named BackupAndUpdate. After a reboot the update cycle runs it by that name
  • A working email configuration in Tools -> Email

Script operating modes:

  • Backups only backup - 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 osnotify - The script monitors for new releases of RouterOS firmware and communicates this information via email. Backups are attached only if forceBackup is enabled.
  • Backups and automatic RouterOS upgrade osupdate - The script checks for a new version of RouterOS. If one is found, it creates a backup, sends it, and starts the upgrade. After the reboot it checks the installed version, upgrades the Routerboard firmware if needed, and sends a second email with backups of the updated system. Two emails in total: the first with the backups from the prior RouterOS version, the second with the final report.

Settings

All settings are at the beginning of the script and are commented there

Setting Default Description
emailAddress Where to send backups and notifications.
scriptMode osupdate backup, osupdate or osnotify, see above.
forceBackup false Create and send backups on every run in osupdate and osnotify modes too.
backupContent both full (system backup), export (configuration export .rsc) or both.
backupPassword Encrypts the system backup. Empty means no encryption. The configuration export contains the script and this password, so use it with backupContent full.
sensitiveDataInConfig false Include passwords and keys in the configuration export in plain text.
updateChannel stable stable, long-term, testing or development.
installOnlyPatchUpdates false In osupdate mode, install only patch updates of the installed version.
allowMajorUpgrade false In osupdate mode, allow the upgrade from v6 to v7.
detectPublicIpAddress true Add the public IP address to the email.

How to use

1. Configure parameters

Take the script and configure its parameters at the beginning of the file.
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

In this example we use WinBox

Go to: System -> Scripts and click the [New] button.

Important! Script name must be BackupAndUpdate
Insert the script which you configured earlier into the source area.

3. Configure mail server

Go to: Tools -> Email and click the [New] button.
Configure your email server parameters. If you don't have one, i recommend using the smtp2go.com service, which allows sending a thousand emails per month for free.

To check email settings, send a test message by running the following command in terminal:

/tool e-mail send to="[email protected]" subject="backup & update test!" body="It works!";
4. Create scheduled task

Go to: System -> Scheduler and click the [Add] button.
Name: Backup And Update
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;

Or you can use this command to create the task:

/system scheduler add name="Backup And Update" on-event="/system script run BackupAndUpdate;" start-time=(03:10:00 + [:totime [:pick [/system clock get time] 6 8]]) interval=1d comment="" disabled=no
5. Test the script

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'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.

Development

To develop and debug the script, use the local RouterOS lab in lab/. It starts MikroTik CHR v7 and v6 with a Mailpit inbox in Docker with a single make up. make test runs the end-to-end tests

Acknowledgements

Special thanks to the talented people who are working at MikroTik for their contributions in creating such outstanding products.

License

The MIT License (MIT). Please see License File for more information.


If you love this project, please buy more mikrotiks ;) and consider giving me a ⭐

Buy me a coffee! :coffee:

استكشف مشاريع مشابهة ومرتبطة

جارٍ التحميل…