Generate backup and send it by e-mail - Mikrotik Script RouterOS

This script generates backup file and sends it to specified e-mail address. Mail subject contains router's name, current date and time.
Note that smtp server must be configured before this script can be used. See /tool e-mail for configuration options.

:log info "Starting Backup Script..."
:global backupfile ([/system identity get name] . ".backup")
:if ([/file find name=$backupfile] != "") do={/file rem $backupfile}
:delay 2s
/system backup save name=$backupfile
:log info "Waiting 5s for backup to complete..."
:delay 5s
:log info "Backup being emailed..."
/tool e-mail send to="backups@yourdomain.com" subject=([/system identity get name] . " Backup") from=RB600@yourdomain.com file=$backupfile server=xxx.xxx.xx.x
:log info "Finished Backup Script!"
Credit: wiki.mikrotik.com