Over the last 9 years or so, Bart Busschots has been teaching you and me to be geekier and more technical through his session in Chit Chat Across the Pond. First, it was random bits of knowledge but in the last few years he’s gotten much more structured about it, bringing us Taming the Terminal and now Programming By Stealth.
I have to confess (and you may have figured this out on your own), I don’t always understand everything he teaches me. Sometimes I understand in the moment, but when I go to apply what he’s taught me, I’m immediately baffled.A while ago, I moved podfeet.com to a Virtual Private Server. Bluehost kind of talked me into it. It didn’t cost a lot more money than the shared server I was on and I knew it would give us all much greater performance for the site. Nobody accesses podfeet.com more often than me, so it was really a present to me as much as to you.
There was one thing that didn’t entirely dawn on me when I agreed to this. On a Virtual Private Server, I am the system administrator! They do some stuff for me, but most of what I took for granted is on my plate. I called Bart in a panic when I found this out, and asked him if he’d officially be my sys admin. He suggested a better idea. Instead of him doing it for me, he wanted to teach me to do it myself!
When I was working I had 150 system administrators working for me. I know a few of them listen to this show and they are falling out of their chairs with hysterical laughter at this idea. I’m looking at you, Keith. I’ve come a long way but I have to be on their side that this is silly talk, but since Bart was willing to do it, I had to jump at the opportunity to learn even more.
This week we worked on some scripts that he wrote that he said we could configure to back up my server to my local drive on our Mac mini. In August of 2015, Bart gave us an introduction to JSON and explained that it’s very useful to create configuration files that can be fed into programs. When Bart created his backup script, instead of making multiple versions for all the servers he managed, he used JSON to make configuration files for the peculiarities of each server. I was so excited that I immediately understood why he used JSON.
During our last few sessions he let me drive while he watched on Skype. I created a public/private key pair so we could talk to the server from the Mac mini, then we modified the JSON configuration file and got everything working. Now every single day at 2 in the morning, a database dump occurs up on podfeet.com, and then the Mac mini pulls that file down. Using rsync, it also pulls down a copy of all of the files associated with podfeet.com. The files are, in my case, mostly images I upload for the blog posts, while the database itself contains all the words that I’ve typed over the last 11 years, the theme for displaying the content, and other bits and bobs like users and plugins.
This was all going swimmingly, but today I was looking at the directory structure on the Mac mini and I saw something I didn’t quite like. We created a log file to let us know if the backups had worked properly. It’s called, quite imaginatively, backup.log. We stored it at the top level of my user account. We also created a directory at the top level of my user account called podfeet_backups, and that’s where the actual backups get plopped, all into neat little daily folders.
I didn’t like having that log file sitting out in the open where Steve or I might accidentally throw it away or clean it up in some fashion that would make it break. I knew I could simply drag it into the podfeet_backups folder, but that would probably confuse the backup script, or at the very least I’d end up with two files.
You’ll never believe what happened next! Sorry, channeling Buzz Feed there for a minute. I noodled around a bit and looked at the backup script itself, but it’s got a lot of stuff in it Bart hasn’t told me about yet. I thought maybe the JSON configuration file would point to where the log file would be written but it wasn’t in there either. It did have the location of the folders of content that were backed up but not the log file.
Then I reached back in my brain to recall how we actually make this backup script go and I remembered we’re using a cron job. Cron is a utility that can be set to run in the background at regular intervals. Crontab is the text file where you define those things that you want to run, and it also tells cron when to run them.
I whipped open my notes from the last time we worked on it (I keep them all in Together from reinventedsoftware.com) and found what I was looking for. In the crontab we told it what time to run (using days, hours, minutes, and seconds), we told it the name of the script to run, we told it the JSON configuration file to use, and the very last bit was where to spit out the log file!
Now all I had to do was remember how to edit that crontab. This next part is why I entitled this segment, “I have made fire!” For as long as I’ve been able to spell UNIX, people have told me, “Just look at the man pages to figure out how to use a command.” And not once, in the 20 years or so people have been saying this to me, have I figured out how to do what I wanted to do from the man pages. Until today. Right there in the man pages, it said to write crontab and follow that by -e and I’d be in an editor! I didn’t know what editor I’d be in but I hoped I could guess.
I think I ended up in vi, which is an editor I learned to use in the late 1800s. I saw where I wanted to insert the directory name to push the file down a level. I arrowed over, closed my eyes, and tapped the “i” key. At the bottom of the file, I was rewarded with the word “INSERT”. Yay! I typed in the folder name. Now I had to remember how to get out AND save the file. Scraping back in the memory banks (from the last time Bart and I mucked in this file) I typed escape, then colon wq for write, and then quit. The file saved and it worked!!!
I know this is a silly little example, but it makes me so very happy to have been able to do such a simple little procedure, ALL BY MYSELF.