Migrate a Magento store without SSH access

We were recently asked to migrate a store to our Sonassi Hosting platform, but the client did not have SSH access to his previous hosting account.

So we quickly knocked up a script to take care of the backup process

<?php
 
	$db_host = "";
	$db_name = "";
	$db_username = "";
	$db_password = "";
 
	// Backup database
	shell_exec("/usr/bin/mysqldump -h ".$db_host." -u ".$db_username." -p".$db_password." > ".$db_name.".sql &");
 
	// Backup entire site
	shell_exec("/usr/bin/tar cfz ".$_SERVER['HTTP_HOST'].".tar.gz
		--exclude=./".$_SERVER['HTTP_HOST'].".tar.gz
		--exclude=./var/session".$_SERVER['HTTP_HOST']."
		--exclude=./var/cache".$_SERVER['HTTP_HOST']."
		".$_SERVER['DOCUMENT_ROOT']." &");
 
?>

We carried out the restoration via SSH, but you could also have a PHP script take care of that too:

<?php
 
	$db_host = "";
	$db_name = "";
	$db_username = "";
	$db_password = "";
 
	// Only set these if you are changing your domain name
	$old_domain = "";
	$new_domain = "";
 
	// Restore entire site
	shell_exec("/usr/bin/tar xfz ".$_SERVER['HTTP_HOST'].".tar.gz
		".$_SERVER['DOCUMENT_ROOT']);
 
	if (!empty($old_domain) && !empty($new_domain)) {
		$sql = &file_get_contents($db_name.".sql");
		file_put_contents($db_name.".sql.bak",$sql);
		$sql = str_replace($old_domain,$new_domain,$sql)
		file_put_contents($db_name.".sql",$sql);
	}
 
	// Restore database
	shell_exec("/usr/bin/mysql -h ".$db_host." -u ".$db_username." -p".$db_password." < ".$db_name.".sql &");
 
	$xml = simplexml_load_file($_SERVER['DOCUMENT_ROOT']."app/etc/local.xml");
 
	$xml->global->resources->default_setup->connection->host = $db_host;
	$xml->global->resources->default_setup->connection->dbname = $db_name;
	$xml->global->resources->default_setup->connection->username = $db_username;
	$xml->global->resources->default_setup->connection->password = $db_password;
 
	$xml->asXML($_SERVER['DOCUMENT_ROOT']."app/etc/local.xml");
 
	// Disable cache
	@unlink($_SERVER['DOCUMENT_ROOT']."app/etc/use_cache.ser");
	@unlink($_SERVER['DOCUMENT_ROOT']."downloader/pear/pear.ini");
 
?>
This entry was posted in Knowledge Base, Magento and tagged , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

One Response to Migrate a Magento store without SSH access

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">