Quick Tips: How to copy/archive a Drupal site with only FTP access

I do most of my work using ssh and other command line tools, such as vim and screen. This is the environment I am most comfortable and productive in.

However, this is not always an option working on client sites. Some do not have ssh enabled for various reasons, including hosting restrictions (e.g. shared hosting) or security concerns and workplace policies.

So, in these situations, it is hard to replicate the site on a test server for an assessment, development work, or moving the site from an old server to a new one.

The following are some techniques that I use when I need to copy a site quickly.

Using cPanel

If the site in question has cPanel, you can use phpMyAdmin to backup the database, and either save it to a file, or directly download it to your desktop. That takes care of the database part, what about the files then?

For the files, you can use cPanel's cron interface to run a command like the following after 2 minutes from present time:

cd ~/public_html; tar -czvf BACKUP.tar.gz . 

Wait for the two minutes to pass, then using FTP or cPanel's File Manager, download the archive that was created.

Using a temporary PHP script

Instead of using web based interfaces, which can be clumsy, you can use FTP to upload a custom PHP script that executes shell commands on your behalf.

First, download the settings.php file for the site. In it, there will be the database name, the use name and password for the site.

Second, take the above information and create a PHP file like this one. Replace the capitalized values with those you just gleaned from the settings file.

<?php
exec("mysqldump -uDBUSER -pPASSWORD DBNAME > DBNAME.sql");
exec("tar -czvf BACKUP.tar.gz .");
print "Done"; 

Name the file something unique and unguessable, such as a timestamp or a random number (e.g. 74688266024.php). Make sure that it ends in .php.

Upload this file using FTP to the public_html directory for your site. Then point your browser to it (e.g. http://example.com/74688266024.php), and wait till the backup completes.

Now, delete the php file you just created, so no one else can run the script.

After that, download the tar achive using FTP, and delete it and the database dump too.

Drupal Modules

There are several Drupal modules that provide backup and restore facilities to varying degrees. One such module is backupdba, and backup_migrate. You can use one of them to create the backup you need and then download it.

However, this requires extra steps like uploading the Drupal module, enabling it, configuring it, running the backup, then disabling/deleting the module.

What other tricks for copying/replicating a site do you use if you encounter a restrictive environment?

Contents: 

Comments

lftp

lftp is a neat programm that can be used to up and download whole directories when executed from the commandline. The best thing about it is that it is scriptable.

RE: Temporary Php script excellent

I like using the temporary PHP script , very well explained and of course working !

Thanks for the trick,

Andy