The importance of backups

What happens when it all goes pear shape

A couple of days ago we had a small power “glitch” here. Apart from the microwave clock going back to zero and the TV going off the Raspberry Pi that this site runs on went down.

When I powered it back up I found that my WordPress site was devoid of content. Further panic stricken investigation revealed that the “wp_posts” table in the database had a corrupt index. After much gnashing of teeth, googling and experimenting (after taking a copy of course) I was unable to fix the problem.

What to do ? Well I bit the bullet and restored a backup I’d take about a week earlier using the “Updraft” plugin. Apart from losing a week’s worth of content all was well. And this is where good fortune stepped in.

During the couple of hours before the power glitch I’d been messing around putting an “RSS Subscribe” in the side bar and testing it on my iPhone. It proved to work well too so on a whim I had a look at the RSS on my phone and it had handily retained all of the content from this site so I was able to e-mail it to myself. From there it was a simple matter to copy and paste the content to the recreated posts. Whew.

The only thing that I lost was about a week’s worth of stats from “WP Statistics” plugin. I can live with that but I’d rather that I didn’t have to though.

OK so I was lucky

So, this time I was lucky ! I only lost a very minimal amount of stuff. The stats and the configuration for Google AdSense.

As a retired large system administrator I know full well the importance of good backups. I wasn’t taking them on a regular basis because “what could possibly go wrong”.

I’m now using a Linux backup package for the whole Pi and I’ve scheduled a backup of WordPress once a day. As well as that I’m taking an Updraft backup right atfer I do anything of any note to WordPress or the system as a whole.

Raspberry Pi and TVheadend

How to turn a standard definition TV into a HD TV using TVheadend

What you’ll need to get TVheadend up and running

A Raspberry Pi 4 and a Raspberry Pi DVB TV Hat or a DVB-T/T2+C+FM+DAB dongle. You’ll also need a TV with HDMI input to plug the whole shooting match into.

The first thing to do is to get Raspbian installed and updated to the current standard. I didn’t pay any attention to secure passwords, etc. as this Pi is not going to be connected to the internet directly. Access is only going to be from the home network.

The next thing to do is to plug in either the Pi TV Hat

TV Hat

or your dongle.

DVB-T/T2/C+FM+DAB dongle

 

Next step is to install TVHeadend – “sudo apt install tvheadend” will get the job done. Before you start on the next step a very important step is to plug the antenna into either your TV Hat or dongle.

Getting it configured

When you are installing TVHeadend be sure that you select a username and a password combination that’s dead easy to remember.

When you’ve got it installed break out your trusty web browser and go to https://x.x.x.x:9981. The x.x.x.x could be localhost if you are doing it from either a TV or monitor connected to the Pi or it could be another system connected to your home network. In either case you’ll be prompted to supply the username and password that you specified during the TVheadend installation. You’ll be presented with a configuration page which is easy to work through. There’s a wealth of info at tvheadend.org which will see you right.

At this stage you should have an Electronic Programme Guide (EPG) visible in your browser and now’s the time to test it to see if it all works. If at this point if you have no success go back to the TVheadend configuration. It took me a few iterations to get a handle on how it works. Once you can see the EPG you’re home and hosed.

Be aware though, you really do need a decent TV antenna to get it working. I don’t think the receivers in either the dongle or the Pi TV hat are very sensitive. Another problem that I ran into was getting the correct region to scan. I started out using “au-other” which was incorrect. When I used “au-Melbourne” it worked as advertised. Like all of my other issues, it was my faulty configuration.

Testing and Job Done

At this point yould be able to select a programme in your browser. You now may have problems getting your browser to support the stream from TVheadend. Don’t worry, salvation is at hand in the form of VLC which can play network streams.

Just install it on the system that uses your old, slow, standard definition TV. Open it up and go to “media -> Network Stream” and enter the followung “https://username:password@x.x.x.x:9981/playlist/channels.m3u” where “x.x.x.x” is the network address of the system that uses your TV as the display. Or any other system on your local home network. You may have to select “View -> Playlist” from the menu to get the playlist. From there you just select the channel that you want. Double click on it and hit full screen mode.

Be aware though, you’ll need a high speed network connection between the system with TVheadend and the system with the TV attached. Of course if the system with TVheadend is directly connected to the TV then this is redundant.

With this setup I can take my tablet down the back yard to the BBQ area and kick back with the cricket and a glass of wine or two. I can’t watch HD TV there though – I’m only just in range of my 2.4GHz wifi which doesn’t quite cut it but hey, it does the job.

Sit back with a glass of your favourite and watch the programme of your choice in HD whilst congratulating yourself on a job well done.

The second last word

Since I got it working I have acquired a few Pi Zero’s for one thing or another and one of them has been pressed into service as my TVHeadend “Server” so I have a dedicated Pi Zero for TVHeadend.

It works every bit as well as the Pi 4 and it just sits alongside my media player Pi 4 behind the TV with only two connections – TV antenna and power. CPU utilisation is around 30% and the temp is around 40 deg C with them ambient at around 20 deg C.

The last word

If you’ve had a poke around this site you’ll see that my wife and I do a fair bit of travelling. One of the things that we take with us is a smallish 12 volt TV and an antenna. Sometimes, however, we get to a place where there is little to nil TV reception. No problem.

I’ve set up port forwarding on my router to allow a connection to my TVHeadend Pi. Using an app called “tvhclient” we can watch TV on my iPad or our iPhone’s. Although we use iPhone’s and an iPad the app is also available for Android. I’ve sort of tested it but the Android tablet I have is of such low power that it’s unworkable although it can get the channel list and attempt to display something.

In areas of good mobile phone signal we can watch high definition TV but usually it’s standard definition only. Of course the only programmes that we get to watch are those that are available on free to air TV at our home base though.

If we find a programme that we really want to see we can set TVHeadend to record it for us and then download it to my iPad and watch it at our leisure.

What seemed like a hare-brained idea turened out to be a good workable solution to what was a tiny problem.

This whole Raspberry Pi thing is getting more complex by the day such is the versatility of these small computers.

 

More LAMP and WordPress

Well there have been some “developments” since I got LAMP and WordPress going.

I’ve tried and abandoned an e-mail server.

I’ve decided that 500GB of storage isn’t enough given our collection of “stuff” – you know, pictures, movies, TV series (Medici is good), music, etc. so I got my grubby fingers on a couple of 2TB Sandisk Extreme SSD drives. Using the same procedure I used to move the /root partition from the SD to the 500gb SSD I moved the /root partition again to a 2TB SSD. I left it as a single, big partition and made a mount point for the second 2TB SSD and put that in fstab using PARTUUID. I moved the contents of our ancient NAS drive onto that. It makes a huge difference to have a share (Samba and NFS) on a 1Gb network connection rather than the old 100baseT connection.

We now have more than enough storage for our foreseeable needs and it’s fast too. I’ll have to get a four port, powered USB 3 hub though. Copying downloaded stuff over the network or via USB 2 is slooooow compared to USB 3.

Meanwhile the Pi 4 4GB keeps on rocking along.

Getting e-mail happening

So I had this brainwave and thought it’d be a good idea to set up a Pi as an e-mail server. After all, how hard could it be, there are hundreds of thousands of mail servers around the globe that work well. What could possibly go wrong ?

I started out trying to keep it simple. I’m pretty familiar with Sendmail but I figured that I’d go with something simple as I was only going to serve two users and Sendmail seemed a lot of overkill.

After a bit of searching Citadel seemed to fit well. I installed it and configured but there is no way I could get past a couple of errors not the least if which is “db:cursor still in progress on cdb 02: attempt to write during a r/o cursor”. I tried a completely fresh install of Raspbian Buster with a brand new install of Citadel. Still no dice. Searched for more comprehensive doco but, again, to no avail. I reckon I just about wore out the search engines looking for a solution but still no illumination. I even tried downloading the source and buildin it from scratch. The same olf “db:cursor still in progress…” error persisted.

Scratch Citadel which is a pity really as I reckon it’d be the bees knees for a simple and small e-mail server.

On to Dovecot and Postfix. I had a few issues but by carefully following the documentation on Postfix.org I had it all up and running. In the beginning I had a lot of trouble getting “saslauthd” to do the authentication and I spent a goodish amount of time trying to treat the symptoms without success. At this point I decided to get rid of postfix and dovecot and start again from a new install of both. The big difference this time was that I folloed the docs on postfix.org to the letter. Surprise, surprise it all worked as it should.

After years and years of telling people to RTFM I didn’t.Once I did RTFM I proved my own point yet again.

Now came the hard part. DNS records. I use a dynamic DNS which has served me very well thus far. Setting up the MX record was very easy but I discovered I needed a PTR (for reverse lookups) and this is where the gremlins started to creep in. I needed a static address. No problem just ask my ISP, right ? Easily doable, for another ten bucks a month. Sign the static IP over to the dynamic DNS provider so that they can use it for all DNS records. ISP says – “oh no we can’t do that”. Luckily my dynamic DNS provider has a facility that can easily get around that particular scenario.

Now that it all works, I’m happy and am quite willing to advocate for the Postfix / Dovecot sulution. It’s a lot easier to configure than Sendmail. The configuration files are well commented and make sense, unlike Sendmail.

If you’re considering setting up your own mail server first check that you can get a PTR DNS record. If you can’t look for another solution. If you can, RTFM and pay attention to the details and recommendations.

Just for fun and games on our internal network I set up a DNS complete with MX and PTR records and with the internal e-mail system configured to insist on reverse lookups it worked perfectly with no errors. Of course this was only with two Pi’s, two PC’s and two windows tablets. I’ve got rid of it all now I know how to make it work and that there’s no point with an uncooperative ISP.

What to do with a second Pi

As the title asks – what to do with a second Pi ? I “accidentally” ended up with a Raspberry Pi 4 1GB to partner my 4GB unit so what to do with it.

The original Pi has LAMP installed and running well. It’s also got 1TB of storage for all my videos and photo’s and stuff and we use it to watch movie’s and TV series using our lounge room TV as the monitor. It works really, really well so I’m quite reluctant to change anything. It does need a fan heatsink though, to keep the temperatures under control. With the fan it only gets up to 55deg C max.

I have a USB DVB-T/2 dongle as well as a Pi TV hat. The TV hat doesn’t fit on my 4GB Pi because I have a fan case on it and a couple of the GPIO pins are used to power the fan. The TV Dongle was pressed into service and works OK with TV Headend. It’s not as sensitive as the Pi Hat despite using the same chipset so I pressed an RF amplifier into service in the antenna cable and it works a treat.

So. In the lounge room, behind the TV I have the 4GB Pi with a TV dongle and a 1TB SSD  with all my stuff attached. In the bedroom, where there’s no antenna socket, I have a smaller TV and a Pi 1GB. The Pi, using VLC, can play the TV from the lounge room Pi running TV Headend and using Samba can also play, using VLC again, all of our shows and movies.

Given that we’ve got good WiFi 5GHz coverage throughout the house thanks to a couple of WiFi extenders, for our grandson and visitors all I need to do to give them HD TV and shows and movies is to move the Pi and give them a keyboard. Our grandson can watch his Youtube stuff to his hearts content without annoying us.

Seeing as how successful that is I reckon another Pi to use for the same purpose in the BBQ area out the back could be the go. Watching the cricket while we’re having a BBQ and a few beers sounds pretty appealing to me. Setup is easy – Latest Raspbian with VLC, power supply and HDMI cable. Seems a bit of a waste of a Pi 4 though. I’ll have to have a look at the specs and get a few opinions of the capabilities of “lesser” and cheaper Pi’s and maybe get a couple more.

Moving the root partition.

This a summary of an article describing how to move the root partition found on the Raspberry Pi Forums .

Before you do anything do a “lsusb”without your external storage plugged in. Then plug in your external storage and do a “lsusb” again to make sure that your storage is going to work OK.

Before you start give a bit of thought as to how you want your storage partitioned. I just left my SSD as a single 500GB partition. In the future I can see that I’ll be adding more to house my collection of music and videos.

Anyway, without further ado, if you follow this guide  to the letter I’m quite sure you’ll have no problems.

LAMP + WordPress

This is not intended to be a complete HOWTO for Linux (Raspbian), Apache2, PHP, MySQL and  WordPress on a Raspberry Pi 4 4GB. What it is supposed to be is a guide that demonstrates that it is easy to get LAMP + WordPress going on a Pi with some links to the documentation that I used.

Assuming you’ve got your Pi and possibly some external storage it’s important to plan out what you’re trying to accomplish and how you want to go about it.

So, I had a 4GB Pi4 as well as a Sandisk Extreme external SSD. First step was to get the latest Raspbian (Buster) in an SD card and booting. Once that was accomplished I installed Apache2 and got that working properly. MySQL / MariaDB was the next cab off the rank followed by PHP and php-mysql.

After each step it’s a damn good idea to make good and sure that what you’ve just installed works properly.

Downloading and installing WordPress was quite possibly the easiest part of the whole process.

For each of the LAMP components there is a heap of available documentation available – remember that Google is your friend. The Raspberry Pi Forums are a brilliant resource. The MariaDB documentation is comprehensive to say the least as is the PHP documentation. There is more WordPress documentation than any mortal could ever want.

So, the steps I followed were :-

  1. Get Raspbian working.
  2. Download, install and get Apache2 working.
  3. If you are going to get SSL working this is when you’d do. I decided not to and just skipped it.
  4. Download and get MariaDB installed and working.
  5. Get PHP and php-mysql downloaded, installed and working.
  6. Get the latest version of WordPress downloaded and installed.
  7. In MySQL reate the WordPress user and the WordPress database.
  8. Set up the privileges for the user.
  9. Configuring WordPress is pretty trivial IF you follow the WordPress procedures.

This is a much more complete HOWTO.

Once I got it all working I set about getting all my stuff over from an ISP’s server. Lots of copying and pasting is all it took.

Once I got it all over I started messing around with WordPress themes and layouts. The choices are bewildering and the theme and layout of this site is a “first attempt mess” which I’ll refine as I work out what I want and how to get there.

At this point I decided that a 32GB SD card probably wouldn’t be enough so I decided to press a Sandisk Extreme 500GB SSD into service. I found a great HOWTO on the  Raspberry Pi Forums and it worked first time. I’ll put that procedure into another post.

Getting rid of the heat

So when I use the Pi to watch movies on our TV it tends to get a bit hot under the collar – up to around 81 or 83degC. Something needed to be done about that state of affairs so I installed it in a heatsink case with fans.

Pi with heatsink case with fans.

Much better. No matter what I do I can’t get the temperature over 55degC.

While I was at it I decided to go with the 64 bit kernel so I added arm_64bit=1 to config.txt so now uname -a gives me :-

Linux markpi 4.19.75-v8+ #1270 SMP PREEMPT Tue Sep 24 18:59:17 BST 2019 aarch64 GNU/Linux

Everything still works as it should – Apache2, PHP, MySQL and VLC which we use a lot for movies, tv series, etc.

The next step is a TV HAT or a TV USB dongle – probably the dongle as that won’t mean messing around with GPIO standoffs, etc to get it to fit with the heatsink.