Code Monkey home page Code Monkey logo

mikrotik-routeros-automatic-backup-and-update's Introduction

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).
  • 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 - 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 does not contain spaces and special characters! System -> Identity

1. Configure parameters

Take the script and configure it's parameters at the begining 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

System -> Scripts [Add]

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

3. Configure mail server

Tools -> Email
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

System -> Scheduler [Add]
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="Firmware Updater" on-event="/system script run BackupAndUpdate;" start-time=03:10:00 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 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:

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! ☕

mikrotik-routeros-automatic-backup-and-update's People

Contributors

alexander-tebiev avatar beeyev avatar clorichel avatar dalemaunder avatar deniska-666 avatar peter-lamantia avatar tebiev avatar tkozybski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mikrotik-routeros-automatic-backup-and-update's Issues

update doesn't work

The script doesn't update the firmware. I receive the message "If you have not received second email in the next 5 minutes, then probably something went wrong." and I don't receive the second mail and the firmware is not updated.

Script error for RouterOS 7.15

There was an error while running the script. The log shows: 'executing script BackupAndUpdate from winbox failed, please check it manually"

Adding Public IP to email details

Hi how easy would it be to add the current Public IP address to the email that is sent out.

http://ifconfig.co/ip
gives the Public IP Address

Something like the below ??
:local fetchdata [/tool fetch url="http://ifconfig.co/ip" output=user]
:local extip ($fetchdata->"data")
:local extip [ :pick [ :tostr "$extip" ] 0 [ :find "$extip" "
" ] ]
"IP updated to $extip!"

Subject to contain date

Firstly, thank you for your script!
This is not an issue.

Gmail conversation view was categorizing all the backups under the same subject as 1 email.

To bypass this I added/changed some code which I would like to share it here as it could be useful for someone who is searching the backups by date.

I added a new line:
:local devicedate [/system clock get date]

Then I edit,
From: :local mailSubject "$SMP Device - $deviceIdentityNameShort.";
To: :local mailSubject "$SMP Device - $deviceIdentityNameShort - $devicedate";

The final subject is now: Bkp&Upd: Device - - apr/26/2022 Backup was created.

Not working on Mikrotik x86

Script not running on Mikrotik x86 .I think it is because /system routerboard command is empty on x86 (even no winbox menu). Or maybe somethong else...

After start in log view only the next line:

Bkp&Upd: script "Mikrotik RouterOS automatic backup & update" started.
Bkp&Upd: Script Mode: backup, forceBackup: false

execute doesn't passing local variable

ros v7.1.3

From
:local backupFileConfig "$backupName.rsc";
To
:global backupFileConfig "$backupName.rsc";

From
:execute "/export compact show-sensitive terse file=$backupName";
To
:execute {/export compact show-sensitive terse file=$backupFileConfig;}

  • "~~~" seems doesn't execute
  • $backupName makes long-long-filename.rsc : )

Or, how about drop "execute" and "wait"?

Please kindly review.

Comma in Identity

When in System -> Identity contains comma (eg. CCR1016, Office1) scrip hangs with message
Bkp&Upd: could not send email message (succeeded). Going to try it again in a while.

Perhaps an additional check or (which is easier!) а naming recommendation will help here.

Mikrotik 7.12 Breaking Changes

I think this script is great.

When the script updates 7.11.2 to 7.12 the script becomes broken because one of the commands has been renamed.

Looking at this https://forum.mikrotik.com/viewtopic.php?t=201345

It states:
email - rename "address" property to "server"

Therefore to fix the script find the section of script below

#Check proper email config
:if ([:len $emailAddress] = 0 or [:len [/tool e-mail get address]] = 0 or [:len [/tool e-mail get from]] = 0) do={
    :log error ("$SMP Email configuration is not correct, please check Tools -> Email. Script stopped.");
    :error "$SMP bye!";

change the word address (after get) to server

Apply the script.

When updating from 7.11.2 to 7.12 the script failed. The routerOS was updated but the routerboard firmware was not.

I hope this helps someone!

Invalid Body..........

Hello
The script worked flawlessly until google removed the option to allow insecure apps option.
I put another smtp server but now I can't send the backup mail anymore:
Same error with both hotmail smtp and smtp2go smtp: invalid BODY
Help please..........

Suggestion: Missed schedule backup time

Sometimes router goes offline and missed schedule backup time. So backup done next day at same as schedule and I lose backup for that day.
Is there any way to confirm backup if it is missed, so run backup script?

input does not match any value of channel

error

input does not match any value of channel

Update channel. Possible values: current, bugfix

:local updateChannel "current";

Need add stable, testting,development, long term Possible values: stable, testting,development, long term

:local updateChannel "stable";


RouterBOARD 941-2nD
Current Firmware 6.43.8

changes for ros 7.1 required

hi,

the current version does not work in ros 7.1

there seems to be an issue with sending an email. syntax changed?

thx!!

sensitive information in ROS v7

There is still an issue with the hide-sensitive option, now in 7.1 the export always hide sensitive information by default, you have to use show-sensitive parameter to export those options too, i have manually changed my script in the export section.

Mikrotik model name.

This is not a script error but some of my Mikrotics have "model: RouterBOARD cAP L-2nD" set and that is the problem.
I solved it like this:
#: local deviceRbModel [/ system routerboard get model];
: local deviceRbModel "RBcAPL-2nD";

Script error at email check for RouterOS 7.12.1

I get an error after RouterOS update in section: #Check proper email config
The expression [/tool e-mail get address] is not valid because of the "address" value
Look like is not longer valid value in that context. I changed to "user", but I am not sure if the meaning of values are similar.
Current RouterOS: 7.12.1
Thank you

Script does not work on a CloudHostetRouter

every time I run it, I get the error "executing script BackupAndUpdate from winbox failed, please check it manually".
If I delete the marked lines, the script works again.

:if ($isSoftBased = false) do={
:set deviceRbModel [/system routerboard get model];
:set deviceRbSerialNumber [/system routerboard get serial-number];
:set deviceRbCurrentFw [/system routerboard get current-firmware];
:set deviceRbUpgradeFw [/system routerboard get upgrade-firmware];
};

New script version note

It would be nice to see if new version of backup-and-update script is available on GH.

You can obtain latest version trough GH API (auth not required as long as repo is public):
https://api.github.com/repos/beeyev/Mikrotik-RouterOS-automatic-backup-and-update/releases/latest

Simple "New script version [version] available" note at the end of email message would be perfect. The other option is to implement auto-update, but I'm not sure if script self-override is possible in ROS.

Add upload backup via FTP/SFTP

Hi!
Could you add uploading file backup via FTP/SFTP protocol? It would required the file name was unique so I suggest to add pattern to the file name like yyyy-MM-dd or yyyy-MM-dd-hh-mm.

Suggestion: Disabling the "Auto backup before updating" feature.

Hello @beeyev.
Would it be possible to disable the "Auto backup before updating" feature?
I really don’t see the need for it if one is using the script often, like every second or third day.
If there are any problems with the new OS version, I can roll back to the previous version a few days back.
Thanks very much.
Clive.

Please add new mode

Please add new mode, example: osupdate over backup if there is an update
The system will backup only when there is an update and will be updated, as was the first version of the script


Прошу добавить новый режим, который будет работать так:
система сделает бэкап только когда есть обновление и обновится, как было в первых версиях скрипта

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.