Chapter 43. Backing Up Your Site and Database


Oh, no! You just tried to log on to your site and it's gone! What can you do? How can you get it back? Unfortunately, it's too late to ask: Disaster has already struck. You should have read this topic beforehand so that you'd be ready.

Assuming, however, that disaster hasn't already struck, you're reading this at a good time. First, you should be aware that many Web hosting companies regularly back up their customers' Web sites and databases. If your site is being hosted, ask your provider if they perform backups, and find out in advance what you'd have to do to get them to restore your site in the event of a disaster.

PHP-Nuke also has a database-backup feature built right in. You'll find it on the Administration menu, as shown in Figure 43.1. It's labeled Backup DB. There's no configuration or anything when you click this icon; the site creates the backup and then immediately downloads it to your local computer for safekeeping.

Figure 43.1. Selecting the Backup DB icon on the Administration menu.


Should the worst occur and you actually need that backup, here's what to do with it: You'll need to delete every table in your PHP-Nuke database and insert the tables that are in the backup instead. Yikes! Exactly how you do that depends on precisely what database engine you're using with PHP-Nuke; MySQL, for example, will allow you to simply import the backup as a big query (the backup is just a giant text file). Most database engines will do that, actually. What you'll need is a way to actually accomplish that import, which is something your hosting provider (if you're using one) must give you. Most will provide a Web-based administration tool; in the case of MySQL, it's called phpMyAdmin. As shown in Figure 43.2, you start by selecting every existing table's check box and selecting Drop from the drop-down list (it says With Selected to start) at the bottom of the page.

Figure 43.2. Selecting tables to drop for a MySQL database.


With all of your tables dropped, go back to the top of the page and click the SQL tab. Then, as shown in Figure 43.3, click the Browse button and find your backup file. MySQL should auto-import it and execute it, which might take a while. In fact, if your backup is bigger than 2MB or so, this technique won't work; you'll have to get your backup file onto your server via FTP and ask a server administrator (at your hosting company, if you use one), to import the file using MySQL's command-line tool.

Figure 43.3. Importing the backup query to restore your data.


Carbon Monoxide Alert!

When you select Drop from the list, you don't have to click any other buttons: MySQL drops the tables. Don't do this unless you know you have a good backup!


The command line goes something like this: mysql h servername u username p databasename < backup_filename. Cryptic, huh? Just have the server guy fill in the italicized bits with the proper information, and you'll be okay.

Now, this backup process is only half the battle: the database. You should also make a regular backup of PHP-Nuke's files, which is most easily accomplished through FTP using some sort of batch FTP application that can copy your entire site's files down to your local computer all at once. I use a freeware application called BatchFTP (www.batchftp.net) that does the trick. Because most of PHP-Nuke's changes occur in the database, you should have to do a file backup just once every few months or so, and definitely before and after any PHP-Nuke version upgrades. Database backups can't be performed too often; weekly is enough for a slow site, but nightly is better for a busy site. Given how long it takes to make a backupa few secondsversus how long it would take to re-create all your hard work if the site crashed, it's probably worth the time to just make the backup.

Sidebar . FAQ

I'm hosting my site with a hosting company. They make backups, right?

Don't assume they doask. Ask how often they're made and what you have to do to get the backup restored in the event of a problem. Some hosts make daily backups, but they use them only if an entire serverwhich may contain multiple Web sitescrashes. The backups might not be for your use at all, which means you're on your own for making backups of your individual site.




    PHP-Nuke Garage
    PHP-Nuke Garage
    ISBN: 0131855166
    EAN: 2147483647
    Year: 2006
    Pages: 235
    Authors: Don Jones

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net