Skip to content

Instantly share code, notes, and snippets.

@d9k
Created June 23, 2016 20:25
Show Gist options
  • Save d9k/a9620d763c1490d072247141d12a6673 to your computer and use it in GitHub Desktop.
Save d9k/a9620d763c1490d072247141d12a6673 to your computer and use it in GitHub Desktop.
#!env php
<?php
//script is intended to run from site directory
//tested on Joomla 2.5
$currentDir = getcwd();
echo "Running from \"${currentDir}\"\n";
$configPath = $currentDir.'/configuration.php';
$backupFolderPath = $currentDir.'/.backupdb';
$backupPath = $backupFolderPath.'/backup.sql';
if (!file_exists($configPath)){
echo "\"${configPath}\" doesn't exist\n";
exit;
}
if (!is_readable($configPath)){
echo "Access to \"${configPath}\" denied\n";
exit;
}
include_once $configPath;
$config = new JConfig();
$db = $config->db;
$password = $config->password;
$user = $config->user;
$host = $config->host;
mkdir($backupFolderPath);
echo shell_exec("mysqldump -u${user} -p${password} --single-transaction --hex-blob ${db} --result-file=${backupPath}");
echo shell_exec("ls -lh ${backupFolderPath}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment