Skip to content

Instantly share code, notes, and snippets.

@hslatman
Last active June 8, 2017 08:32
Show Gist options
  • Save hslatman/ea433437307a7bb9473d to your computer and use it in GitHub Desktop.
Save hslatman/ea433437307a7bb9473d to your computer and use it in GitHub Desktop.
Create a Magento database backup
<?php
/******************************************************************************************************************
* Source: http://www.emvee-solutions.com/blog/magento-create-database-backup-php-code/
*
* Creating a Magento database backup in var/backups
******************************************************************************************************************/
//increase execution time
ini_set('max_execution_time', 900); //900 seconds = 15 minutes
//require Magento
require_once 'app/Mage.php';
$app = Mage::app('admin');
umask(0);
//set error reporting
error_reporting(E_ALL & ~E_NOTICE);
Mage::setIsDeveloperMode(true);
//do backup
try {
$backupDbHelper = Mage::getModel('backup/db');
//create backup instance, set certain options
$backup = Mage::getModel('backup/backup')
->setTime(time())
->setType('db')
->setPath(Mage::getBaseDir("var") . DS . "backups");
//do actual backup
$backupDbHelper->createBackup($backup);
//return success
print 'Backup successfully created';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment