function db_maintanence_do_files_backup in DB Maintenance 5.2
1 call to db_maintanence_do_files_backup()
- db_maintenance_cron in ./
db_maintenance.module - Implementation of hook_cron().
File
- ./
db_maintenance.module, line 437 - Optimizes database tables during cron runs.
Code
function db_maintanence_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 = date($dateformat, $now);
if (is_file($tarpath) && is_dir($filespath) && is_dir($backupdir)) {
$backupname = "{$date}_{$dbname}_files.tar.gz";
$command = "tar -cvzf {$backupdir}/{$backupname} {$filespath}";
exec($command, $output, $return);
// $return is return value of exec'd command (0 is okay status)
if ($return) {
watchdog('db_maintenance', $output, WATCHDOG_ERROR);
return FALSE;
}
else {
if (!is_file("{$backupdir}/{$backupname}")) {
watchdog('db_maintenance', t('failed to create files backup file') . ': ' . $output, WATCHDOG_ERROR);
return FALSE;
}
return "{$backupdir}/{$backupname}";
}
}
else {
watchdog('db_maintenance', t('Files dir not present, backup dir not present or path to tar incorrect'), WATCHDOG_ERROR);
return FALSE;
}
}