Skip to content
Back to Blog
MikroTik

Automated Configuration Backup in MikroTik via FTP and Email

Write RouterOS scripts to automatically backup your MikroTik configuration and send it to an FTP server or via email on a schedule.

Nov 2026
10 min read

Automating Config Backup Upload to FTP in MikroTik

Manual backups only help if someone remembers to run them. Automating the backup process — and uploading it off-device — ensures you always have a recent config to recover from, even if the hardware fails completely.

Step 1: Configure Email or FTP for Off-Device Storage

For FTP upload, RouterOS has a built-in FTP client. Set up a script that creates the backup then uploads it:

TEXT
/system script add name=backup-and-upload source={
  :local filename ("backup-" . [:tostr [/system clock get date]])
  /system backup save name=$filename
  /tool fetch upload=yes address=192.168.10.100 src-path=($filename . ".backup") dst-path=("/backups/" . $filename . ".backup") user=ftpuser password=ftppass mode=ftp
}

Step 2: Schedule the Script

TEXT
/system scheduler add name=weekly-backup interval=7d start-time=02:00:00 on-event=backup-and-upload

Step 3: Email Backup (Alternative)

If you have no FTP server, email the backup directly:

TEXT
/tool e-mail set address=smtp.gmail.com port=587 user=yourbot@gmail.com password=AppPassword from=yourbot@gmail.com

/system script add name=backup-email source={
  :local filename ("backup-" . [:tostr [/system clock get date]])
  /system backup save name=$filename
  /tool e-mail send to=admin@example.com subject=("RouterBackup " . $filename) file=($filename . ".backup")
}

For Gmail, use an App Password (requires 2FA enabled on the account).

Step 4: Export Script Config (Readable Text)

Include an export alongside the binary backup for human-readable recovery:

TEXT
/system script add name=backup-and-export source={
  :local date [:tostr [/system clock get date]]
  :local bname ("backup-" . $date)
  :local ename ("export-" . $date)
  /system backup save name=$bname
  /export file=$ename
  /tool fetch upload=yes address=192.168.10.100 src-path=($bname . ".backup") dst-path=("/backups/" . $bname . ".backup") user=ftpuser password=ftppass mode=ftp
  /tool fetch upload=yes address=192.168.10.100 src-path=($ename . ".rsc") dst-path=("/backups/" . $ename . ".rsc") user=ftpuser password=ftppass mode=ftp
}

Cleaning Up Old Local Files

Add cleanup to the script to prevent filling internal storage:

TEXT
  :foreach f in=[/file find where name~"backup-"] do={
    :if ([:totime [/file get $f creation-time]] < ([:totime [/system clock get time]] - 30d)) do={
      /file remove $f
    }
  }

(RouterOS scripting date/time arithmetic can be complex — a simpler approach is to only keep the latest 3 backups by listing and removing old ones by index.)

Testing the Backup Job

Run it manually first to confirm it works before relying on the scheduler:

TEXT
/system script run backup-and-upload

Check the Files area and your FTP server to confirm both the backup file was created and uploaded.

Verification Tip

Periodically restore a backup in a CHR test VM to verify the backup is actually restorable. A backup file that exists but can't be restored is worthless.

Automated off-device backups cost almost nothing in setup time and can save days of reconfiguration work after a hardware failure or accidental config change.