{"id":1411,"date":"2016-09-05T21:54:13","date_gmt":"2016-09-05T21:54:13","guid":{"rendered":"http:\/\/www.incredigeek.com\/home\/?p=1411"},"modified":"2016-09-05T21:55:08","modified_gmt":"2016-09-05T21:55:08","slug":"mikrotik-backup-script","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/mikrotik-backup-script\/","title":{"rendered":"Mikrotik Backup Script"},"content":{"rendered":"<p>This is a Linux script for creating and backing up backups on Mikroitk routers.<\/p>\n<p><strong>Features<\/strong><\/p>\n<ul>\n<li>Creates the backups automatically, no need to manually create a backup on the Mikrotik<\/li>\n<li>Uses SSH and SCP for encrypted communication between the router and the server<\/li>\n<li>Runs on linux<\/li>\n<li>Easy to use command line interface<\/li>\n<li>Can back up single or multiple routers<\/li>\n<\/ul>\n<p><strong>Future Features<\/strong><\/p>\n<p>These are features I am planning on adding to the script in the future<\/p>\n<ul>\n<li>Ability to compare backups and remove duplicates<\/li>\n<li>Make the script smarter so it can detect a backup on a router and leave it instead of deleting it<\/li>\n<li>Add better logging<\/li>\n<li>Add the functionality to upload the backups to an online service like DropBox, or OneDrive automatically<\/li>\n<li>Add alert mechanism to alert you if a backup failed or router is unreachable<\/li>\n<\/ul>\n<p><strong>Current Bugs or limitations<\/strong><\/p>\n<ul>\n<li>Deletes all backups off of the router, so if you manually created a backup it will delete it without asking<\/li>\n<li>To stop backing up a router, you&#8217;ll need to manually delete the IP address out of the IP database i.e(ip.lst file.)<\/li>\n<li>It does not currently have the ability to delete backups<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Requirements<\/strong><\/p>\n<ol>\n<li>Linux box to run the script from and to store the backups.\u00a0 You can run it from a laptop or VirtualBox.<\/li>\n<li>You&#8217;ll need the following programs for this script to work(fping, sshpass)<\/li>\n<li>The Linux box need to be able to ping the routers, if it can&#8217;t the script will fail<\/li>\n<\/ol>\n<p><strong>Installing<\/strong><\/p>\n<p>Download program<\/p>\n<pre><code>wget www.incredigeek.com\/home\/downloads\/mtbackup\/mtbackup.sh\r\nchmod +x mtbackup.sh<\/code><\/pre>\n<p>Now open up the script and edit the variables at the top for your username, password, and where you want the backups.<\/p>\n<pre> nano mtbackup.sh<\/pre>\n<p>When you have finished editing the variables, hit CTRL+x, and then &#8220;y&#8221; and then &#8220;enter&#8221; to save the file.<\/p>\n<p>If you want to setup the script to backup on a regular basis then setup the script to run in cron.<\/p>\n<p>Run &#8220;crontab -e&#8221; and add the following line<\/p>\n<pre><code>10 1 * * 1 cd \/root\/mtbackup-1.0\/ &amp; sh mtbackup -b<\/code><\/pre>\n<p>Hit CTRL+x, and then &#8220;y&#8221; and then &#8220;enter&#8221; to save the file.<\/p>\n<p><strong>Adding routers to backup<\/strong><\/p>\n<p>Adding routers is really easy.\u00a0 All you have to do is run the script with the -a option and then the ip address and the script will check if it can reach the IP and then add it to the IP Database i.e.(ip.lst file that contains all the routers ip addresses)<br \/>\n.\/mtbackup.sh -a 192.168.88.1<\/p>\n<p>Example:<\/p>\n<pre>[root@localhost mtbackup-1.0]# .\/mtbackup.sh -a 192.168.88.1\r\n#################################################################\r\n\r\nThis is a Mikrotik Backup Utility.  Still being updated and worked on!!!\r\n\r\n#################################################################\r\n\r\nAdding 192.168.88.1 to the ip DB\r\nAdded 192.168.88.1 to ipDB\r\n[root@localhost mtbackup-1.0]#<\/pre>\n<h1>Backing up all routers<\/h1>\n<p>You can manually backup all the routers by running the script with just the &#8220;-b&#8221; option.\u00a0 It&#8217;ll read every IP in the IP database and create a backup for each one and put it in the backup folder with is normally &#8220;.\/backups&#8221;, you can change it in the variables portion of the script.<\/p>\n<pre>.\/mtbackup.sh -b<\/pre>\n<h1><\/h1>\n<h1>Other examples<\/h1>\n<p><strong>List routers in the IP Database<\/strong><\/p>\n<pre> [root@localhost mtbackup-1.0]# .\/mtbackup.sh -L\r\n#################################################################\r\nThis is a Mikrotik Backup Utility. Still being updated and worked on!!!\r\n#################################################################\r\nListing Hosts...\r\n192.168.88.1\r\n10.200.1.1\r\n172.20.1.1\r\n33.11.2.22\r\n[root@localhost mtbackup-1.0]#<\/pre>\n<p><strong>Backup Single router<\/strong><\/p>\n<pre>[root@localhost mtbackup-1.0]# .\/mtbackup.sh -B 192.168.88.1\r\n#################################################################\r\n\r\nThis is the Mikrotik Backup Utility. Currently under construction!!!\r\n\r\n#################################################################\r\n\r\nStarting to do backup on 10.9.0.1\r\n\r\nConfiguration backup saved\r\n[root@localhost mtbackup-1.0]#\r\n<\/pre>\n<p><strong>Other commands<\/strong><\/p>\n<pre>[root@localhost mtbackup-1.0]# .\/mtbackup.sh -h\r\n#################################################################\r\n\r\nThis is the Mikrotik Backup Utility.  Still being updated and worked on!!!\r\n\r\n#################################################################\r\n\r\nUsage\r\n.\/mtbackup.sh [OPTIONS]\r\n.\/mtbackup.sh -b 192.168.88.1\r\n\r\n-l      List backups\r\n-L      List Hosts\r\n-b      Backup all hosts in the IP database\r\n-B {ip} Backup Single Host, Specife IP\r\n-a {ip} Add ip to IP database\r\n-v      Version\r\n\r\n[root@localhost mtbackup-1.0]#<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is a Linux script for creating and backing up backups on Mikroitk routers. Features Creates the backups automatically, no need to manually create a backup on the Mikrotik Uses SSH and SCP for encrypted communication between the router and &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/mikrotik-backup-script\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[75,304,302,305,7,301,303],"class_list":["post-1411","post","type-post","status-publish","format-standard","hentry","category-linux","tag-backup","tag-backup-utility","tag-backups","tag-hhj","tag-linux-2","tag-mikrotik","tag-router-os"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/1411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=1411"}],"version-history":[{"count":23,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/1411\/revisions"}],"predecessor-version":[{"id":1434,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/1411\/revisions\/1434"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=1411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=1411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=1411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}