Thursday, April 26, 2012

BASH and PHP problem solving

I had a problem where I was trying to get a BASH script to run a backup extension on a Joomla site the other day. It was hosted on a shared server on HostGator with my only access being cpanel. For some reason my cron job wasn't firing when I thought it should. It would only work when I scheduled a recurring job every few minutes. I had to look up the PHP code but I wrote something like <?PHP echo date(r); ?> into a time.php file and uploaded it, then navigating to that location with my browser gave me the local time on the server. The server's time was 1 hour in the past which is why my cron jobs set to specific time weren't firing. I set my job to an hour in the past, and it worked that time and since.

The backup extension is Akeeba Backup. One of the features in it is a frontend triggered backup. You can set up a secret word, so just not anyone can trigger it and use something like wget to make it run. There is an integrated backup if you want to pay money for the Pro version. This way you can do scheduled backups with the free version. It's also relatively easy in BASH to delete older files. I haven't had to do anything fancy like keep certain day backups, or only keep x number of backups no matter when they were made.

Monday, April 9, 2012

A word about backups

There are a few different levels of backups:
Full - Just as it sounds, a full backup is a backup of everything. It depends on what you configure for the backup, but it doesn't exclude files from the backup set.
Incremental - An incremental backup only backs up files that are new or modified since the last backup, whatever kind of backup that was.
Differential - A differential backup will backup all files that are new or modified since the last full backup.

The major takeaway from this is that if you do a full backup, and then just an incremental for the next 2 weeks and then the system fails it's a pain to restore. Because to restore you must first restore the full backup, then each incremental in turn until you get caught up. On the other hand, consider if you do a full backup then differential backups each day for 2 weeks then the system fails. All you have to restore is the full backup, then the most recent differential. Both methods have their downsides. While incremental backups require you to restore each individual one since the last full backup, they do potentially take up less space. Differentials will continually increase in size from the point of the last full backup as new data is added and existing data is changed.

An actual backup plan would probably have a mix of backup modes with a full happening much more often. Something like doing a full backup on a Sunday, then incremental backups the rest of the week. Or possibly a differential on Wednesday. This wouldn't always be true however, if you use Amanda backup then it will schedule full and incremental backups to try to always use the same amount of space. It is very much geared toward doing tape backups, but it can also work with a disk based backup system.