Backup and recovery

Automatic MikroTik Backup by Email Every Day

Make your MikroTik router back itself up every night and email the files to you, with a script and scheduler, including Gmail settings and tips for keeping backups safe.

Commands in this article follow RouterOS v7 documentation but have not yet been marked as lab-tested on this site. Always test changes in a lab or maintenance window and keep a backup.

Problem

Backups are only useful if they are recent. Taking them by hand is easy to forget, so you want the router to send you a backup every day automatically.

Symptoms

  • The latest backup you can find is months old.
  • A router failed and you had to rebuild it from memory.

Likely causes

No scheduled backup, or backups stored only on the router itself (they are lost with the router).

Prerequisites

  • An email account for sending. For Gmail, turn on 2-step verification and create an App Password.
  • Correct time on the router (NTP), so file dates make sense.

Solution (WinBox / CLI)

1. Email settings (RouterOS v7.12 and later. Older v7 versions use address= instead of server=; RouterOS v6 uses address= and start-tls=yes):

RouterOS CLI
/tool e-mail set server=smtp.gmail.com port=587 tls=starttls user=yourname@gmail.com password=YOUR_APP_PASSWORD from=yourname@gmail.com

2. Backup script. It saves a password-protected binary backup and a text export, then emails both:

RouterOS CLI
/system script add name=auto-backup policy=read,write,policy,test,sensitive source={
/system backup save name=auto-backup password=BackupPassword123
/export file=auto-export
:delay 5s
/tool e-mail send to="yourname@gmail.com" subject=("Backup " . [/system identity get name]) body="Daily backup attached" file=auto-backup.backup
:delay 10s
/tool e-mail send to="yourname@gmail.com" subject=("Export " . [/system identity get name]) body="Daily export attached" file=auto-export.rsc
}

3. Run it every night at 2 AM:

RouterOS CLI
/system scheduler add name=daily-backup interval=1d start-time=02:00:00 on-event=auto-backup policy=read,write,policy,test,sensitive

Note: On RouterOS v7, /export hides passwords by default. Keep it that way for emailed files; the binary backup (protected with a password) contains everything.

Verification

Run the script once by hand and check your inbox:

RouterOS CLI
/system script run auto-backup
/log print where topics~"e-mail"

Common errors

  • Gmail rejects the login: use an App Password, not your normal password.
  • tls setting wrong: port 587 needs starttls, port 465 needs yes.
  • The email arrives without an attachment: increase the :delay so the file is finished before sending.

Rollback

RouterOS CLI
/system scheduler disable daily-backup

Watch the video (Bangla): Automatic MikroTik router backup by email

Go deeper in class

This topic is covered hands-on in MTCNA — MikroTik Certified Network Associate.

View MTCNA
WhatsApp