I was making a crontab script for a customer today when I got the inspiration to finally do what I have been wanting to do for a while. I wrote a script to write the script for me. This handy script reads in 4 parameters:
- The working directory (where to cd to)
- A binary file (or command to run)
- A file containing the PID of the process to restart
- An output file to save the script to.
This generates a script that can be run from anywhere, like the crontab which will check to make sure the process is running. It will restart the process if not by running the binary file parameter.
The generated script is based on the Unreal3.2 ircdchk script, with some slight modifications. I hope someone finds it useful… if you do, drop a comment here.
It happens to everyone in the hosting industry: hard drive failure. It happened to me on New Year’s Eve. Worst of all, I had not been watching my backups properly. We use cPanel, and its backups are amazing, but sometimes they are too amazing, because you don’t have to watch them. They are reliable in that you can just restore them and have a fully functional website back in seconds. Been there done that, and I had set cPanel to backup accounts a long time ago and just assumed they were working well. In fact, the backup drive was filling up and not all accounts on the server were being backed up properly. Needless to say, when the hard drive failed enough to cause kernel panics in FreeBSD, our only option was to reinstall on a new drive. That is when the fun started.
Once the system was reinstalled, and cPanel was installed, I had the chance to look at the backup situation. The situation was grim, and there was a lot of work to be done. Of the 70+ accounts on this server, 29 were not backed up properly via cPanel. The 40+ accounts that had cPanel backups were restored in minutes with no data loss, but the other 29 were not so lucky, and this website was one of those.
cPanel backs up roughly the following:
- Home directory
- public_html directory
- MySQL data including databases, users, tables, and the data in the tables
- Subdomains, parked domains, and addon domains (like geekpowers.com)
- Email accounts
- Ftp accounts
None of that was backed up in a restorable package, so the process was as follows:
- Create the account manually via our billing system, which creates the cPanel account (luckily the billing system’s account had a healthy backup!).
- Copy the /home directory and public_html directory from the old hard drive (luckily it was still usable)
- Restore all subdomains and addon domains, pointing them to the proper directory under public_html
- Add all databases by looking in /var/db/mysql for the username_ prefix (luckily cPanel prefixes databases with the username).
- Copy the /oldvar/db/mysql/username_database/ contents into the matching database location in /var/db/mysql/username_database.
- Search through the user files for the database name, and look at config files for the username & password to set as having access to the newly created databases.
Unfortunately, there was nothing to be done for email accounts and ftp accounts… that data was lost, and there was nothing for me to look at to refer to for restoring them.
I am simply amazed that the process above seemed to work. It felt so hopeless for a couple days, and I was really dreading the thought of telling customers that their data was just gone… customers that have been with me for almost 8 years. Thanks to a little ingenuity and a lot of luck, though, that did not have to happen, and we were able to restore all accounts.
Lesson learned: do not take backups for granted. I am already in talks with my datacenter about an external backup solution they offer which runs RAID 6. I don’t ever want to feel dread when a hardware failure occurs again. I want to be prepared to be back up in the shortest amount of time possible by keeping the most solid backups I can.