[00:00] Hey guys Matt here from MKSmartHouse.com and in this video I am going to show you the complete way to backup your openhab server using windows. [Intro] [00:16] Imagine that one day you open up your openHAB app on your phone and there is nothing there, you then quickly go to your computer and try to ssh into the server but it just keeps saying At this point all is lost, all your hard work, all the time you put in, simply gone. [00:33] But, lucky for you that was just an imagination and it can all be simply avoided by following In this complete guide I will cover exactly how to backup your openhab server. [00:45] The way this backup will work is there will be an external flash drive plugged into the raspberry pi and every day the raspberry pi will backup the openhab configuration and Now, this does solve a majority of the backup problem but what about the rest of the pi [01:02] Well, since we don't change much non openhab items on the raspberry pi after it is initially set up, we will do a manually backup of the SD card onto the flash drive through the computer. [01:15] The items needed to complete this guide are the following: Number one, is a fully setup any model of raspberry pi running openhab, I am using a raspberry pi 3 in a clear enclosure [01:29] that has a fan which generates a lot of air flow to the raspberry pi, I also installed I did this much cooling because I never want to run the risk of the pi overheating and [01:42] If you want a kit to protect your pi you can find it at mksmarthouse.com/shop. If your pi is not setup check out my home automation server setup guide. [01:54] Number two is a computer running windows, if you have a mac computer then check out Number three, is an SD card reader of some kind that can read the type of SD card you [02:07] have in your pi, I only need a micro SD card reader but this one reads both sizes of sd Lastly, number four you need a flash drive that is the same size as the sd card in your [02:19] pi my sd card is 32gb so I bought a 32gb flash drive. The links to all the parts and guides mentioned are in the video description. Speaking of links in the description, follow @mksmarthouse on twitter, instagram and snapchat [02:36] because those are the place where I give sneak peaks on when videos are releasing and also where I ask for your input on topics and future videos. The first thing we have to do is plug the flash drive into the computer. [02:49] Next open up file explorer and click on this PC. The next part we are about to do will erase everything on the flash drive so make sure Right click on your flash drive and press format [03:03] In the volume label box type in OHBACKUP and in the filesystem select exFAT. Next we need to head over to the written version of this guide on my website, link is in the [03:16] Here we need to download the OHBackup_script. This is the script that we setup to automatically backup openhab every day at 12am and it will also delete backups that over 30 days old in order to not fill up the flash drive completely. [03:32] So go over to your downloads folder, double click on the zip file and then drag the script Once that is copied over eject the flash drive from your computer. [03:44] Grab the flash drive from your computer and plug it into the raspberry pi. Before we get any further I just wanted to show you the basic ui of this server to demonstrate that this pi is fully configured and has a sitemap with items in it in other words it [03:59] I have already done this process to my main openhab server which is why I will be using I recommend having the written version of this guide open so that way you can just copy [04:14] The first thing we have to do is install support for exfat so type in sudo apt-get install You may need to type in your password and press enter. [04:28] It will then ask if you want to confirm type y and press enter. Next enter super user so type in sudo su and press enter. [04:40] Next we have to make a directory to mount the flash drive to, so type in mkdir /mnt/OHBackupDrive Now we have to find out what the UUID or id number of our flash drive is in order to mount [04:58] it to the directory so type in lsblk -o UUID,NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL,MODEL and press enter. [05:10] As you can see this is the 32gb flash drive I inserted into the pi and here is its UUID, In order to mount the flash drive to the directory we need to modify the fstab so type in nano [05:27] 16. Now at the bottom of the file type in UUID=C73C-F2E6 /mnt/OHBackupDrive auto defaults,auto,umask=000,users,rw Replace the UUID with the UUID of your flash drive. [05:41] Once you changed the UUID press control x then y and enter to save. Now to execute the mounting procedure instead of rebooting type in mount -a and press enter. [05:54] To confirm that it mounted to the directory type in df -k /mnt/OHBackupDrive and press enter, you should see how much of the folder is used and some other information. [06:08] Ok, now we are done with super user so type in exit and press enter. Next up is to copy the script from the flash drive to the bin folder do this by typing [06:20] in sudo cp /mnt/OHBackupDrive/OHBackup_script /bin and press enter. Next we need to give the script permission to execute, so type in sudo chmod u+x /bin/OHBackup_script [06:40] To execute the script type in sudo /bin/OHBackup_script and press enter. You should see it say Openhab backup script and Success! [06:54] Now, let's confirm that it did save so type in cd /mnt/OHBackupDrive and press enter then You should see a zip file. [07:07] 27. Now let’s make this backup process happen automatically everyday at 12 am. Type in sudo crontab -e and press enter. [07:20] It might ask you which editor to use, type in 2 to use nano and press enter. In the bottom of the file type in 0 0 * * * /bin/OHBackup_script what this does is execute the backup script [07:34] 30. Like I mentioned in the beginning the script only backs up openhab stuff like your items, things, sitemaps, configuration files etc, so stuff like the the mqtt server settings [07:51] will not be backed up, those things we need to backup manually. I recommend backing up manually before/after every time you make a change to the raspberry pi that is not directly integrated with openhab or when you make an openhab software update. [08:06] In order to backup manually we need to first shut down the pi so type in sudo halt and Once the pi is fully shut down and the lights are not blinking, unplug the power cable, [08:21] Then plug the sd card and flash drive into the computer. Next open up win32diskimager and press yes in the pop up, if you don't know what win32diskimager [08:33] is then go check out my automation server setup guide windows version. Anyway click on the little folder icon, we are now going to choose where to save the img, so choose your desktop and name the backup whatever you want, before you click save take [08:48] a look at what letter your sd card is and then click save. 38. Once it finished open up file explorer and select your flash drive. [09:01] 40. Now, right click on the img file and hover over to send to and click compressed. 42. [09:14] Once they are plugged in you can connect power again. Congratulations, you are now safe from potential failures and part of the small percentage [09:26] of people that actually backup their OpenHAB server. Help spread awareness of backing up openhab by sharing this video everywhere you possibly can and save people from the headache of a failed server with no backup. [09:42] To demonstrate a change made after a manual backup I am going to make a modification to As you can see the sitemap is changed. Now for demonstration purposes I am going to issue a OpenHAB Runtime backup with the [09:57] command sudo /bin/OHBackup_script normally your backup would occur automatically at 12am but for the purposes of this video I am going to back it up now. [10:10] You can also use this command if you are about to do any modifications to the configuration files and want something to fall back on just in case you mess up. For demonstration purposes I am going to simulate a raspberry pi failure that can happen to [10:24] [Hits raspberry pi with the hammer] Now lets go over how to restore your openhab server if it did go through a failure. You would first plug both a new sd card either the same size or bigger than the original [10:40] and the OHBackup flash drive into the computer. Then open file explorer to your SDCardBackups folder and drag the backup you want to use Once it finishes copying right click on the zip, click extract all and then extract. [10:56] Then open up win32diskimager, and click yes in the pop up. Now select your sd card letter in the drop down and then click on the folder icon. It will bring up the file explorer, navigate to your desktop, unzipped image folder and [11:11] Then click write backup. Once it is formatted eject the flash drive and sd card and unplug both the sd card and Plug both items items into the pi and plug in the power cable. [11:25] Once the pi boots up ssh into it through terminal. The first thing we have to do is get into the backup drive and see which zip file we want to restore to so type in cd /mnt/OHBackupDrive and press enter. [11:39] To see what's inside type in ls and enter. 10. Next we need to stop openhab so type in sudo systemctl stop openhab2.service and press [11:56] Now we are going to restore openhab so type in sudo $OPENHAB_RUNTIME/bin/restore /mnt/OHBackupDrive/INSERTBACKUPNAME.zip before you hit enter replace INSERTBACKUPNAME [12:08] 12. 13. Finally, start up openhab again by typing in sudo systemctl start openhab2.service and [12:23] Your openhab server should be fully restored. If I open up the basic UI you can see all the data is still there including the recently Finally, that concludes this complete guide to backing up and restoring your openhab server. [12:41] In the description you will find links to all the parts and devices used in the video as well as a link to mksmarthouse.com/shop where I have a wide range of smart home kits that you can put together such as blinds, led strips, sprinkler system and door sensors. [12:57] section below or head over to mksmarthouse.com/forum. Good Bye!