Skip to content

Backup Automation

RouterOS can automatically create binary backups and RSC configuration exports on a schedule, then deliver them off-router via email, FTP, or SFTP. This ensures a current copy of your configuration survives device failure.

For a reference on backup vs export format differences, see Backup.

/system backup
/export
/system scheduler
/system script
/tool e-mail
/tool fetch

RouterOS provides two complementary formats that serve different recovery scenarios. Both should be included in automation scripts.

Binary Backup (.backup)Text Export (.rsc)
Command/system backup save/export file=
FormatBinaryHuman-readable script
Includes MAC addressesYesNo
Password protectionOptionalNo
Restore to same deviceYesYes
Migrate to new hardwareNot recommendedYes
Partial restoreNoYes (edit file)
Git-friendly diffsNoYes

Keep logic in a script and call it from the scheduler. This separates concerns and makes testing easier.

/system script
add name=auto-backup policy=read,write,policy,test,sensitive source={
:local id [/system identity get name]
:local d [/system clock get date]
:local t [/system clock get time]
:local base ("$id-$d-$t")
/system backup save name=$base password=YourSecurePassword
/export compact file=$base
:log info ("Backup created: $base")
}
/system scheduler
add name=daily-backup \
on-event=auto-backup \
start-time=03:30:00 \
interval=1d \
policy=read,write,policy,test,sensitive

The scheduler calls auto-backup once daily at 03:30. If the router reboots, the next scheduled run occurs at 03:30 the following day.

To additionally run a backup shortly after boot (useful for capturing state before automated changes):

/system scheduler
add name=startup-backup \
on-event=auto-backup \
start-time=startup \
interval=0

start-time=startup runs the script 3 seconds after the console starts. Setting interval=0 means run once rather than repeatedly.

The script and scheduler must share the same policy set. For a backup script that creates files and reads all settings:

PolicyRequired for
readReading configuration
writeCreating backup files
policyAccessing sensitive policy objects
testRunning test commands
sensitiveExporting sensitive values (show-sensitive)

Backups stored only on the router are lost when the router fails. Deliver copies to external systems immediately after creation.

Configure the SMTP client once:

/tool e-mail
set address=smtp.example.com \
port=587 \
password=AppPassword \
tls=starttls

Extend the backup script to send the files as attachments:

/system script
add name=auto-backup policy=read,write,policy,test,sensitive source={
:local id [/system identity get name]
:local d [/system clock get date]
:local t [/system clock get time]
:local base ("$id-$d-$t")
/system backup save name=$base password=YourSecurePassword
/export compact file=$base
:delay 5s
/tool e-mail send \
subject=("RouterOS backup: $id $d $t") \
body=("Automated backup from $id") \
file=("$base.backup,$base.rsc")
:log info ("Backup emailed: $base")
}

The 5-second delay ensures the files are fully written before attaching. See Email for SMTP configuration details and provider-specific TLS settings.

Use /tool fetch with upload=yes to push files to an FTP server:

/tool fetch url="ftp://backup.example.com/routers/$id/$base.backup" \
src-path="$base.backup" \
upload=yes \
user=ftpuser \
password=FtpPassword

SFTP upload uses the same /tool fetch command with the sftp:// scheme:

/tool fetch url="sftp://backup.example.com/routers/$id/$base.backup" \
src-path="$base.backup" \
upload=yes \
user=sftpuser \
password=SftpPassword

To verify server identity, provide the host key:

/tool fetch url="sftp://backup.example.com/routers/$id/$base.backup" \
src-path="$base.backup" \
upload=yes \
user=sftpuser \
password=SftpPassword \
host-key="AAAAB3NzaC1yc2EAAAA..."

See Fetch for full parameter reference.

RSC exports are plain text and integrate cleanly with Git. RouterOS has no native Git client, so the standard workflow is:

  1. RouterOS exports RSC to a file on schedule
  2. An external host (Linux server, CI runner) fetches the file via SCP/SFTP and commits it
/system script
add name=export-config policy=read,write,policy,test source={
/export compact file=running-config
}
/system scheduler
add name=nightly-export \
on-event=export-config \
start-time=02:00:00 \
interval=1d

This overwrites running-config.rsc with the current configuration each night, keeping a single canonical file rather than date-stamped copies.

#!/bin/bash
# Pull latest config export and commit to git
ROUTER=192.168.1.1
ROUTER_USER=admin
REPO=/opt/router-configs
sftp ${ROUTER_USER}@${ROUTER}:running-config.rsc ${REPO}/running-config.rsc
cd ${REPO}
git add running-config.rsc
git commit -m "RouterOS config export $(date -Iseconds)" || true
git push

Schedule this script via cron on the external host to run after the RouterOS export completes.

By default, /export omits passwords and private keys. To include them (required if the export is your sole recovery source):

/export compact show-sensitive file=running-config-full

Dated backup files accumulate on the router’s storage. Remove old files to prevent disk exhaustion:

/system script
add name=auto-backup policy=read,write,policy,test,sensitive source={
:local id [/system identity get name]
:local d [/system clock get date]
:local t [/system clock get time]
:local base ("$id-$d-$t")
# Create backups
/system backup save name=$base password=YourSecurePassword
/export compact file=$base
# Clean up files older than 7 days (keep last 7 entries by name prefix)
:local files [/file find where name~$id]
:foreach f in=$files do={
:if ([:len $files] > 14) do={
/file remove $f
}
}
:log info ("Backup created: $base")
}

Check available storage before implementing long retention periods:

/system resource print
/system backup load name=MyRouter-2026-03-22-030000.backup password=YourSecurePassword

RouterOS prompts for confirmation, then reboots and applies the configuration.

/import file-name=running-config.rsc

For partial restore, download the RSC file, edit it to retain only the desired sections, upload it back, and import.

If the router is in a blank state (factory defaults):

  1. Connect via WinBox or serial console
  2. Upload the backup or RSC file via FTP/SFTP, WinBox Files panel, or Netinstall
  3. Import or load the file
# After uploading the file
/system backup load name=router-config.backup password=YourSecurePassword
PracticeReason
Keep script logic in /system script, not inline in the schedulerEasier to test and modify
Use both binary backup and RSC exportCovers different failure scenarios
Deliver backups off-router immediatelyOn-device copies are lost with the device
Test restoration periodicallyUntested backups may be corrupted or incomplete
Use compact export for version controlReduces diff noise from default values
Monitor scheduler run-count and logsConfirms backups are actually running
Store backup passwords in a password managerEncrypted backups are useless without the password
# Check available disk space
/system resource print
# Check scheduler is running
/system scheduler print
# Run script manually to see errors
/system script run auto-backup
# Check logs
/log print where message~"backup"
  1. Confirm SMTP settings: /tool e-mail print
  2. Verify TLS mode matches the port (starttls → port 587, implicit TLS → port 465)
  3. Check for provider-specific app passwords
  4. Test manually: /tool e-mail send to="[email protected]" subject="test" body="test"
  1. Verify credentials and URL format
  2. Check the destination directory exists and is writable
  3. Test fetch manually with the exact URL
  4. For SFTP, provide host-key to avoid identity verification failures
  1. Verify script name matches on-event exactly
  2. Check scheduler and script have matching policy settings
  3. Look for errors in logs: /log print where topics~"script"
  4. Run the script manually to confirm it works
  • Backup — Binary backup and export format reference
  • Scheduler — Full scheduler parameter reference
  • Email — SMTP client configuration
  • Fetch — FTP/SFTP transfer reference
  • Scripting — RouterOS scripting language reference