Going through the steps required to back up your site is an excellent first step, but for a backup to provide true peace of mind you need to know it works. To test your backup, you need to use it to recreate your site in a different location. This process involves three steps, and is similar to the install process described in Chapter 2.
1. Create your backup database.
2. Upload your codebase to the backup server.
3. Edit the settings.php file to point to your database.
Before We Begin: Web Space for Testing Your Backup
To verify that your backup works, you need to test that you can recreate your site.
This step requires server space that is usually obtained in one of three ways:
1. Buy an additional test domain: If you do a lot of work with websites and want a place to learn, a test domain can be a great resource. If you want to teach your class and spend as little time possible dealing with maintenance, then one of the other options will be a better fit.
2. Create a subdomain in your existing account: For example, if your site is accessible at http:www.yoursite.org, the subdomain would be at http://test.yoursite.org. The advantage of the subdomain is that it is probably the easiest to set up, as most web hosts will help you to do this, and some will even do it for you. The disadvantage of using a subdomain is that if your server goes down, you will lose both your backup site and your main site.
3. Set up a test site on your computer using XAMPP (refer to http://drupal. org/node/75545 ) or MAMP (refer to http://drupal.org/node/66187 ). This is a useful step if you want to learn more about running a server, but it can be too much technical work for many people.
You can use either PHPMyAdmin or the command line to recreate your database. Although PHPMyAdmin provides an easier interface to work with, it has some limitations, especially when it comes to restoring larger databases.
First, create a database and a user for that database, as described in Chapter 2.
Make sure that you keep the username, password, and database name •t^STX of this database in a convenient place, as you will need to specify these N^i.»-^ values in your settings.php file, and you could also need them if you need to populate this database via the command line.
Recreate the Database via PHPMyAdmin
Refer to the following screenshot for details.
1. Click the Import tab on the top-level navigation.
2. On the Import screen, use the Browse button to select your database.
3. Note the upload size limit, shown in the following screenshot by Item 3. (If your database backup is larger than this, you need to use the command line.)
4. Select the correct file, and click the Go button.
To recreate the database using the command line, you will need to FTP the file containing your backed-up database into your staging directory. Then, log into your server via SSH, and cd to your staging directory.
Populate your database using the following command: mysql -u username -p databasename < backupfilename.sql
Once you have completed these steps, you can view the database using phpMyAdmin to verify that the database has been created correctly.
In this chapter, we have covered two ways of backing up the codebase: using your FTP client or by tarring and gzipping the file via the command line. If you used your FTP client to download the codebase, then simply upload the codebase to the appropriate location on your server. If you backed up the codebase via the command line, use your FTP client to upload the backup tar.gz file into your staging directory.
Then, SSH into your server and cd to your staging directory. Untar the codebase using this command:
tar -xzvf backup_codebase.tar.gz
The tar command extracts the codebase. From here, you can use the cp command to copy the codebase into your web directory.
cp -pr backup_codebase /path/to/web/directory
The actual path to your web directory will vary from server to server. If you don't know the path to your web directory, you can use your FTP client to figure this out, as shown by Item 1 in the screenshot before the preceding one.
Once you have moved the codebase into the web directory, you will need to edit the settings.php file so that it points at the correct database. The settings.php file is located in the sites/default directory. You can edit this file using any text editor, or any more-advanced authoring tool, such as Dreamweaver or Zend.
Even though you can open the settings.php file using a word I
processor, don't do it! Word processors add in spaces and formatting that I will render the settings.php file useless. I
As shown in the highlighted section in the following screenshot, you will need to edit three values:
1. Username for the database
2. Password for the user
3. Database name
Edit these values, save your changes, and then replace the old settings.php file with the new file, and your backup is complete. You can test the backup by navigating to the homepage of your new site. You will see an exact replica of your existing site.
Congratulations! You are now running your website with the security of a solid backup procedure.
Was this article helpful?