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$xml = simplexml_load_file("app/etc/local.xml");
$db_host = (string)$xml->global->resources->default_setup->connection->host; $db_name = (string)$xml->global->resources->default_setup->connection->dbname; $db_username = (string)$xml->global->resources->default_setup->connection->username; $db_password = (string)$xml->global->resources->default_setup->connection->password;
$mysqldump = trim(shell_exec("which mysqldump")); $tar = trim(shell_exec("which tar"));
// Backup database var_dump(shell_exec("$mysqldump -h $db_host -u $db_username -p$db_password $db_name > migration_db.sql"));
// Backup entire site var_dump(shell_exec("$tar cfz migration_www.tgz . --exclude=var/session --exclude=var/cache --exclude=var/report --exclude=var/backups --exclude=var/log --exclude=media --exclude=.tgz --exclude=.gz --exclude=.tar --exclude=.zip
"));// Grab non-compressible data var_dump(shell_exec("$tar cf migration_misc.tar media .tgz .gz .tar .zip --exclude=migration_misc.tar"));
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 = ""; $current_domain = "";
$mysql = trim(shell_exec("which mysql")); $tar = trim(shell_exec("which tar")); $wget = trim(shell_exec("which wget"));
// Grab current site shell_exec("$wget $current_domain/migration_www.tgz"); shell_exec("$wget $current_domain/migration_misc.tar");
// Restore entire site shell_exec("$tar xfz migration_www.tar.gz ."); shell_exec("$tar xf migration_misc.tar .");
// Restore database shell_exec("$mysql -h $db_host -u $db_username -p$db_password $db_name < migration_db.sql");
$xml = simplexml_load_file("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("app/etc/local.xml");
@unlink($_SERVER['DOCUMENT_ROOT']."app/etc/use_cache.ser"); @unlink($_SERVER['DOCUMENT_ROOT']."downloader/pear/pear.ini");
[syntaxhighlighter]