function db_maintenance_do_db_backup in DB Maintenance 6.2
Same name and namespace in other branches
- 5.2 db_maintenance.module \db_maintenance_do_db_backup()
1 call to db_maintenance_do_db_backup()
- db_maintenance_cron in ./
db_maintenance.module - Implementation of hook_cron().
File
- ./
db_maintenance.module, line 457 - Optimizes database tables during cron runs.
Code
function db_maintenance_do_db_backup() {
global $db_url;
$mysqldump = variable_get('db_maintenance_path_to_mysqldump', '/usr/bin/mysqldump');
$backupdir = variable_get('db_maintenance_backup_directory', '/tmp');
$dateformat = 'Ymd_H-i-s';
$dbname = db_maintenance_get_db_info('dbname');
$now = time();
$date = format_date($now, 'custom', $dateformat);
$filename = $backupdir . '/' . $date . '_' . $dbname . '_db.sql';
$mysqloptions = db_maintenance_get_mysql_options();
$mysqldumpexec = $mysqldump . ' ' . $mysqloptions . ' > ' . $filename;
if (is_dir($backupdir)) {
exec($mysqldumpexec, $output, $return);
$output = implode('<br />', $output);
// variable_set('db_maintenance_debug', variable_get('db_maintenance_debug', '') . 'MYSQLDUMP: '.$mysqldumpexec.' ('. var_export($return, TRUE) .') '. var_export($output, TRUE)."\n");
if (!$return && !is_file($filename)) {
watchdog('db_maintenance', $output, NULL, WATCHDOG_ERROR);
return FALSE;
}
else {
return $filename;
}
}
else {
watchdog('db_maintenance', 'backup directory does not exist', array(), WATCHDOG_ERROR);
return FALSE;
}
}