function db_maintenance_do_files_backup in DB Maintenance 6.2
1 call to db_maintenance_do_files_backup()
- db_maintenance_cron in ./
db_maintenance.module - Implementation of hook_cron().
File
- ./
db_maintenance.module, line 487 - Optimizes database tables during cron runs.
Code
function db_maintenance_do_files_backup() {
$filespath = file_directory_path();
$tarpath = variable_get('db_maintenance_path_to_tar', '/bin/tar');
$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);
if (is_file($tarpath) && is_dir($filespath) && is_dir($backupdir)) {
$backupname = $date . '_' . $dbname . '_files.tar.gz';
$command = "tar -cvzf {$backupdir}/{$backupname} --exclude=*" . $dbname . "_files.tar.gz --exclude=*" . $dbname . "_db.sql {$filespath}";
$output = array();
exec($command, $output, $return);
$output = implode('<br />', $output);
// variable_set('db_maintenance_debug', variable_get('db_maintenance_debug', '') . 'TAR: '.$command.' ('. var_export($return, TRUE) .') '. var_export($output, TRUE) ."\n");
if (!$return) {
watchdog('db_maintenance', $output, NULL, WATCHDOG_ERROR);
return FALSE;
}
else {
if (!is_file($backupdir . '/' . $backupname)) {
watchdog('db_maintenance', 'failed to create files backup file: !output', array(
'!output' => $output,
), WATCHDOG_ERROR);
return FALSE;
}
return $backupdir . '/' . $backupname;
}
}
else {
watchdog('db_maintenance', 'Files dir not present, backup dir not present or path to tar incorrect', array(), WATCHDOG_ERROR);
return FALSE;
}
}