MikroTik does not natively support Git, but you can push configuration backups to a remote server and where they are automatically committed and pushed to a Git repository.
This guide will help you set up a system for backing up MikroTik configurations using Git. This lets you track and revert changes easily.
- A remote server with PKI Authentication Enabled and a Git repository.
- Scheduler on your MikroTik to automate backups.
Create a scheduler to run the backup daily:
/system scheduler add interval=1d name=config-daily-backup on-event="config-daily-backup-script"
Configure Git on your remote server then Replace SFTP_SERVER_ADDRESS
, SFTP_USERNAME
, and REMOTE_PATH
with your details:
:local config ("config_" . [/system identity get name])
:do {/export file=$config show-sensitive} on-error={/log error "Configuration export failed"}
:local sftpAddr "SFTP_SERVER_ADDRESS"
:local sftpUser "SFTP_USERNAME"
:local sftpDirectory "REMOTE_PATH"
:local sftpUrl ("sftp://" . $sftpAddr . ":" . $sftpDirectory . "/")
:do {
/tool fetch url=($sftpUrl . $config . ".rsc") src-path=($config . ".rsc") user=$sftpUser upload=yes;
:delay 5s;
/file remove ($config . ".rsc")
} on-error={/log error "File upload failed"}
:do {/system ssh-exec address=$sftpAddr user=$sftpUser command=("cd " . $sftpDirectory . "; git add " . $config . ".rsc; git commit -m \"config backup for " . [/system identity get name] . "\"; git push")} on-error={/log error "Git operations failed"}
On your remote server, install and configure Git if not already done. Create and init Git repository in the desired directory
mkdir REMOTE_PATH
cd REMOTE_PATH
git init