I create php script for magento database backup that work well for Single store site but showing error for multi-store
//Magento Database Backup php script
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', 1);
ini_set('memory_limit', '1512M');
// Get Magento Application
require_once 'app/Mage.php';
Mage::app('default');
//Mage::app('main');
// get Magento config
$config = Mage::getConfig()->getResourceConnectionConfig("default_setup");
$dbinfo = array(
"host" => $config->host,
"user" => $config->username,
"pass" => $config->password,
"dbname" => $config->dbname
);
// Database Config
$db_host = $dbinfo["host"];
$db_user = $dbinfo["user"];
$db_pass = $dbinfo["pass"];
$db_name = $dbinfo["dbname"];
//echo $db_name; die();
// filename
$backup_file = $db_name ."-". date("ymdHis") . ".zip";
$command = "mysqldump --database " . $db_name . " -u ". $db_user . " -p'". $db_pass . "' | gzip > " . $backup_file;
echo 'command executing is ' . $command . '<br/>' ;
$output = shell_exec($command);
echo 'Finished!<br/>' ;
//shell_exec("mysqldump --opt --default-character-set=utf8 -uuser {$backup_db} > {$sql_name}")
Error For Multi-store as follows:
Fatal error: Uncaught exception 'Mage_Core_Model_Store_Exception' in
/public_html/app/code/core/Mage/Core/Model/App.php:1357 Stack trace: #0
/public_html/app/code/core/Mage/Core/Model/App.php(842): Mage_Core_Model_App->throwStoreException() #1 /public_html/app/code/core/Mage/Core/Model/App.php(491): Mage_Core_Model_App->getStore() #2 /home
/public_html/app/code/core/Mage/Core/Model/App.php(274): Mage_Core_Model_App->_initCurrentStore('default', 'store') #3
/public_html/app/Mage.php(616): Mage_Core_Model_App->init('default', 'store', Array) #4
/public_html/mege_dbbackup.php(9): Mage::app('default') #5 {main} thrown in
/public_html/app/code/core/Mage/Core/Model/App.php on line 1357
Best Answer
When you do a mysql dump, you're not just dumping a single store but the entire Magento database. Your issue is that
You're loading 'default' as the scope. This throws an exception:
Just leave it blank as in: