Tech Note: Database Backup Revamp Redux

Charles Johnsonfollow me on twitter
Sat Apr 19, 2008 at 1:15 pm PDT • Views: 272

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

Advertisement

301 comments

^ back to top ^

Name:

Pass:

Register Forgot Your Password? Re-send Confirmation (To log in, cookies must be enabled in your browser!)

Turn off ads by subscribing!
For about 33 cents a day, our subscription option turns off all advertisements at LGF!
Read more...


► LGF Headlines

  • Loading...

► Tweeted Articles

  • Loading...

► Tweeted Pages

  • Loading...

► Top 10 Comments

  • Loading...

► Bottom Comments

  • Loading...

► Recent Comments

  • Loading...

► Tools/Info

► Tag Cloud

► Contact

You must have Javascript enabled to use the contact form.
Your email:

Subject:

Message:


Messages may be published in our weblog, unless you request otherwise.
Tech Note:
Using the Contact Form

More Partners

Compare Electricity Prices in your area. Texas Electricity is deregulated; you have the right to choose Texas Electric Rates from among many Texas Electric Companies.

Put your foot on the rock.

TwitterFacebook
LGF Pages
Recent Pages

Channeling Confucius
The 7 Most Terrifying Archaeological Discoveries
1 hour, 19 minutes ago
Views: 75 • Comments: 0
Tweets: 0 • Rating: 0

Aigle
Ha'aretz, Lost in Translation
2 hours, 15 minutes ago
Views: 68 • Comments: 3
Tweets: 0 • Rating: 0

Randall Gross
Government Employment Drops Under Obama, but Media Run With Romney Myth Anyway
4 hours, 5 minutes ago
Views: 137 • Comments: 0
Tweets: 6 • Rating: 1

researchok
French Philosopher Alain Badiou on the Real Expression of Love: 'If You Limit Yourself to Sexual Pleasure It's Narcissistic'
8 hours, 9 minutes ago
Views: 87 • Comments: 0
Tweets: 0 • Rating: 0

Haywood Jabloeme
Closing the Racial and Generational Divides
11 hours, 59 minutes ago
Views: 92 • Comments: 0
Tweets: 0 • Rating: 1

Aziz Poonawalla
I Speak for Myself: All-American
15 hours, 55 minutes ago
Views: 137 • Comments: 0
Tweets: 0 • Rating: 5

Mostly sane, most of the time.
So wake up and notice already
2 days, 11 hours ago
Views: 294 • Comments: 0
Tweets: 2 • Rating: 7

Daniel Ballard
Late Afternoon Light-Kalanchoe
3 days, 15 hours ago
Views: 270 • Comments: 0
Tweets: 0 • Rating: 5

Eclectic Infidel
City College of San Francisco Budget Update
3 days, 16 hours ago
Views: 323 • Comments: 0
Tweets: 0 • Rating: 1

MichaelJ
Apple TV Slated to Debut in December?
4 days, 22 hours ago
Views: 372 • Comments: 0
Tweets: 0 • Rating: 1

 Frank says:

Of course you realize you won't be able to hear the organ once we turn the guitars on. -- Introduction to "Louie, Louie" on "Uncle Meat"