Created
November 18, 2018 22:56
-
-
Save shanehull/c767d8fe970bcb19b1ee4d9cff88f735 to your computer and use it in GitHub Desktop.
Script to backup Mikrotik config to disk, upload via FTP and ping healthchecks.io url.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Settings | |
:local backupPath path/to/mikrotik.backup | |
:local healthchecksURL https://hc-ping.com/example | |
:local ftpAddress 192.168.1.10 | |
:local ftpFullPath path/to/ftpserver/mikrotik.backup | |
:local ftpUser ftpuser | |
:local ftpPassword password | |
# Check if router can ping WAN | |
if ([/ping 8.8.8.8 count=5]=5) do={ | |
# Create current backup to the set backup path | |
:execute [/system backup save name=$backupPath] | |
:log info "Creating backup of configuration..." | |
:delay 10s | |
# Get current date | |
:local currentDate [/system clock get date] | |
# Get existing backup file date | |
:local creationTime [/file get [/file find name=$backupPath] creation-time] | |
:local creationDate [/pick $currentDate 0 11] | |
# Compare creation date to current date. | |
:if ($creationDate = $currentDate) do={ | |
# If dates match, upload current file to FTP server | |
:log info "Uploading file to $ftpAddress:$ftpFullPath" | |
:tool fetch mode=ftp upload=yes address=$ftpAddress src-path=$backupPath dst-path=$ftpFullPath user=$ftpUser password=$ftpPassword | |
# If dates match, ping healthchecks.io. If not; log warning. | |
:tool fetch mode=https url=$"healthchecksURL" http-method=get keep-result=no | |
:log info "Config backed up to $"backupPath", uploaded to $ftpAddress:$ftpFullPath and ping sent to healthchecks.io" | |
} else={:log warning "Failed to ping healthchecks.io... Current backup file not present." | |
} | |
} else={ | |
:log warning "Ping failed to 8.8.8.8... Config not backed up." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment