Until Ros 6.49.7 all working fine
On Ros 7 an up never work next script :
Does anyone have a suggestion? Or if you know where I'm wrong?
Still works fine on the previous version even now.
Thank you
Code: Select all
# Mikrotik Backup Script for Mikrotik RouterOS "6.40.1"
# This script will take mikrotik backup/export in files, and send them using
# Gmail SMTP. it will then delete those 2 files from the FILES section to preserve disk space in RouterOS
# It will also continue in case of DNS failure by an additional check
:local COMPANY "MyName"
:local sub1 ([/system identity get name])
:local sub2 ([/system clock get time])
:local sub3 ([/system clock get date])
:local backupfile "$sub1 mt_config_backup.backup"
:local mikrotikexport "$sub1 mt_export.rsc"
:local adminmail1 Email1@gmail.com
:local adminmail2 Email2@gmail.com
# GMAIL SMTP DYNAMIC Config Section, Make sure to change these values to match your's / Jz
:local gmailid myEmail@gmx.com
:local gmailuser myusername@gmx.com
:local gmailpwd MYPASSWORD
:local gmailport 587
# GMAIL SMTP DYNAMIC Config Section, Make sure to change these values to match your's / Jz
# Additional Check for GMAIL SMTP Resolving.
# If gmail SMTP failed to resolve, then it willset manual IP for gmail smtp
# So that email should go even if there is a dns failure.
:local GMAILSMTPDNSNAME "mail.gmx.com"
:global GMAILSMTP "212.227.17.184"
:local RESOLVELIST {"$GMAILSMTPDNSNAME"}
:foreach addr in $RESOLVELIST do={
:do {:resolve server=212.227.17.184 $addr} on-error={:set GMAILSMTP "0";}}
:if ($GMAILSMTP = 0) do={
:set GMAILSMTP "mail.gmx.com";
} else={
:set GMAILSMTP [:resolve "$GMAILSMTPDNSNAME"];
}
#####################################
## Donot change beyon this point ####
#####################################
# Setting gmail options in tool email as well, useful when u dont have configured toosl email option
/tool e-mail set address=$GMAILSMTP port=$gmailport start-tls=yes from=$gmailid user=$gmailuser password=$gmailpwd
:log warning "$COMPANY - Mikrotik Router Backup JOB Started . . ."
:log warning "$COMPANY - Creating new up-to date backup/export files . . . "
# Start creating Backup files backup and export both
/system backup save name=$backupfile dont-encrypt=yes
/export file=$mikrotikexport
:put "$COMPANY : Backup JOB process pausing for 60s so it can complete creating backup. Usually for Slow systems ..."
:log warning "$COMPANY : Backup JOB process pausing for 60s so it can complete creating backup. Usually for Slow systems ..."
:delay 60s
:log warning "Backup JOB is now sending Backup File via Email using GMAIL SMTP . . ."
# Start Sending email files to 1st email account, you can duplicate following two sending mail entries to add mulitple recipients
/tool e-mail send to=$adminmail1 subject="Router: $sub1 @ $sub3 - $sub2 Configuration BACKUP File" file=$backupfile start-tls=yes
/tool e-mail send to=$adminmail1 subject="Router: $sub1 @ $sub3 - $sub2 Configuration EXPORT File" file=$mikrotikexport start-tls=yes
# Send same backup files to 2nd email account , jsut for duplication and backup
/tool e-mail send to=$adminmail2 subject="Router: $sub1 @ $sub3 - $sub2 Configuration BACKUP File" file=$backupfile start-tls=yes
/tool e-mail send to=$adminmail2 subject="Router: $sub1 @ $sub3 - $sub2 Configuration EXPORT File" file=$mikrotikexport start-tls=yes
:log warning "$COMPANY : BACKUP JOB: Sleeping for 60s seconds so email can be delivered, "
:delay 60s
# REMOVE Old backup files to save space.
/file remove $backupfile
/file remove $mikrotikexport
# Print Log for done
:log warning "$COMPANY : Backup JOB: Process Finished & Backup File Removed. All Done. You should verify your inbox for confirmation"
# Script END