Tech Note: Database Backup Revamp Redux

• Views: 1,859

This one’s going to get knee deep in geekspeak before you know it, so feel free to skip over and treat it as an open thread — my feelings won’t be hurt.

It’s all about the backups. You don’t know how important they are until some piece of critical hardware fails and destroys your data, and your only backup is 6 months old. Or you don’t even have a backup. If it’s already happened to you, you have no excuse when it happens again.

Our latest system is fully automated, and makes incremental backups of both the MySQL database and the web server that runs our LGF Blog Engine. The backups are transferred from these two servers to the local office machine, through the wonders of rsync over SSH; the web server is backed up every hour, and the MySQL database once a day. With Apple’s Time Machine backing up the local computer, we have archives going back months—a multi-level disaster recovery system, administered remotely through an ultra-secure connection. Oh yeah.

The database server is backed up less frequently because the backup has to be created first on the server. For maximum portability and ease of restoring, I’m using the mysqldump program to dump out SQL text files for each table in our main database. This process is in a shell script that runs as a daily cron job at low traffic times, because it can take a little while (about 5 minutes for the whole DB) and it uses server resources while dumping the tables.

The Unix rsync program, which runs on the local Mac, is just made for jobs like this; it does a smart incremental backup, and only transfers the changed sections of files—and even compresses them during the transfer. The hourly backup of the entire web server takes only a few seconds and hardly any server resources, because there aren’t many files that change frequently (and the ones that do are usually small).

On the local Mac, I decided to avoid using cron for two reasons: 1) Apple has deprecated it, in favor of their launchd utility, and 2) cron jobs run in a very limited shell environment, and don’t inherit the proper SSH variables, making rsync connections more difficult.

So I’m taking Apple’s advice and using two launchd agents instead, to call the rsync commands; one that runs every hour to back up the web server, and one that runs daily for the MySQL database. Launchd agents run in a full Unix environment, and if you have SSH keys set up for remote access you can use them in your agent. (A new feature of Leopard: built-in support for ssh-agent.)

Creating the launchd agent was simple; it’s an XML “plist” file, and you can either create it by hand if you’re manly enough, or use the free utility Lingon and save some time.

References:
launchd in Depth
MacDevCenter.com — Inside SSH, Part 1

Jump to top

Create a PageThis is the LGF Pages posting bookmarklet. To use it, drag this button to your browser's bookmark bar, and title it 'LGF Pages' (or whatever you like). Then browse to a site you want to post, select some text on the page to use for a quote, click the bookmarklet, and the Pages posting window will appear with the title, text, and any embedded video or audio files already filled in, ready to go.
Or... you can just click this button to open the Pages posting window right away.
Last updated: 2023-04-04 11:11 am PDT
LGF User's Guide RSS Feeds

Help support Little Green Footballs!

Subscribe now for ad-free access!Register and sign in to a free LGF account before subscribing, and your ad-free access will be automatically enabled.

Donate with
PayPal
Cash.app
Recent PagesClick to refresh
The Pandemic Cost 7 Million Lives, but Talks to Prevent a Repeat Stall In late 2021, as the world reeled from the arrival of the highly contagious omicron variant of the coronavirus, representatives of almost 200 countries met - some online, some in-person in Geneva - hoping to forestall a future worldwide ...
Cheechako
3 days ago
Views: 119 • Comments: 0 • Rating: 1
Texas County at Center of Border Fight Is Overwhelmed by Migrant Deaths EAGLE PASS, Tex. - The undertaker lighted a cigarette and held it between his latex-gloved fingers as he stood over the bloated body bag lying in the bed of his battered pickup truck. The woman had been fished out ...
Cheechako
2 weeks ago
Views: 280 • Comments: 0 • Rating: 1