Recently, I had to work on a few Drupal sites and only had FTP access to the webservers. One thing is for certain: FTP is slow and painful. I prefer SSH access so I can interact with Subversion, compress files, dump mysql databases, and transfer files securely. I tried to copy the entire remote docroot to my local development environment (using my FTP client, CyberDuck), and the time estimate to copy all the files individually was ridiculous. There are over 500 files in Drupal core alone, not to mention all the 3rd party modules and uploaded files. I decided to upload a tiny PHP file to execute once to backup the filesystem outside the docroot, so I could copy a single compressed file. Before you attempt something like this, you MUST understand the security risk and vulnerability of exposing site archives and having PHP scripts like this on your server. For instance, if someone was able to get a hold of your settings.php file, they'll have access to your MySQL DNS (connection string). Hopefully, your webserver does not have MySQL and other important services exposed through your firewall, but that is a different topic altogether. I'm already having doubts sharing this PHP snippet. I uploaded the following code to a file in the docroot of Drupal, browsed to the web path once, then promptly removed it from existence. Afterward, I was able to copy the entire filesystem as one file (one transfer), maintain my sanity, and saved myself hours of slow FTP transfers.
<?php
// define a list of valid IPs that can access this file
// yes, I know, this will not prevent spoofers, etc
$validIPs = array(
'MY-IPADDRESS',
'MY-OTHER-IPADDRESS'
);
// ensure the request is coming from a valid IP address
if (!in_array($_SERVER['REMOTE_ADDR'], $validIPs)) die;
// define a path to the archive to create
// VERY IMPORTANT: you must prefix the file path with "../" to ensure the archive is created outside the docroot path!
// NOTE: you may need to update the file path to work in your hosting situation
$filePath = "../backup.tar.gz";
// ensure the file does not already exist
if (file_exists($filePath)) die;
// define the command to execute to compress the site
// NOTE: you may need to specify the full path to the tar command
$command = "tar -czf $filePath .";
// execute the command to compress the entire site
exec($command);
echo "done."
?>After this code is executed, be sure to remove the PHP script and archive!










Slow FTP
In case you haven't tried it yet, Yummy FTP is far and away the fastest FTP client I have ever used (on Mac or any other platform). I have a very fast FTP connection so Drupal core only takes me a few minutes to upload but you should see a significant speed increase over Cyberduck on any connection. I'm pretty they still have a free trial available but the program only costs $28 anyway.
ftp uncompressed
Just to clarify, the problem with FTP is the protocol, not the application being used. FTP typically transfers files individually, which opens and closes connections frequently. The point of my article was to show how you could compress the entire site into 1 file which will dramatically speed up your transfer. Sorry for the confusion.
Cheers,
Eric
Make your script self-destruct
If you're only going to have your script run once, why not have the script delete itself after execution?
Assuming your script's filename is "selfdestruct.php", replace the last two lines with this:
echo "done.";
exec('rm -f selfdestruct.php');
?>
Note that I added a semi-colon to the line: echo "done."
yup!
good call, thanks :)
database
Oh, and if I have not mentioned this before, the Backup and Migrate module is great for transferring your database from server to server.
-Eric
Time out?
Won't the script time out, if you have to back up large enough amount of data? say 13Gb ?