Prepare for Disaster
It happened once before when I was KK4FGM. I had a logbook on a computer that died, and I lost my entire logbook. It was never uploaded to LOTW, QRZ, eQSL, or anywhere, so I lost all credit for any awards or recollection! Since getting back into HF in December 2015, I have made 100% sure that I have duplicate copies of my logs and other important data on a separate device.
Expectations of Design
- Being a lover of Linux because of the ease of implementation and cost and functionality, I chose to use devices that run Linux.
- I have several Raspberry PI devices so I chose to use them. They are inexpensive, small, and consume little power. (I have 3 Raspberry PI model B and 1 Raspberry PI 3.)
- Should be online at all times, low maintenance, somewhat reliable.
- The data should be stored on a removable device that does not house the operating system. I chose to use a 32Gb USB drive.
- A script on my ham radio computer should gather the data that I want to back up, write it to a temp location, then SCP that data to the file server to store on the USB drive.
- Finally, I want the script to do the whole file transfer sequence without the need for passwords, so I need to install a shared SSH key on both devices.
- I didn’t do it on this device, but having a static IP on the LAN is advisable, but I didn’t want to mess with it right now.
- This description assumes you have some knowledge of how to move around in Linux. If you are a newbie, there will be some extra Googling involved to figure out some of the implementation.
Implementing the System
Step 1: I won’t go into the steps to get an operating system on the Raspberry PI because Installing Operating System Images does such a great job at it.
I have a Raspberry PI 3 as my ham radio computer running Raspbian Jesse. I use the same OS on my Raspberry PI model B.
Step 2: Make sure that SSH works on the PI file server. You need an Internet connection. I use a USB WIFI card, but LAN also works. Make sure that you can SSH into your server from another device. This is important!!!
Step 3: Insert a USB drive. Mount it. (Easier said than done…mine didn’t work out of the gate.) I will explain. I inserted my drive, but it did not mount. I think this is normal. Here’s how to do it:
- Before inserting USB run this command:
- Take note of what appears in that list. Now insert the USB drive and wait a second. Run that command again.
- Look through both lists and find the new entry. My entry that appeared for the USB drive was: sda sda1. sda1 is the partition location that needs to be mounted.
- First, make a directory in /media/. You’ll need root privileges to do this. Call the directory whatever you want, but remember it. I called mine cruzer, but BACKUP is memorable. Run this command:
sudo mkdir /media/BACKUP
- You’ll need to edit a file to add this so it mounts the file system. The file you need to edit is located at /etc/fstab, and you need root privileges to edit this file. I use a program called VIM to edit files. It’s not as easy as using NANO or GEDIT.
sudo vim /etc/fstab
- This is the line that I added for my drive. Your setup may look different, and you might need pointers from Edit FSTAB. There are other ways to handle it, but this is what I know to do. Add a line similar to this to fstab. Edit it to suit your needs.
/dev/sda1 /media/BACKUP vfat defaults,uid=1000,gid=1000,auto 0 0
- Save fstab and exit. Run this command to mount all drives:
sudo mount -a
- You should be able to access your USB drive. Try it out. Try to write something to it. It should work. Newbies will struggle some with this in a command line interface. The graphical user interface makes this so much easier.
- The last step is to allow SSH to log in automatically. This is best described by SSH with Keys. You could skip this step, but I don’t want to be bothered with a password when running my script. If this is too burdensome for the newbie, it could be skipped without too much trouble.
The last thing to do is to choose what you want to back up. It could be anything; It doesn’t have to be related to ham radio at all. Mine mostly is ham radio related since that is all I do on this computer. Write down each location that you want to backup. I had locations in FLDIGI and FLRIG directory, minicom directory, and my Documents directory. At some point I might also back up the whole Documents directory. I keep a few other logs and SKCC award files in there that I don’t want to type up again.
Writing BASH scripts can be a daunting task, and this is something that a newbie will certainly have the most trouble with! Take my script and use it to figure out how it works. Look at BASH Programming Introduction for tricks on BASH scripting.
This script does a couple of things. It copies the files that I want to a temporary directory. Then it takes those files and uses SCP to send them to the file server. Some things you need to know: the file’s location that you want to backup, the IP address of your server, and the location of your USB drive on the server. This shows my setup, and you can change what you need to make yours work. BASH programming is beyond the scope of this particular blog. There are many books and websites totally devoted to the task. It’s a programming language all its own, and knowing how to program can help you tailor the script.
2 thoughts on “Raspberry PI File Server: Backup Ham Radio Data”
Nice write up! Thanks for posting. Have you found the Pi B to be adequate for the task? I imagine writing periodically to a hard drive is not a terribly taxing operation….
The PI B seems to do very well for file transfers. I believe that the networking aspect is the slowest part, but without having experience in testing the efficiency and speed of read/write cycles, network speed, and other items relating to this task, I couldn’t make an educated guess. I haven’t had any issues with my system at this point. I hope to hear about your experience with backing up your logs! -Rob