Table of Contents

Sending RouterOS Backup File via Email

This guide provides a script to automate the process of creating a backup on a RouterOS device, sending it as an email attachment, and then removing the backup file from the router.

Script

:local emailAddress "[email protected]"

:log info "BACKUP STARTING NOW"

# Create the backup file
:global backupfile ([/system identity get name])
/system backup save name=$backupfile

:log info "BACKUP FILE SAVED AS $backupfile, SENDING EMAIL IN 5 SECONDS"
:delay 5s

# Send the backup file via email
/tool e-mail send to="$emailAddress" subject=([/system identity get name] . " Backup " . [/system clock get date] . " " . [/system clock get time]) file=$backupfile

:delay 15s
:log info "EMAIL SENT, REMOVING BACKUP FILE"

# Remove the backup file from the router
/file remove $backupfile

:log info "Backup file removed from router"
:log info "Backup process completed"

Explanation

  1. Email Address: Set your destination email address where the backup will be sent.
  2. File Naming: The backup file name is generated using the router's name.

    Forward slashes would cause issues with file paths.

  3. Backup Creation: The script creates a backup file on the router.
  4. Email Sending: After a delay, the script sends the backup file via email.
  5. Cleanup: The backup file is removed from the router after the email is sent.

This script is useful for automating regular backups and ensuring they are securely stored off the router.