Skip to content

heximcz/routerboard-backup

Repository files navigation

Mikrotik Routerboard Backup

Latest Stable Version Latest Unstable Version License

Changelog

Read changelog for news.

Overview

Ultimate backup of your mikrotik routerboard configurations. Backup to local hard drive or backup to GitLab repository.

Prerequisites

PHP >= 7.4 ( from v1.0.3 )

Warning

Private Token support will be removed in GitLab 10.2, from this version please use Personal Access Tokens

Features

  • support for gitlab base64 file decode** (from 1.0.1)
  • Full support Gitlab API V4 (from 1.0.0)
  • Support for override default SSH port in the config file. (from v0.9.0)
  • Backup to GitLab repository. (from v0.8.0)
  • Auto generate RSA key if it does not exist.
  • Create a new account for backup on a routerboard with a public key.
  • Get routerboard identity and save IP address along with this one to database.
  • When backing up the routerboard, delete the old backup to create new ones. Only the current backup will remain on the routerboard; it will not fill the disk with the old backup.
  • Create standard .backup and .rsc backup files in the form of a script.
  • Your backups are stored on a local disk to the directories; each have in their name an identity and IP address of the backed-up device.
  • Your backups on the local disk are automatically replaced with the current backup. Only the last five backups remain. You will never have a full disk, even after many years to come.
  • If an error occurs while backing up, an email will be sent automatically.

Recommended

  • Do not forget set up "sendmail_path" value in php.ini ;-)
  • for example sendmail_path = "/usr/sbin/sendmail -t -i -f no-reply@your-domain.com"

How to install

  • Connet via SSH to your web server
$ cd /opt/
$ git clone https://github.com/heximcz/routerboard-backup.git
$ cd /opt/routerboard-backup/
$ git tag -l
$ git checkout tags/<last tag name of stable version>
$ cp ./config.default.yml ./config.yml
$ mkdir -p /var/log/routerboard-backup/
  • !! Do not forget to configure the config.yml !!

Create database

CREATE TABLE IF NOT EXISTS `routers` (
  `id` int(11) NOT NULL,
  `addr` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'IP address',
  `port` smallint(5) UNSIGNED DEFAULT NULL,
  `identity` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT 'System identity',
  `created` datetime NOT NULL,
  `modify` datetime DEFAULT NULL,
  `lastbackup` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

ALTER TABLE `routers`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `routers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

How to update Routerboard Backup

$ cd /opt/routerboard-backup/
$ git pull
$ git tag -l
$ git checkout tags/<last tag name of stable version>
  • How simply find out how to check the tag
$ git describe --tags

Example Usage

print help:

php ./routerboard-backup.php

php ./routerboard-backup.php rb:mod -h

php ./routerboard-backup.php rb:backup -h

php ./routerboard-backup.php rb:list -h

php ./routerboard-backup.php rb:gitlab -h

php ./routerboard-backup.php rb:decode -h

Using via crontab

add this line to your /etc/crontab: (backup of all in database one per week to local hard drive)

nano /etc/crontab

0 0 * * 6 root /usr/bin/php /opt/routerboard-backup/routerboard-backup.php rb:backup >> /var/log/routerboard-backup/routerboard-backup.log

add this line to your /etc/crontab: (backup of all in database one per week to GitLab repository)

0 0 * * 6 root /usr/bin/php /opt/routerboard-backup/routerboard-backup.php rb:gitlab >> /var/log/routerboard-backup/routerboard-backup.log

Logrotate script

nano /etc/logrotate.d/routerboard-backup

/var/log/routerboard-backup/*.log
{
	rotate 5
	monthly
	compress
	missingok
	notifempty
}

Donate

If this repo helped you set donating to the author of the program.

Bitcoin: 17MPKzx9jxssa5z83FBPmpfLYTpAcEEfLV

YouTube video: How to

Routerboard Backup Video How To

Product site

https://routerboard-backup.best-hosting.cz/

License

MIT